diff --git a/src/Microsoft.DotNet.Configurer/NuGetCacheSentinel.cs b/src/Microsoft.DotNet.Configurer/NuGetCacheSentinel.cs index a0feea827..bf17272b7 100644 --- a/src/Microsoft.DotNet.Configurer/NuGetCacheSentinel.cs +++ b/src/Microsoft.DotNet.Configurer/NuGetCacheSentinel.cs @@ -17,25 +17,13 @@ namespace Microsoft.DotNet.Configurer private string _nugetCachePath; - private string NuGetCachePath - { - get - { - if (string.IsNullOrEmpty(_nugetCachePath)) - { - _nugetCachePath = NuGetPathContext.Create(new NullSettings()).UserPackageFolder; - } - - return _nugetCachePath; - } - } - - private string SentinelPath => Path.Combine(NuGetCachePath, SENTINEL); - private string InProgressSentinelPath => Path.Combine(NuGetCachePath, INPROGRESS_SENTINEL); + private string SentinelPath => Path.Combine(_nugetCachePath, SENTINEL); + private string InProgressSentinelPath => Path.Combine(_nugetCachePath, INPROGRESS_SENTINEL); private Stream InProgressSentinel { get; set; } - public NuGetCacheSentinel() : this(string.Empty, FileSystemWrapper.Default.File) + public NuGetCacheSentinel(CLIFallbackFolderPathCalculator cliFallbackFolderPathCalculator) : + this(cliFallbackFolderPathCalculator.CLIFallbackFolderPath, FileSystemWrapper.Default.File) { } @@ -74,9 +62,9 @@ namespace Microsoft.DotNet.Configurer { try { - if(!Directory.Exists(NuGetCachePath)) + if(!Directory.Exists(_nugetCachePath)) { - Directory.CreateDirectory(NuGetCachePath); + Directory.CreateDirectory(_nugetCachePath); } // open an exclusive handle to the in-progress sentinel and mark it for delete on close. diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 989956781..ad0c11f67 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -79,7 +79,8 @@ namespace Microsoft.DotNet.Cli var success = true; var command = string.Empty; var lastArg = 0; - using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel()) + var cliFallbackFolderPathCalculator = new CLIFallbackFolderPathCalculator(); + using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel(cliFallbackFolderPathCalculator)) { for (; lastArg < args.Length; lastArg++) { @@ -111,7 +112,7 @@ namespace Microsoft.DotNet.Cli } else { - ConfigureDotNetForFirstTimeUse(nugetCacheSentinel); + ConfigureDotNetForFirstTimeUse(nugetCacheSentinel, cliFallbackFolderPathCalculator); // It's the command, and we're done! command = args[lastArg]; @@ -165,28 +166,27 @@ namespace Microsoft.DotNet.Cli } - private static void ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel) + private static void ConfigureDotNetForFirstTimeUse( + INuGetCacheSentinel nugetCacheSentinel, + CLIFallbackFolderPathCalculator cliFallbackFolderPathCalculator) { using (PerfTrace.Current.CaptureTiming()) { - using (var nugetPackagesArchiver = new NuGetPackagesArchiver()) - { - var cliFallbackFolderPathCalculator = new CLIFallbackFolderPathCalculator(); - var environmentProvider = new EnvironmentProvider(); - var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true); - var nugetConfig = new NuGetConfi(cliFallbackFolderPathCalculator); - var nugetCachePrimer = new NuGetCachePrimer( - nugetPackagesArchiver, - nugetCacheSentinel, - nugetConfig, - cliFallbackFolderPathCalculator); - var dotnetConfigurer = new DotnetFirstTimeUseConfigurer( - nugetCachePrimer, - nugetCacheSentinel, - environmentProvider); + var nugetPackagesArchiver = new NuGetPackagesArchiver(); + var environmentProvider = new EnvironmentProvider(); + var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true); + var nugetConfig = new NuGetConfig(cliFallbackFolderPathCalculator); + var nugetCachePrimer = new NuGetCachePrimer( + nugetPackagesArchiver, + nugetCacheSentinel, + nugetConfig, + cliFallbackFolderPathCalculator); + var dotnetConfigurer = new DotnetFirstTimeUseConfigurer( + nugetCachePrimer, + nugetCacheSentinel, + environmentProvider); - dotnetConfigurer.Configure(); - } + dotnetConfigurer.Configure(); } } diff --git a/src/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs b/src/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs index 88d64a832..a967bb1ce 100644 --- a/src/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs +++ b/src/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Tools.MSBuild { public sealed class MSBuildLogger : Logger { - private readonly INuGetCacheSentinel _sentinel = new NuGetCacheSentinel(); + private readonly INuGetCacheSentinel _sentinel = new NuGetCacheSentinel(new CLIFallbackFolderPathCalculator()); private readonly ITelemetry _telemetry; public MSBuildLogger()