From beec7ddbd13f8610fcb9db458aea203dda0558bd Mon Sep 17 00:00:00 2001 From: heng-liu <45407901+heng-liu@users.noreply.github.com> Date: Mon, 16 Dec 2019 11:20:56 -0800 Subject: [PATCH] Retarget to netcore5.0 (#3162) * retarget to netcore5.0; Linux script workaround need to apply for downloading SDK for build --- build/common.project.props | 4 +- build/common.targets | 4 +- build/config.props | 17 +- build/vsts_build.yaml | 109 ++++++--- global.json | 5 + .../NuGet.CommandLine.Test/Util.cs | 2 +- .../MsbuildIntegrationTestFixture.cs | 223 +++++++++--------- .../HttpRetryHandlerTests.cs | 10 +- .../NuGet.XPlat.FuncTest/DotnetCliUtil.cs | 2 +- 9 files changed, 210 insertions(+), 166 deletions(-) create mode 100644 global.json diff --git a/build/common.project.props b/build/common.project.props index 30967481e3b..3a2a2fb476e 100644 --- a/build/common.project.props +++ b/build/common.project.props @@ -14,8 +14,8 @@ net472 netcoreapp2.1 netcoreapp2.1 - netcoreapp2.1;netcoreapp3.0 - netcoreapp3.0 + netcoreapp2.1;netcoreapp5.0 + netcoreapp5.0 netstandard2.0 $(NETFXTargetFramework);$(NETCoreTargetFrameworks) $(NETFXTargetFramework);$(NetStandardVersion) diff --git a/build/common.targets b/build/common.targets index a6dbea2ac6f..cd089556ebf 100644 --- a/build/common.targets +++ b/build/common.targets @@ -11,8 +11,8 @@ true - - $(DefineConstants);NETCORE3_0 + + $(DefineConstants);NETCORE5_0 diff --git a/build/config.props b/build/config.props index 166a34cc96e..7f1ed66caf7 100644 --- a/build/config.props +++ b/build/config.props @@ -32,20 +32,21 @@ $([MSBuild]::Add(11, $(MajorNuGetVersion))) master int.$(VsTargetBranch) + + rel/d$(VsTargetMajorVersion).$(MinorNuGetVersion) int.d$(VsTargetMajorVersion).$(MinorNuGetVersion) + - - false + + true - release/3.0.1xx 3.0.100-preview7-012802 - 3.1.x - 3.0.100-preview6-012264 - - + master 5.0.100-alpha1-015516 + master + "master 5.0.100-alpha1-015516" $(OverrideCliBranchForTesting) - release/3.1.2xx + master $(OverrideCliTargetBranches) master $(OverrideCliTargetBranches) diff --git a/build/vsts_build.yaml b/build/vsts_build.yaml index e0c5171e2c2..29235d45f1b 100644 --- a/build/vsts_build.yaml +++ b/build/vsts_build.yaml @@ -94,13 +94,11 @@ phases: - msbuild steps: - - task: UseDotNet@2 - displayName: 'Use .NET Core sdk' + - task: PowerShell@1 inputs: - packageType: sdk - version: $(SDKVersionForBuild) - includePreviewVersions: true - installationPath: $(Agent.TempDirectory)/dotnet + scriptName: "$(Build.Repository.LocalPath)\\scripts\\utils\\InstallCLIforBuild.ps1" + arguments: '$(SDKVersionForBuild)' + displayName: "Install .NET 5.0 for build" - task: PowerShell@1 displayName: "Update Build Number" @@ -116,6 +114,7 @@ phases: scriptType: "inlineScript" inlineScript: | Write-Host "##vso[task.setvariable variable=ManifestFilePath]$(Build.Repository.LocalPath)\artifacts\manifests\nuget.client.xml" + Write-Host "##vso[task.setvariable variable=Path]${env:AGENT_TEMPDIRECTORY}\dotnet\;${env:Path}" - task: NuGetToolInstaller@0 displayName: "Use NuGet 5.0.0" @@ -573,13 +572,18 @@ phases: SkipDesktopAssemblies: "true" steps: - - task: UseDotNet@2 - displayName: 'Use .NET Core sdk' + - task: PowerShell@1 + inputs: + scriptName: "$(Build.Repository.LocalPath)\\scripts\\utils\\InstallCLIforBuild.ps1" + arguments: '$(SDKVersionForBuild)' + displayName: "Install .NET 5.0 for build" + + - task: PowerShell@1 + displayName: "Define variables" inputs: - packageType: sdk - version: $(SDKVersionForBuild) - includePreviewVersions: true - installationPath: $(Agent.TempDirectory)/dotnet + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[task.setvariable variable=Path]${env:AGENT_TEMPDIRECTORY}\dotnet\;${env:Path}" - task: PowerShell@1 displayName: "Print Environment Variables" @@ -657,14 +661,23 @@ phases: demands: sh steps: - - task: UseDotNet@2 - displayName: 'Use .NET Core sdk' - inputs: - packageType: sdk - version: $(SDKVersionForBuild) - includePreviewVersions: true - installationPath: $(Agent.TempDirectory)/dotnet - + + - task: ShellScript@2 + displayName: "Install .NET 5.0 for build" + continueOnError: "true" + inputs: + scriptPath: "scripts/utils/InstallCLIforBuild.sh" + disableAutoCwd: "true" + cwd: "$(Build.Repository.LocalPath)" + args: '$(SDKVersionForBuild)' + + - task: PowerShell@2 + displayName: "Define variables" + inputs: + targetType: "inline" + script: | + Write-Host "##vso[task.setvariable variable=PATH]${env:AGENT_TEMPDIRECTORY}/dotnet/:${env:PATH}" + - task: PowerShell@2 displayName: "Update Build Number" inputs: @@ -718,15 +731,16 @@ phases: - VSTS_OS -equals Mac_Mojave_10.14 - Mono -equals 6.4.0 - steps: - - task: UseDotNet@2 - displayName: 'Use .NET Core sdk' - inputs: - packageType: sdk - version: $(SDKVersionForBuild) - includePreviewVersions: true - installationPath: $(Agent.TempDirectory)/dotnet - + steps: + - task: ShellScript@2 + displayName: "Install .NET 5.0 for build" + continueOnError: "true" + inputs: + scriptPath: "scripts/utils/InstallCLIforBuild.sh" + disableAutoCwd: "true" + cwd: "$(Build.Repository.LocalPath)" + args: '$(SDKVersionForBuild)' + - task: PowerShell@2 displayName: "Update Build Number" inputs: @@ -736,6 +750,13 @@ phases: failOnStderr: "true" condition: "always()" + - task: PowerShell@2 + displayName: "Define variables" + inputs: + targetType: "inline" + script: | + Write-Host "##vso[task.setvariable variable=PATH]${env:AGENT_TEMPDIRECTORY}/dotnet/:${env:PATH}" + - task: DownloadBuildArtifacts@0 displayName: "Download NuGet.CommandLine.Test artifacts" inputs: @@ -785,13 +806,18 @@ phases: demands: DotNetFramework steps: - - task: UseDotNet@2 - displayName: 'Use .NET Core sdk' + - task: PowerShell@1 + inputs: + scriptName: "$(Build.Repository.LocalPath)\\scripts\\utils\\InstallCLIforBuild.ps1" + arguments: '$(SDKVersionForBuild)' + displayName: "Install .NET 5.0 for build" + + - task: PowerShell@1 + displayName: "Define variables" inputs: - packageType: sdk - version: $(SDKVersionForBuild) - includePreviewVersions: true - installationPath: $(Agent.TempDirectory)/dotnet + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[task.setvariable variable=Path]${env:AGENT_TEMPDIRECTORY}\dotnet\;${env:Path}" - task: PowerShell@1 displayName: "Print Environment Variables" @@ -913,6 +939,19 @@ phases: inputs: versionSpec: "4.5.0" + - task: PowerShell@1 + inputs: + scriptName: "$(Build.Repository.LocalPath)\\scripts\\utils\\InstallCLIforBuild.ps1" + arguments: '$(SDKVersionForBuild)' + displayName: "Install .NET 5.0 for build" + + - task: PowerShell@1 + displayName: "Define variables" + inputs: + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[task.setvariable variable=Path]${env:AGENT_TEMPDIRECTORY}\dotnet\;${env:Path}" + - task: MSBuild@1 displayName: "Bootstrap NuGet packages" inputs: diff --git a/global.json b/global.json new file mode 100644 index 00000000000..a32d2892027 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "5.0.100-alpha1" + } +} \ No newline at end of file diff --git a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/Util.cs b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/Util.cs index cfc06a6edee..392d2990998 100644 --- a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/Util.cs +++ b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/Util.cs @@ -1236,7 +1236,7 @@ public static void CreateTempGlobalJson(string solutionRoot) var globalJsonFile = @"{ ""sdk"": { - ""version"": ""3.0.100 - preview"" + ""version"": ""5.0.100-alpha1"" } }"; diff --git a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/MsbuildIntegrationTestFixture.cs b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/MsbuildIntegrationTestFixture.cs index 3a96285dd74..1980299781b 100644 --- a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/MsbuildIntegrationTestFixture.cs +++ b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/MsbuildIntegrationTestFixture.cs @@ -33,9 +33,9 @@ public MsbuildIntegrationTestFixture() var sdkPaths = Directory.GetDirectories(Path.Combine(_cliDirectory, "sdk")); MsBuildSdksPath = Path.Combine( - sdkPaths.Where(path => path.Split(Path.DirectorySeparatorChar).Last().StartsWith("3")).First() + sdkPaths.Where(path => path.Split(Path.DirectorySeparatorChar).Last().StartsWith("5")).First() , "Sdks"); - + _processEnvVars.Add("MSBuildSDKsPath", MsBuildSdksPath); _processEnvVars.Add("UseSharedCompilation", "false"); _processEnvVars.Add("DOTNET_MULTILEVEL_LOOKUP", "0"); @@ -287,154 +287,153 @@ private void CopyRestoreArtifacts(string artifactsDirectory, string pathToSdkInC var artifactDirectories = projectArtifactsFolder.EnumerateDirectories(); - IEnumerable frameworkArtifactFolders = artifactDirectories.Where(folder => folder.FullName.Contains("netstandard2.1") || folder.FullName.Contains("netcoreapp3.0")); + IEnumerable frameworkArtifactFolders = artifactDirectories.Where(folder => folder.FullName.Contains("netstandard2.1") || folder.FullName.Contains("netcoreapp5.0")); if (!frameworkArtifactsFolders.Any()) { frameworkArtifactsFolders = frameworkArtifactsFolders.Where(folder => folder.FullName.Contains("netstandard2.0")); } - - foreach (var frameworkArtifactsFolder in frameworkArtifactsFolders) - { - var fileName = projectName + ".dll"; - File.Copy( - sourceFileName: Path.Combine(frameworkArtifactsFolder.FullName, fileName), - destFileName: Path.Combine(pathToSdkInCli, fileName), - overwrite: true); - // Copy the restore targets. - if (projectName.Equals(restoreProjectName)) + foreach (var frameworkArtifactsFolder in frameworkArtifactsFolders) { + var fileName = projectName + ".dll"; File.Copy( - sourceFileName: Path.Combine(frameworkArtifactsFolder.FullName, restoreTargetsName), - destFileName: Path.Combine(pathToSdkInCli, restoreTargetsName), - overwrite: true); + sourceFileName: Path.Combine(frameworkArtifactsFolder.FullName, fileName), + destFileName: Path.Combine(pathToSdkInCli, fileName), + overwrite: true); + // Copy the restore targets. + if (projectName.Equals(restoreProjectName)) + { + File.Copy( + sourceFileName: Path.Combine(frameworkArtifactsFolder.FullName, restoreTargetsName), + destFileName: Path.Combine(pathToSdkInCli, restoreTargetsName), + overwrite: true); + } } } } - } - private void CopyPackSdkArtifacts(string artifactsDirectory, string pathToSdkInCli, string configuration, string toolsetVersion) - { - var pathToPackSdk = Path.Combine(pathToSdkInCli, "Sdks", "NuGet.Build.Tasks.Pack"); - - const string packProjectName = "NuGet.Build.Tasks.Pack"; - const string packTargetsName = "NuGet.Build.Tasks.Pack.targets"; - // Copy the pack SDK. - var packProjectCoreArtifactsDirectory = new DirectoryInfo(Path.Combine(artifactsDirectory, packProjectName, toolsetVersion, "bin", configuration)).EnumerateDirectories("netstandard*").Single(); - var packAssemblyDestinationDirectory = Path.Combine(pathToPackSdk, "CoreCLR"); - // Be smart here so we don't have to call ILMerge in the VS build. It takes ~15s total. - // In VisualStudio, simply use the non il merged version. - var ilMergedPackDirectoryPath = Path.Combine(packProjectCoreArtifactsDirectory.FullName, "ilmerge"); - if (Directory.Exists(ilMergedPackDirectoryPath)) + private void CopyPackSdkArtifacts(string artifactsDirectory, string pathToSdkInCli, string configuration, string toolsetVersion) { - var packFileName = packProjectName + ".dll"; - // Only use the il merged assembly if it's newer than the build. - DateTime packAssemblyCreationDate = File.GetCreationTimeUtc(Path.Combine(packProjectCoreArtifactsDirectory.FullName, packFileName)); - DateTime ilMergedPackAssemblyCreationDate = File.GetCreationTimeUtc(Path.Combine(ilMergedPackDirectoryPath, packFileName)); - if (ilMergedPackAssemblyCreationDate > packAssemblyCreationDate) + var pathToPackSdk = Path.Combine(pathToSdkInCli, "Sdks", "NuGet.Build.Tasks.Pack"); + + const string packProjectName = "NuGet.Build.Tasks.Pack"; + const string packTargetsName = "NuGet.Build.Tasks.Pack.targets"; + // Copy the pack SDK. + var packProjectCoreArtifactsDirectory = new DirectoryInfo(Path.Combine(artifactsDirectory, packProjectName, toolsetVersion, "bin", configuration)).EnumerateDirectories("netstandard*").Single(); + var packAssemblyDestinationDirectory = Path.Combine(pathToPackSdk, "CoreCLR"); + // Be smart here so we don't have to call ILMerge in the VS build. It takes ~15s total. + // In VisualStudio, simply use the non il merged version. + var ilMergedPackDirectoryPath = Path.Combine(packProjectCoreArtifactsDirectory.FullName, "ilmerge"); + if (Directory.Exists(ilMergedPackDirectoryPath)) { - FileUtility.Replace( - sourceFileName: Path.Combine(packProjectCoreArtifactsDirectory.FullName, "ilmerge", packFileName), - destFileName: Path.Combine(packAssemblyDestinationDirectory, packFileName)); - } - else - { - foreach (var assembly in packProjectCoreArtifactsDirectory.EnumerateFiles("*.dll")) + var packFileName = packProjectName + ".dll"; + // Only use the il merged assembly if it's newer than the build. + DateTime packAssemblyCreationDate = File.GetCreationTimeUtc(Path.Combine(packProjectCoreArtifactsDirectory.FullName, packFileName)); + DateTime ilMergedPackAssemblyCreationDate = File.GetCreationTimeUtc(Path.Combine(ilMergedPackDirectoryPath, packFileName)); + if (ilMergedPackAssemblyCreationDate > packAssemblyCreationDate) { - File.Copy( - sourceFileName: assembly.FullName, - destFileName: Path.Combine(packAssemblyDestinationDirectory, assembly.Name), - overwrite: true); + FileUtility.Replace( + sourceFileName: Path.Combine(packProjectCoreArtifactsDirectory.FullName, "ilmerge", packFileName), + destFileName: Path.Combine(packAssemblyDestinationDirectory, packFileName)); } + else + { + foreach (var assembly in packProjectCoreArtifactsDirectory.EnumerateFiles("*.dll")) + { + File.Copy( + sourceFileName: assembly.FullName, + destFileName: Path.Combine(packAssemblyDestinationDirectory, assembly.Name), + overwrite: true); + } + } + // Copy the pack targets + var packTargetsSource = Path.Combine(packProjectCoreArtifactsDirectory.FullName, packTargetsName); + var targetsDestination = Path.Combine(pathToPackSdk, "build", packTargetsName); + var targetsDestinationCrossTargeting = Path.Combine(pathToPackSdk, "buildCrossTargeting", packTargetsName); + File.Copy(packTargetsSource, targetsDestination, overwrite: true); + File.Copy(packTargetsSource, targetsDestinationCrossTargeting, overwrite: true); } - // Copy the pack targets - var packTargetsSource = Path.Combine(packProjectCoreArtifactsDirectory.FullName, packTargetsName); - var targetsDestination = Path.Combine(pathToPackSdk, "build", packTargetsName); - var targetsDestinationCrossTargeting = Path.Combine(pathToPackSdk, "buildCrossTargeting", packTargetsName); - File.Copy(packTargetsSource, targetsDestination, overwrite: true); - File.Copy(packTargetsSource, targetsDestinationCrossTargeting, overwrite: true); } - } - public void Dispose() - { - RunDotnet(Path.GetDirectoryName(TestDotnetCli), "build-server shutdown"); - KillDotnetExe(TestDotnetCli); - _cliDirectory.Dispose(); - _templateDirectory.Dispose(); - } + public void Dispose() + { + RunDotnet(Path.GetDirectoryName(TestDotnetCli), "build-server shutdown"); + KillDotnetExe(TestDotnetCli); + _cliDirectory.Dispose(); + _templateDirectory.Dispose(); + } - private static void KillDotnetExe(string pathToDotnetExe) - { - var processes = Process.GetProcessesByName("dotnet") - .Where(t => string.Compare(t.MainModule.FileName, Path.GetFullPath(pathToDotnetExe), ignoreCase: true) == 0); - var testDirProcesses = Process.GetProcesses() - .Where(t => t.MainModule.FileName.StartsWith(TestFileSystemUtility.NuGetTestFolder, StringComparison.OrdinalIgnoreCase)); - try + private static void KillDotnetExe(string pathToDotnetExe) { - if (processes != null) + var processes = Process.GetProcessesByName("dotnet") + .Where(t => string.Compare(t.MainModule.FileName, Path.GetFullPath(pathToDotnetExe), ignoreCase: true) == 0); + var testDirProcesses = Process.GetProcesses() + .Where(t => t.MainModule.FileName.StartsWith(TestFileSystemUtility.NuGetTestFolder, StringComparison.OrdinalIgnoreCase)); + try { - foreach (var process in processes) + if (processes != null) { - if (string.Compare(process.MainModule.FileName, Path.GetFullPath(pathToDotnetExe), true) == 0) + foreach (var process in processes) { - process.Kill(); + if (string.Compare(process.MainModule.FileName, Path.GetFullPath(pathToDotnetExe), true) == 0) + { + process.Kill(); + } } } - } - if (testDirProcesses != null) - { - foreach (var process in testDirProcesses) + if (testDirProcesses != null) { - process.Kill(); + foreach (var process in testDirProcesses) + { + process.Kill(); + } } - } - } - catch { } - } - - /// - /// Depth-first recursive delete, with handling for descendant - /// directories open in Windows Explorer or used by another process - /// - private static void DeleteDirectory(string path) - { - foreach (string directory in Directory.GetDirectories(path)) - { - DeleteDirectory(directory); + } + catch { } } - try + /// + /// Depth-first recursive delete, with handling for descendant + /// directories open in Windows Explorer or used by another process + /// + private static void DeleteDirectory(string path) { - Directory.Delete(path, true); - } - catch (IOException) - { - Directory.Delete(path, true); - } - catch (UnauthorizedAccessException) - { - var MaxTries = 100; + foreach (string directory in Directory.GetDirectories(path)) + { + DeleteDirectory(directory); + } - for (var i = 0; i < MaxTries; i++) + try + { + Directory.Delete(path, true); + } + catch (IOException) { + Directory.Delete(path, true); + } + catch (UnauthorizedAccessException) + { + var MaxTries = 100; - try - { - Directory.Delete(path, recursive: true); - break; - } - catch (UnauthorizedAccessException) when (i < (MaxTries - 1)) + for (var i = 0; i < MaxTries; i++) { - Thread.Sleep(100); + + try + { + Directory.Delete(path, recursive: true); + break; + } + catch (UnauthorizedAccessException) when (i < (MaxTries - 1)) + { + Thread.Sleep(100); + } } } - } - catch - { + catch + { + } } } } -} diff --git a/test/NuGet.Core.FuncTests/NuGet.Protocol.FuncTest/HttpRetryHandlerTests.cs b/test/NuGet.Core.FuncTests/NuGet.Protocol.FuncTest/HttpRetryHandlerTests.cs index acfae3d7774..7298acadc3a 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Protocol.FuncTest/HttpRetryHandlerTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Protocol.FuncTest/HttpRetryHandlerTests.cs @@ -100,7 +100,7 @@ public async Task HttpRetryHandler_HandlesFailureToConnect() } else { -#if NETCORE3_0 +#if (NETCORE3_0 || NETCORE5_0) Assert.Equal("No connection could be made because the target machine actively refused it.", exception.InnerException.Message); #else Assert.Equal("No connection could be made because the target machine actively refused it", exception.InnerException.Message); @@ -122,7 +122,7 @@ public async Task HttpRetryHandler_HandlesInvalidProtocol() var exception = await ThrowsException(server); #if IS_CORECLR Assert.Null(exception.InnerException); -#if NETCORE3_0 +#if (NETCORE3_0 || NETCORE5_0) Assert.Equal("Received an invalid status code: 'BAD'.", exception.Message); #else Assert.Equal("The server returned an invalid or unrecognized response.", exception.Message); @@ -146,7 +146,7 @@ public async Task HttpRetryHandler_HandlesNameResolutionFailure() if (RuntimeEnvironmentHelper.IsMacOSX) { -#if NETCORE3_0 +#if (NETCORE3_0 || NETCORE5_0) Assert.Equal("nodename nor servname provided, or not known", exception.InnerException.Message); #else Assert.Equal("Device not configured", exception.InnerException.Message); @@ -154,7 +154,7 @@ public async Task HttpRetryHandler_HandlesNameResolutionFailure() } else if (!RuntimeEnvironmentHelper.IsWindows) { -#if NETCORE3_0 +#if (NETCORE3_0 || NETCORE5_0) Assert.Equal("Name or service not known", exception.InnerException.Message); #else Assert.Equal("No such device or address", exception.InnerException.Message); @@ -162,7 +162,7 @@ public async Task HttpRetryHandler_HandlesNameResolutionFailure() } else { -#if NETCORE3_0 +#if (NETCORE3_0 || NETCORE5_0) Assert.Equal("No such host is known.", exception.InnerException.Message); #else Assert.Equal("No such host is known", exception.InnerException.Message); diff --git a/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/DotnetCliUtil.cs b/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/DotnetCliUtil.cs index ab78865c3d0..654a7ccd94f 100644 --- a/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/DotnetCliUtil.cs +++ b/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/DotnetCliUtil.cs @@ -131,7 +131,7 @@ public static string GetXplatDll() var relativePaths = new string[] { - Path.Combine("artifacts", "NuGet.CommandLine.XPlat", "16.0", "bin", configuration, "netcoreapp3.0", XPlatDll) + Path.Combine("artifacts", "NuGet.CommandLine.XPlat", "16.0", "bin", configuration, "netcoreapp5.0", XPlatDll) }; foreach (var relativePath in relativePaths)