diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index 0861f2016..ca0485887 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -5,7 +5,7 @@ $(MicrosoftAspNetCoreAllPackageVersion) 2.1.0-rtm-26515-03 $(MicrosoftNETCoreAppPackageVersion) - 15.7.179 + 15.8.0-preview-000061 $(MicrosoftBuildPackageVersion) $(MicrosoftBuildPackageVersion) $(MicrosoftBuildPackageVersion) @@ -45,6 +45,7 @@ $(NuGetBuildTasksPackageVersion) $(NuGetBuildTasksPackageVersion) $(NuGetBuildTasksPackageVersion) + $(NuGetBuildTasksPackageVersion) 15.8.0-preview-20180510-03 $(MicrosoftNETTestSdkPackageVersion) $(MicrosoftNETTestSdkPackageVersion) diff --git a/netci.groovy b/netci.groovy index f06ec6ed6..c2283cd23 100644 --- a/netci.groovy +++ b/netci.groovy @@ -3,6 +3,7 @@ // Import the utility functionality. +import jobs.generation.ArchivalSettings; import jobs.generation.Utilities; def project = GithubProject @@ -108,6 +109,12 @@ set DOTNET_CLI_UI_LANGUAGE=es Utilities.addMSTestResults(newJob, '**/*.trx') } Utilities.addGithubPRTriggerForBranch(newJob, branch, "${os} ${architecture} ${configuration} Build") + + def archiveSettings = new ArchivalSettings() + archiveSettings.addFiles("test/**/*.trx") + archiveSettings.setFailIfNothingArchived() + archiveSettings.setArchiveOnFailure() + Utilities.addArchival(newJob, archiveSettings) } // Make the call to generate the help job diff --git a/scripts/obtain/dotnet-install.ps1 b/scripts/obtain/dotnet-install.ps1 index 1a35ec4fb..5bfd355eb 100644 --- a/scripts/obtain/dotnet-install.ps1 +++ b/scripts/obtain/dotnet-install.ps1 @@ -522,6 +522,7 @@ else { throw "Invalid value for `$Runtime" } +# Check if the SDK version is already installed. $isAssetInstalled = Is-Dotnet-Package-Installed -InstallRoot $InstallRoot -RelativePathToPackage $dotnetPackageRelativePath -SpecificVersion $SpecificVersion if ($isAssetInstalled) { Say "$assetName version $SpecificVersion is already installed." @@ -561,6 +562,12 @@ catch { Say "Extracting zip from $DownloadLink" Extract-Dotnet-Package -ZipPath $ZipPath -OutPath $InstallRoot +# Check if the SDK version is now installed; if not, fail the installation. +$isAssetInstalled = Is-Dotnet-Package-Installed -InstallRoot $InstallRoot -RelativePathToPackage $dotnetPackageRelativePath -SpecificVersion $SpecificVersion +if (!$isAssetInstalled) { + throw "$assetName version $SpecificVersion failed to install with an unknown error." +} + Remove-Item $ZipPath Prepend-Sdk-InstallRoot-To-Path -InstallRoot $InstallRoot -BinFolderRelativePath $BinFolderRelativePath diff --git a/scripts/obtain/dotnet-install.sh b/scripts/obtain/dotnet-install.sh index 6d17c58e7..cee78b1ae 100755 --- a/scripts/obtain/dotnet-install.sh +++ b/scripts/obtain/dotnet-install.sh @@ -754,6 +754,7 @@ install_dotnet() { return 1 fi + # Check if the SDK version is already installed. if is_dotnet_package_installed "$install_root" "$asset_relative_path" "$specific_version"; then say "$asset_name version $specific_version is already installed." return 0 @@ -791,6 +792,12 @@ install_dotnet() { say "Extracting zip from $download_link" extract_dotnet_package "$zip_path" "$install_root" + # Check if the SDK version is now installed; if not, fail the installation. + if ! is_dotnet_package_installed "$install_root" "$asset_relative_path" "$specific_version"; then + say_err "$asset_name version $specific_version failed to install with an unknown error." + return 1 + fi + return 0 } diff --git a/src/Microsoft.DotNet.Cli.Utils/FileAccessRetryer.cs b/src/Microsoft.DotNet.Cli.Utils/FileAccessRetryer.cs index f73d5d4d1..80201ecac 100644 --- a/src/Microsoft.DotNet.Cli.Utils/FileAccessRetryer.cs +++ b/src/Microsoft.DotNet.Cli.Utils/FileAccessRetryer.cs @@ -3,6 +3,7 @@ using System; using System.IO; +using System.Threading; using System.Threading.Tasks; namespace Microsoft.DotNet.Cli.Utils @@ -47,5 +48,35 @@ namespace Microsoft.DotNet.Cli.Utils } } } + + /// + /// Run Directory.Move and File.Move in Windows has a chance to get IOException with + /// HResult 0x80070005 due to Indexer. But this error is transient. + /// + internal static void RetryOnMoveAccessFailure(Action action) + { + const int ERROR_HRESULT_ACCESS_DENIED = unchecked((int)0x80070005); + int nextWaitTime = 10; + int remainRetry = 10; + + while (true) + { + try + { + action(); + break; + } + catch (IOException e) when (e.HResult == ERROR_HRESULT_ACCESS_DENIED) + { + Thread.Sleep(nextWaitTime); + nextWaitTime *= 2; + remainRetry--; + if (remainRetry == 0) + { + throw; + } + } + } + } } } diff --git a/src/Microsoft.DotNet.Configurer/DotnetFirstRunConfiguration.cs b/src/Microsoft.DotNet.Configurer/DotnetFirstRunConfiguration.cs new file mode 100644 index 000000000..b959c7c41 --- /dev/null +++ b/src/Microsoft.DotNet.Configurer/DotnetFirstRunConfiguration.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.DotNet.Configurer +{ + public class DotnetFirstRunConfiguration + { + public bool GenerateAspNetCertificate { get; } + + public bool PrintTelemetryMessage { get; } + + public bool SkipFirstRunExperience { get; } + + public DotnetFirstRunConfiguration( + bool generateAspNetCertificate, + bool printTelemetryMessage, + bool skipFirstRunExperience) + { + GenerateAspNetCertificate = generateAspNetCertificate; + PrintTelemetryMessage = printTelemetryMessage; + SkipFirstRunExperience = skipFirstRunExperience; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs b/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs index 2cb502256..94478909b 100644 --- a/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs +++ b/src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Configurer public class DotnetFirstTimeUseConfigurer { private IReporter _reporter; - private IEnvironmentProvider _environmentProvider; + private DotnetFirstRunConfiguration _dotnetFirstRunConfiguration; private INuGetCachePrimer _nugetCachePrimer; private INuGetCacheSentinel _nugetCacheSentinel; private IFirstTimeUseNoticeSentinel _firstTimeUseNoticeSentinel; @@ -29,7 +29,7 @@ namespace Microsoft.DotNet.Configurer IAspNetCertificateSentinel aspNetCertificateSentinel, IAspNetCoreCertificateGenerator aspNetCoreCertificateGenerator, IFileSentinel toolPathSentinel, - IEnvironmentProvider environmentProvider, + DotnetFirstRunConfiguration dotnetFirstRunConfiguration, IReporter reporter, string cliFallbackFolderPath, IEnvironmentPath pathAdder) @@ -40,7 +40,7 @@ namespace Microsoft.DotNet.Configurer _aspNetCertificateSentinel = aspNetCertificateSentinel; _aspNetCoreCertificateGenerator = aspNetCoreCertificateGenerator; _toolPathSentinel = toolPathSentinel; - _environmentProvider = environmentProvider; + _dotnetFirstRunConfiguration = dotnetFirstRunConfiguration; _reporter = reporter; _cliFallbackFolderPath = cliFallbackFolderPath; _pathAdder = pathAdder ?? throw new ArgumentNullException(nameof(pathAdder)); @@ -93,11 +93,8 @@ namespace Microsoft.DotNet.Configurer #if EXCLUDE_ASPNETCORE return false; #else - var generateAspNetCertificate = - _environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true); - return ShouldRunFirstRunExperience() && - generateAspNetCertificate && + _dotnetFirstRunConfiguration.GenerateAspNetCertificate && !_aspNetCertificateSentinel.Exists(); #endif } @@ -116,11 +113,8 @@ namespace Microsoft.DotNet.Configurer private bool ShouldPrintFirstTimeUseNotice() { - var showFirstTimeUseNotice = - _environmentProvider.GetEnvironmentVariableAsBool("DOTNET_PRINT_TELEMETRY_MESSAGE", true); - return ShouldRunFirstRunExperience() && - showFirstTimeUseNotice && + _dotnetFirstRunConfiguration.PrintTelemetryMessage && !_firstTimeUseNoticeSentinel.Exists(); } @@ -157,10 +151,7 @@ namespace Microsoft.DotNet.Configurer private bool ShouldRunFirstRunExperience() { - var skipFirstTimeExperience = - _environmentProvider.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false); - - return !skipFirstTimeExperience; + return !_dotnetFirstRunConfiguration.SkipFirstRunExperience; } } } diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index ce08bcb56..2e9dafea5 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -141,6 +141,15 @@ namespace Microsoft.DotNet.Cli command = "help"; } + var environmentProvider = new EnvironmentProvider(); + + bool generateAspNetCertificate = + environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true); + bool printTelemetryMessage = + environmentProvider.GetEnvironmentVariableAsBool("DOTNET_PRINT_TELEMETRY_MESSAGE", true); + bool skipFirstRunExperience = + environmentProvider.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false); + topLevelCommandParserResult = new TopLevelCommandParserResult(command); var hasSuperUserAccess = false; if (IsDotnetBeingInvokedFromNativeInstaller(topLevelCommandParserResult)) @@ -149,15 +158,26 @@ namespace Microsoft.DotNet.Cli firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); toolPathSentinel = new NoOpFileSentinel(exists: false); hasSuperUserAccess = true; + + // When running through a native installer, we want the cache expansion to happen, so + // we need to override this. + skipFirstRunExperience = false; } + var dotnetFirstRunConfiguration = new DotnetFirstRunConfiguration( + generateAspNetCertificate, + printTelemetryMessage, + skipFirstRunExperience); + ConfigureDotNetForFirstTimeUse( nugetCacheSentinel, firstTimeUseNoticeSentinel, aspNetCertificateSentinel, toolPathSentinel, cliFallbackFolderPathCalculator, - hasSuperUserAccess); + hasSuperUserAccess, + dotnetFirstRunConfiguration, + environmentProvider); break; } @@ -222,15 +242,17 @@ namespace Microsoft.DotNet.Cli IAspNetCertificateSentinel aspNetCertificateSentinel, IFileSentinel toolPathSentinel, CliFolderPathCalculator cliFolderPathCalculator, - bool hasSuperUserAccess) + bool hasSuperUserAccess, + DotnetFirstRunConfiguration dotnetFirstRunConfiguration, + IEnvironmentProvider environmentProvider) { - var environmentProvider = new EnvironmentProvider(); - using (PerfTrace.Current.CaptureTiming()) { var nugetPackagesArchiver = new NuGetPackagesArchiver(); - var environmentPath = - EnvironmentPathFactory.CreateEnvironmentPath(cliFolderPathCalculator, hasSuperUserAccess, environmentProvider); + var environmentPath = EnvironmentPathFactory.CreateEnvironmentPath( + cliFolderPathCalculator, + hasSuperUserAccess, + environmentProvider); var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true); var nugetCachePrimer = new NuGetCachePrimer( nugetPackagesArchiver, @@ -244,7 +266,7 @@ namespace Microsoft.DotNet.Cli aspNetCertificateSentinel, aspnetCertificateGenerator, toolPathSentinel, - environmentProvider, + dotnetFirstRunConfiguration, Reporter.Output, cliFolderPathCalculator.CliFallbackFolderPath, environmentPath); diff --git a/src/dotnet/ShellShim/ShellShimRepository.cs b/src/dotnet/ShellShim/ShellShimRepository.cs index 121582cf6..a2ebd78a4 100644 --- a/src/dotnet/ShellShim/ShellShimRepository.cs +++ b/src/dotnet/ShellShim/ShellShimRepository.cs @@ -113,7 +113,7 @@ namespace Microsoft.DotNet.ShellShim foreach (var file in GetShimFiles(commandName).Where(f => _fileSystem.File.Exists(f.Value))) { var tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); - _fileSystem.File.Move(file.Value, tempPath); + FileAccessRetrier.RetryOnMoveAccessFailure(() => _fileSystem.File.Move(file.Value, tempPath)); files[file.Value] = tempPath; } } @@ -137,7 +137,7 @@ namespace Microsoft.DotNet.ShellShim rollback: () => { foreach (var kvp in files) { - _fileSystem.File.Move(kvp.Value, kvp.Key); + FileAccessRetrier.RetryOnMoveAccessFailure(() => _fileSystem.File.Move(kvp.Value, kvp.Key)); } }); } diff --git a/src/dotnet/ToolPackage/ToolPackageInstaller.cs b/src/dotnet/ToolPackage/ToolPackageInstaller.cs index 674067bdf..c7df5f18a 100644 --- a/src/dotnet/ToolPackage/ToolPackageInstaller.cs +++ b/src/dotnet/ToolPackage/ToolPackageInstaller.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Xml.Linq; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Configurer; using Microsoft.DotNet.Tools; using Microsoft.Extensions.EnvironmentAbstractions; @@ -82,7 +83,7 @@ namespace Microsoft.DotNet.ToolPackage } Directory.CreateDirectory(packageRootDirectory.Value); - Directory.Move(stageDirectory.Value, packageDirectory.Value); + FileAccessRetrier.RetryOnMoveAccessFailure(() => Directory.Move(stageDirectory.Value, packageDirectory.Value)); rollbackDirectory = packageDirectory.Value; return new ToolPackageInstance(_store, packageId, version, packageDirectory); diff --git a/src/dotnet/ToolPackage/ToolPackageInstance.cs b/src/dotnet/ToolPackage/ToolPackageInstance.cs index c8be8d5ca..9a8041582 100644 --- a/src/dotnet/ToolPackage/ToolPackageInstance.cs +++ b/src/dotnet/ToolPackage/ToolPackageInstance.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.EnvironmentAbstractions; using NuGet.ProjectModel; using NuGet.Versioning; using Microsoft.DotNet.Cli.Utils; +using System.Threading; namespace Microsoft.DotNet.ToolPackage { @@ -79,7 +80,7 @@ namespace Microsoft.DotNet.ToolPackage // Use the staging directory for uninstall // This prevents cross-device moves when temp is mounted to a different device var tempPath = _store.GetRandomStagingDirectory().Value; - Directory.Move(PackageDirectory.Value, tempPath); + FileAccessRetrier.RetryOnMoveAccessFailure(() => Directory.Move(PackageDirectory.Value, tempPath)); tempPackageDirectory = tempPath; } @@ -111,7 +112,7 @@ namespace Microsoft.DotNet.ToolPackage if (tempPackageDirectory != null) { Directory.CreateDirectory(rootDirectory.Value); - Directory.Move(tempPackageDirectory, PackageDirectory.Value); + FileAccessRetrier.RetryOnMoveAccessFailure(() => Directory.Move(tempPackageDirectory, PackageDirectory.Value)); } }); } diff --git a/src/redist/redist.csproj b/src/redist/redist.csproj index a03bbac1e..7ce296c7e 100644 --- a/src/redist/redist.csproj +++ b/src/redist/redist.csproj @@ -17,6 +17,7 @@ + @@ -283,6 +284,9 @@ + + + diff --git a/test/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurer.cs b/test/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurer.cs index 115acacd7..37036602d 100644 --- a/test/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurer.cs +++ b/test/Microsoft.DotNet.Configurer.UnitTests/GivenADotnetFirstTimeUseConfigurer.cs @@ -21,7 +21,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests private Mock _aspNetCertificateSentinelMock; private Mock _aspNetCoreCertificateGeneratorMock; private Mock _toolPathSentinelMock; - private Mock _environmentProviderMock; private Mock _reporterMock; private Mock _pathAdderMock; @@ -33,16 +32,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock = new Mock(); _aspNetCoreCertificateGeneratorMock = new Mock(); _toolPathSentinelMock = new Mock(); - _environmentProviderMock = new Mock(); _reporterMock = new Mock(); _pathAdderMock = new Mock(); - - _environmentProviderMock - .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false)) - .Returns(false); - _environmentProviderMock - .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_PRINT_TELEMETRY_MESSAGE", true)) - .Returns(true); } [Fact] @@ -57,7 +48,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -72,9 +68,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests public void It_does_not_print_the_first_time_use_notice_when_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environemnt_variable() { _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false); - _environmentProviderMock - .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false)) - .Returns(true); var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( _nugetCachePrimerMock.Object, @@ -83,7 +76,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: true + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -98,9 +96,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests public void It_does_not_print_the_first_time_use_notice_when_the_user_has_set_the_DOTNET_PRINT_TELEMETRY_MESSAGE_environemnt_variable() { _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false); - _environmentProviderMock - .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_PRINT_TELEMETRY_MESSAGE", true)) - .Returns(false); var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( _nugetCachePrimerMock.Object, @@ -109,7 +104,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: false, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -132,7 +132,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -155,7 +160,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -177,7 +187,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -199,7 +214,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -210,12 +230,9 @@ namespace Microsoft.DotNet.Configurer.UnitTests } [Fact] - public void It_does_not_prime_the_cache_if_the_sentinel_exists_but_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environemnt_variable() + public void It_does_not_prime_the_cache_if_the_sentinel_does_not_exist_but_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environment_variable() { _nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(false); - _environmentProviderMock - .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false)) - .Returns(true); var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( _nugetCachePrimerMock.Object, @@ -224,7 +241,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: true + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -246,7 +268,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -269,7 +296,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -295,7 +327,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -322,7 +359,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -345,7 +387,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -368,7 +415,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -398,7 +450,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -420,7 +477,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -435,9 +497,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests public void It_does_not_generate_the_aspnet_https_development_certificate_when_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environment_variable() { _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false); - _environmentProviderMock - .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false)) - .Returns(true); var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( _nugetCachePrimerMock.Object, @@ -446,7 +505,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: true + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -461,9 +525,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests public void It_does_not_generate_the_aspnet_https_development_certificate_when_the_user_has_set_the_DOTNET_GENERATE_ASPNET_CERTIFICATE_environment_variable() { _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false); - _environmentProviderMock - .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true)) - .Returns(false); var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( _nugetCachePrimerMock.Object, @@ -472,7 +533,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: false, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -487,8 +553,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests public void It_generates_the_aspnet_https_development_certificate_if_the_sentinel_does_not_exist() { _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false); - _environmentProviderMock.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true)) - .Returns(true); var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( _nugetCachePrimerMock.Object, @@ -497,7 +561,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -520,7 +589,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: false + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); @@ -533,10 +607,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests [Fact] public void It_does_not_add_the_tool_path_to_the_environment_if_the_first_run_experience_is_skipped() { - _environmentProviderMock - .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false)) - .Returns(true); - var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer( _nugetCachePrimerMock.Object, _nugetCacheSentinelMock.Object, @@ -544,7 +614,12 @@ namespace Microsoft.DotNet.Configurer.UnitTests _aspNetCertificateSentinelMock.Object, _aspNetCoreCertificateGeneratorMock.Object, _toolPathSentinelMock.Object, - _environmentProviderMock.Object, + new DotnetFirstRunConfiguration + ( + generateAspNetCertificate: true, + printTelemetryMessage: true, + skipFirstRunExperience: true + ), _reporterMock.Object, CliFallbackFolderPath, _pathAdderMock.Object); diff --git a/test/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs b/test/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs index 97e1db0be..bea3dde7e 100644 --- a/test/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs +++ b/test/Microsoft.DotNet.MSBuildSdkResolver.Tests/GivenAnMSBuildSdkResolver.cs @@ -334,19 +334,34 @@ namespace Microsoft.DotNet.Cli.Utils.Tests private sealed class MockFactory : SdkResultFactory { public override SdkResult IndicateFailure(IEnumerable errors, IEnumerable warnings = null) - => new MockResult { Success = false, Errors = errors, Warnings = warnings }; + => new MockResult(success: false, path: null, version: null, warnings: warnings, errors: errors); public override SdkResult IndicateSuccess(string path, string version, IEnumerable warnings = null) - => new MockResult { Success = true, Path = path, Version = version, Warnings = warnings }; + => new MockResult(success: true, path: path, version: version, warnings: warnings); } private sealed class MockResult : SdkResult { - public new bool Success { get => base.Success; set => base.Success = value; } - public string Version { get; set; } - public string Path { get; set; } - public IEnumerable Errors { get; set; } - public IEnumerable Warnings { get; set; } + public MockResult(bool success, string path, string version, IEnumerable warnings = null, + IEnumerable errors = null) + { + Success = success; + Path = path; + Version = version; + Warnings = warnings; + Errors = errors; + } + + public new bool Success + { + get => base.Success; + private set => base.Success = value; + } + + public override string Version { get; protected set; } + public override string Path { get; protected set; } + public IEnumerable Errors { get; } + public IEnumerable Warnings { get; } } } } diff --git a/test/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.csproj b/test/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.csproj index 59b36f03c..8c85a02fe 100644 --- a/test/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.csproj +++ b/test/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.csproj @@ -13,9 +13,5 @@ - - - - - + \ No newline at end of file