From 7a1ffd7accde0156f0d1f23810eae1f82261f7b8 Mon Sep 17 00:00:00 2001 From: Jan Krivanek Date: Fri, 19 Aug 2022 09:33:30 +0200 Subject: [PATCH] Remove custom logic of fetching dotnet dir --- src/Cli/dotnet/CommonOptions.cs | 19 ++----- .../commands/dotnet-new/SdkInfoProvider.cs | 17 +++++- .../TemplateLocator.cs | 8 +-- .../MSBuildSdkResolver.cs | 8 +-- .../EnvironmentProvider.cs | 53 ++++++++++++++----- .../GivenAnMSBuildSdkResolver.cs | 33 +++++++----- .../ToolPackageInstallerTests.cs | 17 +++++- .../GivenAnTemplateLocator.cs | 2 +- .../dotnet-new.Tests/SdkInfoProviderTests.cs | 3 +- 9 files changed, 109 insertions(+), 51 deletions(-) diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index 8fdfef697714..ae72928daf90 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -231,22 +231,13 @@ internal static string ResolveRidShorthandOptionsToRuntimeIdentifier(string os, return $"{os}-{arch}"; } - public static string GetDotnetExeDirectory() - { - // Alternatively we could use Microsoft.DotNet.NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory here - // (while injecting env resolver so that DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR is being returned as null) - // However - it first looks on PATH - which can be problematic in environment (e.g. dev) where we have installed and xcopy dotnet versions - - var dotnetRootPath = Path.GetDirectoryName(Environment.ProcessPath); - // When running under test the path does not always contain "dotnet". - // The sdk folder is /d/ when run on helix because of space issues - dotnetRootPath = Path.GetFileName(dotnetRootPath).Contains("dotnet") || Path.GetFileName(dotnetRootPath).Contains("x64") || Path.GetFileName(dotnetRootPath).Equals("d") ? dotnetRootPath : Path.Combine(dotnetRootPath, "dotnet"); - return dotnetRootPath; - } - public static string GetCurrentRuntimeId() { - var dotnetRootPath = GetDotnetExeDirectory(); + // Get the dotnet directory, while ignoring custom msbuild resolvers + string dotnetRootPath = Microsoft.DotNet.NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory(key => + key.Equals("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR", StringComparison.InvariantCultureIgnoreCase) + ? null + : Environment.GetEnvironmentVariable(key)); var ridFileName = "NETCoreSdkRuntimeIdentifierChain.txt"; // When running under test the Product.Version might be empty or point to version not installed in dotnetRootPath. string runtimeIdentifierChainPath = string.IsNullOrEmpty(Product.Version) || !Directory.Exists(Path.Combine(dotnetRootPath, "sdk", Product.Version)) ? diff --git a/src/Cli/dotnet/commands/dotnet-new/SdkInfoProvider.cs b/src/Cli/dotnet/commands/dotnet-new/SdkInfoProvider.cs index 9af935f40f79..d168f780f87c 100644 --- a/src/Cli/dotnet/commands/dotnet-new/SdkInfoProvider.cs +++ b/src/Cli/dotnet/commands/dotnet-new/SdkInfoProvider.cs @@ -19,8 +19,19 @@ namespace Microsoft.DotNet.Tools.New { internal class SdkInfoProvider : ISdkInfoProvider { + private readonly Func _getCurrentProcessPath; + public Guid Id { get; } = Guid.Parse("{A846C4E2-1E85-4BF5-954D-17655D916928}"); + public SdkInfoProvider() + : this(null) + { } + + internal SdkInfoProvider(Func getCurrentProcessPath) + { + _getCurrentProcessPath = getCurrentProcessPath; + } + public Task GetCurrentVersionAsync(CancellationToken cancellationToken) { return Task.FromResult(Product.Version); @@ -29,10 +40,12 @@ public Task GetCurrentVersionAsync(CancellationToken cancellationToken) public Task> GetInstalledVersionsAsync(CancellationToken cancellationToken) { // Get the dotnet directory, while ignoring custom msbuild resolvers - string dotnetDir = Microsoft.DotNet.NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory(key => + string dotnetDir = Microsoft.DotNet.NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory( + key => key.Equals("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR", StringComparison.InvariantCultureIgnoreCase) ? null - : Environment.GetEnvironmentVariable(key)); + : Environment.GetEnvironmentVariable(key), + _getCurrentProcessPath); IEnumerable sdks; try diff --git a/src/Microsoft.DotNet.TemplateLocator/TemplateLocator.cs b/src/Microsoft.DotNet.TemplateLocator/TemplateLocator.cs index b0a32fa649db..b489ef143624 100644 --- a/src/Microsoft.DotNet.TemplateLocator/TemplateLocator.cs +++ b/src/Microsoft.DotNet.TemplateLocator/TemplateLocator.cs @@ -17,9 +17,10 @@ public sealed class TemplateLocator private IWorkloadResolver? _workloadResolver; private readonly Lazy _netCoreSdkResolver; private readonly Func _getEnvironmentVariable; + private readonly Func? _getCurrentProcessPath; #nullable disable public TemplateLocator() - : this(Environment.GetEnvironmentVariable, VSSettings.Ambient, null, null) + : this(Environment.GetEnvironmentVariable, null, VSSettings.Ambient, null, null) { } #nullable restore @@ -27,7 +28,7 @@ public TemplateLocator() /// /// Test constructor /// - public TemplateLocator(Func getEnvironmentVariable, VSSettings vsSettings, + public TemplateLocator(Func getEnvironmentVariable, Func? getCurrentProcessPath, VSSettings vsSettings, IWorkloadManifestProvider? workloadManifestProvider, IWorkloadResolver? workloadResolver) { _netCoreSdkResolver = @@ -36,6 +37,7 @@ public TemplateLocator(Func getEnvironmentVariable, VSSettings v _workloadManifestProvider = workloadManifestProvider; _workloadResolver = workloadResolver; _getEnvironmentVariable = getEnvironmentVariable; + _getCurrentProcessPath = getCurrentProcessPath; } public IReadOnlyCollection GetDotnetSdkTemplatePackages( @@ -63,7 +65,7 @@ public IReadOnlyCollection GetDotnetSdkTemplate public bool TryGetDotnetSdkVersionUsedInVs(string vsVersion, out string? sdkVersion) { - string dotnetExeDir = EnvironmentProvider.GetDotnetExeDirectory(_getEnvironmentVariable); + string dotnetExeDir = EnvironmentProvider.GetDotnetExeDirectory(_getEnvironmentVariable, _getCurrentProcessPath); if (!Version.TryParse(vsVersion, out var parsedVsVersion)) { diff --git a/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs b/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs index 62286d556b8c..c1f64d571efa 100644 --- a/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs +++ b/src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs @@ -31,19 +31,21 @@ public sealed class DotNetMSBuildSdkResolver : SdkResolver public override int Priority => 5000; private readonly Func _getEnvironmentVariable; + private readonly Func _getCurrentProcessPath; private readonly NETCoreSdkResolver _netCoreSdkResolver; private static CachingWorkloadResolver _staticWorkloadResolver = new CachingWorkloadResolver(); public DotNetMSBuildSdkResolver() - : this(Environment.GetEnvironmentVariable, VSSettings.Ambient) + : this(Environment.GetEnvironmentVariable, null, VSSettings.Ambient) { } // Test constructor - public DotNetMSBuildSdkResolver(Func getEnvironmentVariable, VSSettings vsSettings) + public DotNetMSBuildSdkResolver(Func getEnvironmentVariable, Func getCurrentProcessPath, VSSettings vsSettings) { _getEnvironmentVariable = getEnvironmentVariable; + _getCurrentProcessPath = getCurrentProcessPath; _netCoreSdkResolver = new NETCoreSdkResolver(getEnvironmentVariable, vsSettings); } @@ -87,7 +89,7 @@ public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext if (msbuildSdksDir == null) { - dotnetRoot = EnvironmentProvider.GetDotnetExeDirectory(_getEnvironmentVariable); + dotnetRoot = EnvironmentProvider.GetDotnetExeDirectory(_getEnvironmentVariable, _getCurrentProcessPath); string globalJsonStartDir = GetGlobalJsonStartDir(context); var resolverResult = _netCoreSdkResolver.ResolveNETCoreSdkDirectory(globalJsonStartDir, context.MSBuildVersion, context.IsRunningInVisualStudio, dotnetRoot); diff --git a/src/Resolvers/Microsoft.DotNet.NativeWrapper/EnvironmentProvider.cs b/src/Resolvers/Microsoft.DotNet.NativeWrapper/EnvironmentProvider.cs index a3f8d6c528ce..270c42a95309 100644 --- a/src/Resolvers/Microsoft.DotNet.NativeWrapper/EnvironmentProvider.cs +++ b/src/Resolvers/Microsoft.DotNet.NativeWrapper/EnvironmentProvider.cs @@ -16,10 +16,16 @@ public class EnvironmentProvider private IEnumerable _searchPaths; private readonly Func _getEnvironmentVariable; + private readonly Func _getCurrentProcessPath; public EnvironmentProvider(Func getEnvironmentVariable) + : this(getEnvironmentVariable, GetCurrentProcessPath) + { } + + public EnvironmentProvider(Func getEnvironmentVariable, Func getCurrentProcessPath) { _getEnvironmentVariable = getEnvironmentVariable; + _getCurrentProcessPath = getCurrentProcessPath; } private IEnumerable SearchPaths @@ -61,22 +67,24 @@ public string GetDotnetExeDirectory() return environmentOverride; } - var dotnetExe = GetCommandPath(Constants.DotNet); + string dotnetExe = _getCurrentProcessPath(); - if (dotnetExe != null && !Interop.RunningOnWindows) + if (string.IsNullOrEmpty(dotnetExe) || !Path.GetFileNameWithoutExtension(dotnetExe) + .Equals(Constants.DotNet, StringComparison.InvariantCultureIgnoreCase)) { - // e.g. on Linux the 'dotnet' command from PATH is a symlink so we need to - // resolve it to get the actual path to the binary - dotnetExe = Interop.Unix.realpath(dotnetExe) ?? dotnetExe; - } + string dotnetExeFromPath = GetCommandPath(Constants.DotNet); + + if (dotnetExeFromPath != null && !Interop.RunningOnWindows) + { + // e.g. on Linux the 'dotnet' command from PATH is a symlink so we need to + // resolve it to get the actual path to the binary + dotnetExeFromPath = Interop.Unix.realpath(dotnetExeFromPath) ?? dotnetExeFromPath; + } - if (string.IsNullOrWhiteSpace(dotnetExe)) - { -#if NET6_0_OR_GREATER - dotnetExe = Environment.ProcessPath; -#else - dotnetExe = Process.GetCurrentProcess().MainModule.FileName; -#endif + if (!string.IsNullOrWhiteSpace(dotnetExeFromPath)) + { + dotnetExe = dotnetExeFromPath; + } } return Path.GetDirectoryName(dotnetExe); @@ -91,5 +99,24 @@ public static string GetDotnetExeDirectory(Func getEnvironmentVa var environmentProvider = new EnvironmentProvider(getEnvironmentVariable); return environmentProvider.GetDotnetExeDirectory(); } + + public static string GetDotnetExeDirectory(Func getEnvironmentVariable, Func getCurrentProcessPath) + { + getEnvironmentVariable ??= Environment.GetEnvironmentVariable; + getCurrentProcessPath ??= GetCurrentProcessPath; + var environmentProvider = new EnvironmentProvider(getEnvironmentVariable, getCurrentProcessPath); + return environmentProvider.GetDotnetExeDirectory(); + } + + private static string GetCurrentProcessPath() + { + string currentProcessPath; +#if NET6_0_OR_GREATER + currentProcessPath = Environment.ProcessPath; +#else + currentProcessPath = Process.GetCurrentProcess().MainModule.FileName; +#endif + return currentProcessPath; + } } } diff --git a/src/Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs b/src/Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs index fe3c2abf48c6..488607149f4a 100644 --- a/src/Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs +++ b/src/Tests/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs @@ -74,7 +74,7 @@ public void ItFindsTheVersionSpecifiedInGlobalJson() new MockContext { ProjectFileDirectory = environment.TestDirectory }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be(expected.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be("99.99.98"); @@ -99,7 +99,7 @@ public void ItUsesProjectDirectoryIfSolutionFilePathIsNullOrWhitespace(string so new MockContext { ProjectFileDirectory = environment.TestDirectory, SolutionFilePath = solutionFilePath }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().StartWith(environment.TestDirectory.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be(version); @@ -126,7 +126,7 @@ public void ItUsesCurrentDirectoryIfSolutionFilePathAndProjectFilePathIsNullOrWh new MockContext { ProjectFilePath = projectFilePath, SolutionFilePath = solutionFilePath }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().StartWith(environment.TestDirectory.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be(version); @@ -207,7 +207,7 @@ public void ItReturnsHighestSdkAvailableThatIsCompatibleWithMSBuild(bool disallo }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be((disallowPreviews ? compatibleRtm : compatiblePreview).FullName); result.AdditionalPaths.Should().BeNull(); result.PropertiesToAdd.Should().BeNull(); @@ -281,7 +281,7 @@ public void ItReturnsHighestSdkAvailableThatIsCompatibleWithMSBuildWhenVersionIn }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be((disallowPreviews ? compatibleRtm : compatiblePreview).FullName); result.AdditionalPaths.Should().BeNull(); result.PropertiesToAdd.Count.Should().Be(2); @@ -352,7 +352,7 @@ public void ItReturnsTheVersionIfItIsEqualToTheMinVersionAndTheVSDefinedMinVersi new MockContext { ProjectFileDirectory = environment.TestDirectory }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be(expected.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be("99.99.99"); @@ -374,7 +374,7 @@ public void ItReturnsTheVersionIfItIsHigherThanTheMinVersionAndTheVSDefinedMinVe new MockContext { ProjectFileDirectory = environment.TestDirectory }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be(expected.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be("999.99.99"); @@ -401,7 +401,7 @@ public void ItDisallowsPreviewsBasedOnDefault(bool disallowPreviewsByDefault) new MockContext { ProjectFileDirectory = environment.TestDirectory }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be(expected.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be(disallowPreviewsByDefault ? "10.0.0" : "11.0.0-preview1"); @@ -429,7 +429,7 @@ public void ItDisallowsPreviewsBasedOnFile(bool disallowPreviews) new MockContext { ProjectFileDirectory = environment.TestDirectory }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be(expected.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be(disallowPreviews ? "10.0.0" : "11.0.0-preview1"); @@ -503,7 +503,7 @@ public void ItAllowsPreviewWhenGlobalJsonHasPreviewIrrespectiveOfSetting() new MockContext { ProjectFileDirectory = environment.TestDirectory }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be(preview.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be("11.0.0-preview1"); @@ -532,7 +532,7 @@ public void ItRespectsAmbientVSSettings() new MockContext { ProjectFileDirectory = environment.TestDirectory }, new MockFactory()); - result.Success.Should().BeTrue(); + result.Success.Should().BeTrue($"No error expected. Error encountered: {string.Join(Environment.NewLine, result.Errors ?? new string[]{})}. Mocked Process Path: {environment.ProcessPath}. Mocked Path: {environment.PathEnvironmentVariable}"); result.Path.Should().Be(expected.FullName); result.AdditionalPaths.Should().BeNull(); result.Version.Should().Be(vsSettings.DisallowPrerelease() ? "10.0.0" : "11.0.0-preview1"); @@ -548,7 +548,9 @@ public void GivenTemplateLocatorItCanResolveSdkVersion() environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", sdkVersion); environment.CreateMuxerAndAddToPath(ProgramFiles.X64); - var resolver = new TemplateLocator.TemplateLocator(environment.GetEnvironmentVariable, + var resolver = new TemplateLocator.TemplateLocator( + environment.GetEnvironmentVariable, + () => environment.ProcessPath, new sdkResolver::Microsoft.DotNet.DotNetSdkResolver.VSSettings(environment.VSSettingsFile?.FullName, environment.DisallowPrereleaseByDefault), null, null); resolver.TryGetDotnetSdkVersionUsedInVs("15.8", out var version).Should().BeTrue(); @@ -568,6 +570,8 @@ private sealed class TestEnvironment : SdkResolverContext public string PathEnvironmentVariable { get; set; } + public string ProcessPath { get; set; } + public DirectoryInfo TestDirectory { get; } public FileInfo VSSettingsFile { get; set; } public bool DisallowPrereleaseByDefault { get; set; } @@ -588,6 +592,8 @@ public TestEnvironment(TestAssetsManager testAssets, string identifier = "", [Ca public SdkResolver CreateResolver(bool useAmbientSettings = false) => new DotNetMSBuildSdkResolver( GetEnvironmentVariable, + // force current executable location to be the mocked dotnet executable location + () => ProcessPath, useAmbientSettings ? VSSettings.Ambient : new VSSettings(VSSettingsFile?.FullName, DisallowPrereleaseByDefault)); @@ -629,7 +635,8 @@ public void CreateMuxerAndAddToPath(ProgramFiles programFiles) new DirectoryInfo(Path.Combine( TestDirectory.FullName, GetProgramFilesDirectory(programFiles).FullName, "dotnet")); - new FileInfo(Path.Combine(muxerDirectory.FullName, Muxer)).Create(); + ProcessPath = Path.Combine(muxerDirectory.FullName, Muxer); + new FileInfo(ProcessPath).Create(); PathEnvironmentVariable = $"{muxerDirectory}{Path.PathSeparator}{PathEnvironmentVariable}"; } diff --git a/src/Tests/Microsoft.DotNet.PackageInstall.Tests/ToolPackageInstallerTests.cs b/src/Tests/Microsoft.DotNet.PackageInstall.Tests/ToolPackageInstallerTests.cs index e2593cc86abb..714c653353f9 100644 --- a/src/Tests/Microsoft.DotNet.PackageInstall.Tests/ToolPackageInstallerTests.cs +++ b/src/Tests/Microsoft.DotNet.PackageInstall.Tests/ToolPackageInstallerTests.cs @@ -33,7 +33,22 @@ namespace Microsoft.DotNet.PackageInstall.Tests { - public class ToolPackageInstallerTests : SdkTest + internal class DotnetEnvironmentTestFixture : IDisposable + { + private readonly string _originalPath; + private const string _PATH_VAR_NAME = "PATH"; + + public DotnetEnvironmentTestFixture() + { + string dotnetRootUnderTest = TestContext.Current.ToolsetUnderTest.DotNetRoot; + _originalPath = Environment.GetEnvironmentVariable(_PATH_VAR_NAME); + Environment.SetEnvironmentVariable(_PATH_VAR_NAME, dotnetRootUnderTest + Path.PathSeparator + _originalPath); + } + + public void Dispose() => Environment.SetEnvironmentVariable(_PATH_VAR_NAME, _originalPath); + } + + public class ToolPackageInstallerTests : SdkTest, IClassFixture { [Theory] [InlineData(false)] diff --git a/src/Tests/Microsoft.DotNet.TemplateLocator.Tests/GivenAnTemplateLocator.cs b/src/Tests/Microsoft.DotNet.TemplateLocator.Tests/GivenAnTemplateLocator.cs index 6ddb438444dc..3a6bc691a2a3 100644 --- a/src/Tests/Microsoft.DotNet.TemplateLocator.Tests/GivenAnTemplateLocator.cs +++ b/src/Tests/Microsoft.DotNet.TemplateLocator.Tests/GivenAnTemplateLocator.cs @@ -20,7 +20,7 @@ public class GivenAnTemplateLocator : SdkTest public GivenAnTemplateLocator(ITestOutputHelper logger) : base(logger) { - _resolver = new TemplateLocator(Environment.GetEnvironmentVariable, VSSettings.Ambient, null, null); + _resolver = new TemplateLocator(Environment.GetEnvironmentVariable, null, VSSettings.Ambient, null, null); _fakeDotnetRootDirectory = Path.Combine(TestContext.Current.TestExecutionDirectory, Path.GetRandomFileName()); diff --git a/src/Tests/dotnet-new.Tests/SdkInfoProviderTests.cs b/src/Tests/dotnet-new.Tests/SdkInfoProviderTests.cs index f83b233342c6..050005f36007 100644 --- a/src/Tests/dotnet-new.Tests/SdkInfoProviderTests.cs +++ b/src/Tests/dotnet-new.Tests/SdkInfoProviderTests.cs @@ -33,7 +33,8 @@ public void GetInstalledVersionsAsync_ShouldContainCurrentVersion() try { - ISdkInfoProvider sp = new SdkInfoProvider(); + // make sure current process path is not picked up as the dontet executable location + ISdkInfoProvider sp = new SdkInfoProvider(() => string.Empty); string currentVersion = sp.GetCurrentVersionAsync(default).Result; List allVersions = sp.GetInstalledVersionsAsync(default).Result?.ToList();