From aaf2c3937994b40813b453c8b9e66a8a67e4312b Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Mon, 23 Sep 2019 15:47:17 -0700 Subject: [PATCH] add crossVerify tests fix path in build.proj and common.project.props fix testFixture issue fix publishing on windows twice issue by using matrix in yaml add global.json for 2 crossVerify projects to use preview SDK when restored separately rename srcipt to runVerifySignedPackages.sh add dependsOn of Initialize_Build to verify phases fix target name fix artifactName and dowloadPath in yaml add other 7 cases for cross verify fix directory.create and simplify package name simplify case name add GenerateFixture for crossverify testing fix GetFiles for package and cert Remove and sort usings; Remove unused function fix install SDK preview version change sdk version change scipt to use bootstrap.proj use scripts/funcTests/dotnet-install.sh regenerate sln change CrossVerifyProjects in build.proj update verify script --- NuGet.sln | 17 +- build/build.proj | 70 + build/common.project.props | 4 + build/vsts_build.yaml | 2568 ++++++++++------- scripts/funcTests/runGenSignedPackages.sh | 124 + scripts/funcTests/runVerifySignedPackages.sh | 124 + .../CrossVerifyCollection.cs | 14 + .../GenerateFixture.cs | 56 + .../GenerateSignedPackages.cs | 368 +++ ...Packaging.CrossVerify.Generate.Test.csproj | 55 + .../global.json | 5 + .../xunit.runner.json | 4 + ...t.Packaging.CrossVerify.Verify.Test.csproj | 55 + .../VerifySignedPackages.cs | 459 +++ .../global.json | 5 + .../xunit.runner.json | 4 + .../SigningTests/SigningTestFixture.cs | 11 + 17 files changed, 2900 insertions(+), 1043 deletions(-) create mode 100644 scripts/funcTests/runGenSignedPackages.sh create mode 100644 scripts/funcTests/runVerifySignedPackages.sh create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/CrossVerifyCollection.cs create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/GenerateFixture.cs create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/GenerateSignedPackages.cs create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/NuGet.Packaging.CrossVerify.Generate.Test.csproj create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/global.json create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/xunit.runner.json create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/NuGet.Packaging.CrossVerify.Verify.Test.csproj create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/VerifySignedPackages.cs create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/global.json create mode 100644 test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/xunit.runner.json diff --git a/NuGet.sln b/NuGet.sln index 879df12a97b..0d0bb961463 100644 --- a/NuGet.sln +++ b/NuGet.sln @@ -168,7 +168,6 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.VisualStudio.Interop", "src\NuGet.Clients\NuGet.VisualStudio.Interop\NuGet.VisualStudio.Interop.csproj", "{7DB43FE1-75E1-49F9-B2C8-06A552BA2144}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGetConsole.Host.PowerShell", "src\NuGet.Clients\NuGetConsole.Host.PowerShell\NuGetConsole.Host.PowerShell.csproj", "{5A79EEF3-51C0-4A14-8D37-50EF38AD835D}" - # Make NuGetConsole.Host.PowerShell depend on NuGet.PackageManagement.PowerShellCmdlets. This is so NuGetConsole.Host.PowerShell's build can update NuGet.psd1 based on the strong name of NuGet.PackageManagement.PowerShellCmdlets.dll ProjectSection(ProjectDependencies) = postProject {26DC17AC-A390-4515-A2C0-07A0950036C5} = {26DC17AC-A390-4515-A2C0-07A0950036C5} EndProjectSection @@ -235,10 +234,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Packaging.Core", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Tools.Test", "test\NuGet.Clients.Tests\NuGet.Tools.Test\NuGet.Tools.Test.csproj", "{437C6B7E-B625-4AE5-A4CE-F2B3747FE1CE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Msbuild.Integration.Test", "test\NuGet.Core.FuncTests\Msbuild.Integration.Test\Msbuild.Integration.Test.csproj", "{92EF44DB-4F40-4610-A1AD-3A554A0CA8B9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Msbuild.Integration.Test", "test\NuGet.Core.FuncTests\Msbuild.Integration.Test\Msbuild.Integration.Test.csproj", "{92EF44DB-4F40-4610-A1AD-3A554A0CA8B9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Build.Tasks.Console", "src\NuGet.Core\NuGet.Build.Tasks.Console\NuGet.Build.Tasks.Console.csproj", "{3ED13630-90EB-420E-8083-0959B2955C6E}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Packaging.CrossVerify.Generate.Test", "test\NuGet.Core.FuncTests\NuGet.Packaging.CrossVerify.Generate.Test\NuGet.Packaging.CrossVerify.Generate.Test.csproj", "{5F7B0AAE-4522-4D1F-B358-627041BF336D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NuGet.Packaging.CrossVerify.Verify.Test", "test\NuGet.Core.FuncTests\NuGet.Packaging.CrossVerify.Verify.Test\NuGet.Packaging.CrossVerify.Verify.Test.csproj", "{DBB6AA5C-C9F7-4F59-9A51-80B26EA1ABDD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -577,6 +580,14 @@ Global {3ED13630-90EB-420E-8083-0959B2955C6E}.Debug|Any CPU.Build.0 = Debug|Any CPU {3ED13630-90EB-420E-8083-0959B2955C6E}.Release|Any CPU.ActiveCfg = Release|Any CPU {3ED13630-90EB-420E-8083-0959B2955C6E}.Release|Any CPU.Build.0 = Release|Any CPU + {5F7B0AAE-4522-4D1F-B358-627041BF336D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F7B0AAE-4522-4D1F-B358-627041BF336D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F7B0AAE-4522-4D1F-B358-627041BF336D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F7B0AAE-4522-4D1F-B358-627041BF336D}.Release|Any CPU.Build.0 = Release|Any CPU + {DBB6AA5C-C9F7-4F59-9A51-80B26EA1ABDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DBB6AA5C-C9F7-4F59-9A51-80B26EA1ABDD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DBB6AA5C-C9F7-4F59-9A51-80B26EA1ABDD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DBB6AA5C-C9F7-4F59-9A51-80B26EA1ABDD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -675,6 +686,8 @@ Global {437C6B7E-B625-4AE5-A4CE-F2B3747FE1CE} = {01BC4531-1E25-48D7-A8FD-A47D6FEC47FB} {92EF44DB-4F40-4610-A1AD-3A554A0CA8B9} = {BB63CACA-866F-454F-BA4C-78B788D032BB} {3ED13630-90EB-420E-8083-0959B2955C6E} = {506AF844-92E0-4404-BBFC-0AB073890A72} + {5F7B0AAE-4522-4D1F-B358-627041BF336D} = {BB63CACA-866F-454F-BA4C-78B788D032BB} + {DBB6AA5C-C9F7-4F59-9A51-80B26EA1ABDD} = {BB63CACA-866F-454F-BA4C-78B788D032BB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3747A66A-00D1-41B8-A9C5-ED0D7BEA9D25} diff --git a/build/build.proj b/build/build.proj index 37dac3946e8..763ecd6c7c0 100644 --- a/build/build.proj +++ b/build/build.proj @@ -75,6 +75,54 @@ + + + + + $(RepositoryRootDirectory)test\NuGet.Core.FuncTests\NuGet.Packaging.CrossVerify.Generate.Test\NuGet.Packaging.CrossVerify.Generate.Test.csproj + CrossVerifyGeneratePackageTests + + + + + + + + + + + + + $(RepositoryRootDirectory)test\NuGet.Core.FuncTests\NuGet.Packaging.CrossVerify.Verify.Test\NuGet.Packaging.CrossVerify.Verify.Test.csproj + CrossVerifyVerifyPackageTests + + + + + + + + + + + + + @(CrossVerifyProjects) + + + + + + + @@ -266,6 +268,8 @@ $(RepositoryRootDirectory)test\NuGet.Core.Tests\NuGet.Indexing.Test\*.csproj" /> + diff --git a/build/vsts_build.yaml b/build/vsts_build.yaml index 29235d45f1b..bc6eccf66b4 100644 --- a/build/vsts_build.yaml +++ b/build/vsts_build.yaml @@ -1,1046 +1,1532 @@ name: $(SourceBranchName)-$(Date:yyyyMMdd)-$(rev:rr) phases: + - phase: Initialize_Build + queue: + name: VSEng-MicroBuildVS2019 + timeoutInMinutes: 60 + demands: + - DotNetFramework + - msbuild + + steps: + - task: PowerShell@1 + displayName: "Official only branch checks" + inputs: + scriptType: "inlineScript" + inlineScript: | + $needOfficialBuild = $Env:BUILD_SOURCEBRANCHNAME -eq 'dev' -or $Env:BUILD_SOURCEBRANCHNAME.StartsWith('release-') + if ($needOfficialBuild) + { + throw [System.Exception] ($Env:BUILD_SOURCEBRANCHNAME + ' should only be built from the official build definition') + } + condition: " not(eq(variables['IsOfficialBuild'], 'true')) " + + - task: PowerShell@1 + displayName: "Initialize Git Commit Status on GitHub" + inputs: + scriptType: "inlineScript" + inlineScript: | + . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 + InitializeAllTestsToPending -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -CommitSha $(Build.SourceVersion) + + - task: PowerShell@1 + displayName: "Update Build Number" + name: "updatebuildnumber" + inputs: + scriptType: "inlineScript" + inlineScript: | + $revision = Get-Content $env:BUILDCOUNTERFILE + $newBuildCounter = [System.Decimal]::Parse($revision) + $newBuildCounter++ + Set-Content $env:BUILDCOUNTERFILE $newBuildCounter + $msbuildExe = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe' + $productVersion = & $msbuildExe $env:BUILD_REPOSITORY_LOCALPATH\build\config.props /v:m /nologo /t:GetSemanticVersion + $productVersion = $productVersion.Trim() + $FullBuildNumber = "$productVersion.$newBuildCounter" + $targetChannel = & $msbuildExe $env:BUILD_REPOSITORY_LOCALPATH\build\config.props /v:m /nologo /t:GetVsTargetChannel + $targetChannel = $targetChannel.Trim() + $targetMajorVersion = & $msbuildExe $env:BUILD_REPOSITORY_LOCALPATH\build\config.props /v:m /nologo /t:GetVsTargetMajorVersion + $targetMajorVersion = $targetMajorVersion.Trim() + Write-Host "##vso[task.setvariable variable=VsTargetChannel;isOutput=true]$targetChannel" + Write-Host "##vso[task.setvariable variable=VsTargetMajorVersion;isOutput=true]$targetMajorVersion" + Write-Host "##vso[build.updatebuildnumber]$FullBuildNumber" + Write-Host "##vso[task.setvariable variable=BuildNumber;isOutput=true]$newBuildCounter" + Write-Host "##vso[task.setvariable variable=FullVstsBuildNumber;isOutput=true]$FullBuildNumber" + + - task: PowerShell@1 + displayName: "Get SDK Version For Build" + name: "getSDKVersionForBuild" + inputs: + scriptType: "inlineScript" + inlineScript: | + $msbuildExe = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe' + $SDKVersionForBuild = & $msbuildExe $env:BUILD_REPOSITORY_LOCALPATH\build\config.props /v:m /nologo /t:GetCliVersionForBuilding + Write-Host "##vso[task.setvariable variable=SDKVersionForBuild;isOutput=true]$SDKVersionForBuild" + + - task: PowerShell@1 + displayName: "Add Build Tags" + inputs: + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[build.addbuildtag]${env:BUILD_SOURCEVERSIONAUTHOR}" + Write-Host "##vso[build.addbuildtag]${env:BUILD_SOURCEBRANCHNAME}" + + - phase: Build_and_UnitTest + dependsOn: Initialize_Build + variables: + BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']] + FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + VsTargetChannel: $[dependencies.Initialize_Build.outputs['updatebuildnumber.VsTargetChannel']] + VsTargetMajorVersion: $[dependencies.Initialize_Build.outputs['updatebuildnumber.VsTargetMajorVersion']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + queue: + name: VSEng-MicroBuildVS2019 + timeoutInMinutes: 90 + parallel: 2 + matrix: + RTM: + BuildRTM: "true" + NonRTM: + BuildRTM: "false" + demands: + - DotNetFramework + - msbuild -- phase: Initialize_Build - queue: - name: VSEng-MicroBuildVS2019 - timeoutInMinutes: 60 - demands: - - DotNetFramework - - msbuild - - steps: - - task: PowerShell@1 - displayName: "Official only branch checks" - inputs: - scriptType: "inlineScript" - inlineScript: | - $needOfficialBuild = $Env:BUILD_SOURCEBRANCHNAME -eq 'dev' -or $Env:BUILD_SOURCEBRANCHNAME.StartsWith('release-') - if ($needOfficialBuild) - { - throw [System.Exception] ($Env:BUILD_SOURCEBRANCHNAME + ' should only be built from the official build definition') - } - condition: " not(eq(variables['IsOfficialBuild'], 'true')) " - - - task: PowerShell@1 - displayName: "Initialize Git Commit Status on GitHub" - inputs: - scriptType: "inlineScript" - inlineScript: | - . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 - InitializeAllTestsToPending -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -CommitSha $(Build.SourceVersion) - - - task: PowerShell@1 - displayName: "Update Build Number" - name: "updatebuildnumber" - inputs: - scriptType: "inlineScript" - inlineScript: | - $revision = Get-Content $env:BUILDCOUNTERFILE - $newBuildCounter = [System.Decimal]::Parse($revision) - $newBuildCounter++ - Set-Content $env:BUILDCOUNTERFILE $newBuildCounter - $msbuildExe = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe' - $productVersion = & $msbuildExe $env:BUILD_REPOSITORY_LOCALPATH\build\config.props /v:m /nologo /t:GetSemanticVersion - $productVersion = $productVersion.Trim() - $FullBuildNumber = "$productVersion.$newBuildCounter" - $targetChannel = & $msbuildExe $env:BUILD_REPOSITORY_LOCALPATH\build\config.props /v:m /nologo /t:GetVsTargetChannel - $targetChannel = $targetChannel.Trim() - $targetMajorVersion = & $msbuildExe $env:BUILD_REPOSITORY_LOCALPATH\build\config.props /v:m /nologo /t:GetVsTargetMajorVersion - $targetMajorVersion = $targetMajorVersion.Trim() - Write-Host "##vso[task.setvariable variable=VsTargetChannel;isOutput=true]$targetChannel" - Write-Host "##vso[task.setvariable variable=VsTargetMajorVersion;isOutput=true]$targetMajorVersion" - Write-Host "##vso[build.updatebuildnumber]$FullBuildNumber" - Write-Host "##vso[task.setvariable variable=BuildNumber;isOutput=true]$newBuildCounter" - Write-Host "##vso[task.setvariable variable=FullVstsBuildNumber;isOutput=true]$FullBuildNumber" - - - task: PowerShell@1 - displayName: "Get SDK Version For Build" - name: "getSDKVersionForBuild" - inputs: - scriptType: "inlineScript" - inlineScript: | - $msbuildExe = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe' - $SDKVersionForBuild = & $msbuildExe $env:BUILD_REPOSITORY_LOCALPATH\build\config.props /v:m /nologo /t:GetCliVersionForBuilding - Write-Host "##vso[task.setvariable variable=SDKVersionForBuild;isOutput=true]$SDKVersionForBuild" - - - task: PowerShell@1 - displayName: "Add Build Tags" - inputs: - scriptType: "inlineScript" - inlineScript: | - Write-Host "##vso[build.addbuildtag]${env:BUILD_SOURCEVERSIONAUTHOR}" - Write-Host "##vso[build.addbuildtag]${env:BUILD_SOURCEBRANCHNAME}" - -- phase: Build_and_UnitTest - dependsOn: Initialize_Build - variables: - BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']] - FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] - VsTargetChannel: $[dependencies.Initialize_Build.outputs['updatebuildnumber.VsTargetChannel']] - VsTargetMajorVersion: $[dependencies.Initialize_Build.outputs['updatebuildnumber.VsTargetMajorVersion']] - SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] - queue: - name: VSEng-MicroBuildVS2019 - timeoutInMinutes: 90 - parallel: 2 - matrix: - RTM: - BuildRTM: "true" - NonRTM: - BuildRTM: "false" - demands: - - DotNetFramework - - msbuild - - steps: - - 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: "Update Build Number" - inputs: - scriptType: "inlineScript" - inlineScript: | - Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" - Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize - - - task: PowerShell@1 - displayName: "Define variables" - inputs: - 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" - inputs: - versionSpec: "5.0.0" - - - task: PowerShell@1 - inputs: - scriptName: "$(Build.Repository.LocalPath)\\configure.ps1" - arguments: "-Force" - displayName: "Run Configure.ps1" - - - task: PowerShell@1 - inputs: - scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\ConfigureVstsBuild.ps1" - arguments: "-BuildCounterFile $(BuildCounterFile) -BuildInfoJsonFile $(BuildInfoJsonFile) -BuildRTM $(BuildRTM) -SkipUpdateBuildNumber" - displayName: "Configure VSTS CI Environment" - - - task: PublishBuildArtifacts@1 - displayName: 'Publish buildinfo.json as an artifact' - inputs: - ArtifactName: 'BuildInfo' - ArtifactType: 'Container' - PathToPublish: '$(Build.Repository.LocalPath)\artifacts\buildinfo.json' - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'))" - - - task: PowerShell@1 - displayName: "Print Environment Variables" - inputs: - scriptType: "inlineScript" - inlineScript: | - Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize - - - task: NuGetCommand@2 - displayName: 'MicroBuild: install core package' - inputs: - command: 'custom' - arguments: 'install Microsoft.VisualStudioEng.MicroBuild.Core -Version 0.4.1 -ConfigFile $(System.DefaultWorkingDirectory)\NuGet.config -OutputDirectory $(System.DefaultWorkingDirectory)\packages' - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: MicroBuildLocalizationPlugin@1 - displayName: "Install Localization Plugin" - - - task: MicroBuildSigningPlugin@1 - inputs: - signType: "$(SigningType)" - esrpSigning: "true" - displayName: "Install Signing Plugin" - - - task: MicroBuildSwixPlugin@1 - displayName: "Install Swix Plugin" - - - task: ms-vseng.MicroBuildTasks.965C8DC6-1483-45C9-B384-5AC75DA1F1A4.MicroBuildOptProfPlugin@4 - displayName: 'OptProfV2: install the plugin' - inputs: - getDropNameByDrop: true - optimizationInputsDropNamePrefix: OptimizationInputs/$(System.TeamProject)/$(Build.Repository.Name) - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: MSBuild@1 - displayName: "Restore for VS2019" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:RestoreVS /p:BuildNumber=$(BuildNumber) /p:BuildRTM=$(BuildRTM) /v:m" - - - task: MSBuild@1 - displayName: "Build for VS2019" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:BuildNoVSIX /p:BuildRTM=$(BuildRTM) /p:BuildNumber=$(BuildNumber)" - - - task: MSBuild@1 - displayName: "Ensure msbuild.exe can parse nuget.sln" - continueOnError: "false" - inputs: - solution: "nuget.sln" - msbuildVersion: "16.0" - msbuildArguments: "/t:EnsureNewtonsoftJsonVersion" - condition: "succeeded()" - - - task: MSBuild@1 - displayName: "Run unit tests" - continueOnError: "true" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:CoreUnitTests;UnitTestsVS /p:BuildRTM=$(BuildRTM) /p:BuildNumber=$(BuildNumber) /p:TestResultOutputFormat=xml" - condition: "and(succeeded(),eq(variables['BuildRTM'], 'true'))" - - - task: PublishTestResults@2 - displayName: "Publish Test Results" - inputs: - testRunner: "XUnit" - testResultsFiles: "*.xml" - testRunTitle: "NuGet.Client Unit Tests On Windows" - searchFolder: "$(Build.Repository.LocalPath)\\build\\TestResults" - mergeTestResults: "true" - publishRunAttachments: "false" - condition: "and(succeededOrFailed(),eq(variables['BuildRTM'], 'true'))" - - - task: PowerShell@1 - displayName: "Initialize Git Commit Status on GitHub" - inputs: - scriptType: "inlineScript" - arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" - inlineScript: | - . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 - SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "Unit Tests On Windows" - condition: "and(always(),eq(variables['BuildRTM'], 'true'))" - - - task: PublishBuildArtifacts@1 - displayName: "Publish NuGet.CommandLine.Test as artifact" - inputs: - PathtoPublish: "$(Build.Repository.LocalPath)\\test\\NuGet.Clients.Tests\\NuGet.CommandLine.Test\\bin\\$(BuildConfiguration)\\net472\\win7-x64" - ArtifactName: "NuGet.CommandLine.Test" - ArtifactType: "Container" - condition: "and(succeeded(),eq(variables['BuildRTM'], 'true'))" - - - task: MSBuild@1 - displayName: "Localize Assemblies" - inputs: - solution: "build\\loc.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:AfterBuild" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " - - - task: MSBuild@1 - displayName: "Sign Assemblies" - inputs: - solution: "build\\sign.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:AfterBuild" - - - task: MSBuild@1 - displayName: "Pack Nupkgs" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:Pack /p:BuildRTM=$(BuildRTM) /p:ExcludeTestProjects=$(BuildRTM) /p:BuildNumber=$(BuildNumber)" - - - task: MSBuild@1 - displayName: "Pack VSIX" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:BuildVSIX /p:BuildRTM=$(BuildRTM) /p:ExcludeTestProjects=$(BuildRTM) /p:IsCIBuild=true" - condition: "and(succeeded(),eq(variables['BuildRTM'], 'false'))" - - - task: MSBuild@1 - displayName: "Generate Build Tools package" - inputs: - solution: "setup/Microsoft.VisualStudio.NuGet.BuildTools.vsmanproj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/p:BuildNumber=$(BuildNumber) /p:IsVsixBuild=true" - condition: " and(succeeded(), eq(variables['BuildRTM'], 'false'))" - - - task: MSBuild@1 - displayName: "Sign Nupkgs and VSIX" - inputs: - solution: "build\\sign.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:AfterBuild /p:SignPackages=true" - - - task: NuGetCommand@2 - displayName: "Verify Nupkg Signatures" - inputs: - command: "custom" - arguments: "verify -Signatures $(Build.Repository.LocalPath)\\artifacts\\$(NupkgOutputDir)\\*.nupkg" - - - task: ms-vseng.MicroBuildShipTasks.7c429315-71ba-4cb3-94bb-f829c95f7915.MicroBuildCodesignVerify@1 - displayName: Verify Assembly Signatures and StrongName for the nupkgs - inputs: - TargetFolder: '$(Build.Repository.LocalPath)\\artifacts\\$(NupkgOutputDir)' - - - task: ms-vseng.MicroBuildShipTasks.7c429315-71ba-4cb3-94bb-f829c95f7915.MicroBuildCodesignVerify@1 - displayName: Verify Assembly Signatures and StrongName for the VSIX & exes - inputs: - TargetFolder: '$(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir)' - WhiteListPathForCerts: '$(Build.Repository.LocalPath)\\build\\ignorecodesign.csv' - WhiteListPathForSigs: '$(Build.Repository.LocalPath)\\build\\ignorecodesign.csv' - - - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0 - displayName: 'Component Detection' - condition: "and(succeeded(),eq(variables['BuildRTM'], 'true'))" - - - task: CopyFiles@2 - displayName: "Copy Nupkgs" - inputs: - SourceFolder: "artifacts\\$(NupkgOutputDir)" - Contents: "*.nupkg" - TargetFolder: "$(BuildOutputTargetPath)\\artifacts\\$(VsixPublishDir)\\$(NupkgOutputDir)" - - - task: MSBuild@1 - displayName: "Generate VSMAN file for NuGet Core VSIX" - inputs: - solution: "setup\\Microsoft.VisualStudio.NuGet.Core.vsmanproj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " - - - task: MSBuild@1 - displayName: "Generate VSMAN file for Build Tools VSIX" - inputs: - solution: "setup\\Microsoft.VisualStudio.NuGet.BuildTools.vsmanproj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " - - - task: PowerShell@1 - displayName: "Create EndToEnd Test Package" - inputs: - scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\CreateEndToEndTestPackage.ps1" - arguments: "-c $(BuildConfiguration) -tv 16 -out $(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir)" - failOnStandardError: "true" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " - - - task: CopyFiles@2 - displayName: "Copy NuGet.exe, VSIX and EndToEnd" - inputs: - SourceFolder: "artifacts" - Contents: | - $(VsixPublishDir)\\NuGet.exe - $(VsixPublishDir)\\NuGet.pdb - $(VsixPublishDir)\\NuGet.Mssign.exe - $(VsixPublishDir)\\NuGet.Mssign.pdb - $(VsixPublishDir)\\Microsoft.VisualStudio.NuGet.Core.json - $(VsixPublishDir)\\NuGet.Tools.vsix - $(VsixPublishDir)\\Microsoft.VisualStudio.NuGet.BuildTools.vsix - $(VsixPublishDir)\\Microsoft.VisualStudio.NuGet.BuildTools.json - $(VsixPublishDir)\\EndToEnd.zip - TargetFolder: "$(BuildOutputTargetPath)\\artifacts" - - - task: NuGetCommand@2 - displayName: 'OptProfV2: add the NuGet package source' - inputs: - command: 'custom' - arguments: 'sources add -Name VS -Source $(VsPackageFeedUrl) -UserName $(VsPackageFeedUsername) -Password $(VsPackageFeedPassword) -ConfigFile $(System.DefaultWorkingDirectory)\NuGet.config' - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: NuGetCommand@2 - displayName: 'OptProfV2: install the NuGet package for building .runsettingsproj file' - inputs: - command: 'custom' - arguments: 'install Microsoft.DevDiv.Validation.TestPlatform.Settings.Tasks -Version 1.0.308 -Source $(VsPackageFeedUrl) -ConfigFile $(System.DefaultWorkingDirectory)\NuGet.config -OutputDirectory $(System.DefaultWorkingDirectory)\packages' - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: ms-vseng.MicroBuildTasks.0e9d0d4d-71ec-4e4e-ae40-db9896f1ae74.MicroBuildBuildVSBootstrapper@2 - displayName: 'OptProfV2: build a Visual Studio bootstrapper' - inputs: - channelName: "$(VsTargetChannel)" - vsMajorVersion: "$(VsTargetMajorVersion)" - manifests: '$(Build.Repository.LocalPath)\artifacts\$(VsixPublishDir)\Microsoft.VisualStudio.NuGet.Core.vsman' - outputFolder: '$(Build.Repository.LocalPath)\artifacts\$(VsixPublishDir)' - continueOnError: true - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: PublishBuildArtifacts@1 - displayName: 'OptProfV2: publish BootstrapperInfo.json as a build artifact' - inputs: - PathtoPublish: $(Build.StagingDirectory)\MicroBuild\Output - ArtifactName: MicroBuildOutputs - ArtifactType: Container - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: PowerShell@1 - displayName: 'OptProfV2: set the TestDrop environment variable' - inputs: - scriptType: 'inlineScript' - inlineScript: | - [string] $bootstrapperInfoFilePath = "$Env:BUILD_STAGINGDIRECTORY\MicroBuild\Output\BootstrapperInfo.json" - $json = Get-Content $bootstrapperInfoFilePath | ConvertFrom-Json - [string] $buildDropPath = $json.BuildDrop - Write-Host "Build drop: $buildDropPath" - [string] $testDropPath = $buildDropPath.Replace('/Products/', '/Tests/').Substring('https://vsdrop.corp.microsoft.com/file/v1/'.Length) - Write-Host "Test drop: $testDropPath" - Write-Host "##vso[task.setvariable variable=TestDrop]$testDropPath" - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: MSBuild@1 - displayName: 'OptProfV2: generate a .runsettings file' - inputs: - solution: 'build\NuGet.OptProfV2.runsettingsproj' - msbuildVersion: '16.0' - msbuildArguments: '/p:OutputPath="$(Build.Repository.LocalPath)\artifacts\RunSettings" /p:TestDrop="$(TestDrop)" /p:ProfilingInputsDrop="ProfilingInputs/$(System.TeamProject)/$(Build.Repository.Name)/$(Build.SourceBranchName)/$(Build.BuildId)"' - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: ms-vscs-artifact.build-tasks.artifactDropTask-1.artifactDropTask@0 - displayName: 'OptProfV2: publish the .runsettings file to artifact services' - inputs: - dropServiceURI: 'https://devdiv.artifacts.visualstudio.com' - buildNumber: 'RunSettings/$(System.TeamProject)/$(Build.Repository.Name)/$(Build.SourceBranchName)/$(Build.BuildId)' - sourcePath: 'artifacts\RunSettings' - toLowerCase: false - usePat: false - dropMetadataContainerName: RunSettings - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: ms-vscs-artifact.build-tasks.artifactDropTask-1.artifactDropTask@0 - displayName: 'OptProfV2: publish profiling inputs to artifact services' - inputs: - dropServiceURI: 'https://devdiv.artifacts.visualstudio.com' - buildNumber: 'ProfilingInputs/$(System.TeamProject)/$(Build.Repository.Name)/$(Build.SourceBranchName)/$(Build.BuildId)' - sourcePath: '$(Build.ArtifactStagingDirectory)\OptProf\ProfilingInputs' - toLowerCase: false - usePat: false - condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" - - - task: PublishBuildArtifacts@1 - displayName: "Publish NuGet.exe VSIX and EndToEnd.zip as artifact" - inputs: - PathtoPublish: "$(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir)" - ArtifactName: "$(VsixPublishDir)" - ArtifactType: "Container" - condition: "and(succeeded(),eq(variables['BuildRTM'], 'false'))" - - - task: CopyFiles@2 - displayName: "Copy LCG Files" - inputs: - SourceFolder: "artifacts\\" - Contents: "**\\*.lcg" - TargetFolder: "$(CIRoot)\\PLOC\\$(Build.SourceBranchName)\\$(Build.BuildNumber)" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true')) " - - - task: PowerShell@1 - displayName: "Publish Artifacts to MyGet" - continueOnError: "true" - inputs: - scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\PublishArtifactsFromVsts.ps1" - arguments: "-NuGetBuildFeedUrl $(NuGetBuildFeed) -NuGetBuildSymbolsFeedUrl $(NuGetBuildSymbolsFeed) -DotnetCoreFeedUrl $(DotnetCoreBuildFeed) -DotnetCoreSymbolsFeedUrl $(DotnetCoreSymbolsFeed) -NuGetBuildFeedApiKey $(NuGetBuildApiKey) -DotnetCoreFeedApiKey $(DotnetCoreFeedApiKey)" - failOnStandardError: "true" - condition: " and(succeeded(),eq(variables['PublishArtifactsToMyGet'], 'true'), eq(variables['BuildRTM'], 'false')) " - - - task: MSBuild@1 - displayName: "Collect Build Symbols" - inputs: - solution: "build\\symbols.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/p:IsSymbolBuild=true" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true')) " - - - task: CopyFiles@2 - displayName: "Copy Symbols" - inputs: - SourceFolder: "$(Build.Repository.LocalPath)\\artifacts\\symbolstoindex" - Contents: "**\\*" - TargetFolder: "$(BuildOutputTargetPath)\\symbols" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true')) " - - - task: ms-vscs-artifact.build-tasks.artifactSymbolTask-1.artifactSymbolTask@0 - displayName: "Publish Symbols on Symweb" - inputs: - symbolServiceURI: "https://microsoft.artifacts.visualstudio.com/DefaultCollection" - requestName: "CollectionId/$(System.CollectionId)/ProjectId/$(System.TeamProjectId)/$(TeamName)/BuildId/$(Build.BuildId)" - sourcePath: "$(Build.Repository.LocalPath)\\artifacts\\symbolstoindex" - detailedLog: "true" - expirationInDays: "45" - usePat: "false" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true')) " - - - task: MicroBuildUploadVstsDropFolder@1 - displayName: "Upload VSTS Drop" - inputs: - DropFolder: "$(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir)" - condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " - - - task: PowerShell@1 - displayName: "Validate VSIX Localization" - inputs: - scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\BuildValidator.ps1" - arguments: "-BuildRTM $(BuildRTM) -BuildOutputTargetPath $(BuildOutputTargetPath) -ValidateVsix" - condition: "succeeded()" - - - task: PowerShell@1 - displayName: "Validate Repository Artifacts Localization" - inputs: - scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\BuildValidator.ps1" - arguments: "-BuildRTM $(BuildRTM) -BuildOutputTargetPath $(BuildOutputTargetPath)" - condition: "succeeded()" - - # Use dotnet msbuild instead of MSBuild CLI. - # Using MSBuild CLI results in an assembly binding failure for NuGet.Common.dll 4.4.0.3 because Microsoft.DotNet.Build.Tasks.Feed.dll references SleetLib.dll which references NuGet.Common 4.4.0.3. - # The Microsoft.DotNet.Build.Tasks.Feed package includes NuGet.Common 4.9.0.6 and a binding redirection in Microsoft.DotNet.Build.Tasks.Feed.dll.config but the binding redirection is not processed. - # This would probably solve it: https://github.com/Microsoft/msbuild/issues/1309 - - task: CmdLine@2 - displayName: "Publish the packages to the .NET Core build asset registry (BAR)" - inputs: - script: dotnet msbuild ..\build\publish.proj /t:PublishPackagesToBuildAssetRegistry /p:NuGetClientNupkgsDirectoryPath=$(Build.Repository.LocalPath)\artifacts\$(NupkgOutputDir) /p:FeedUrl=$(DotNetFeedUrl) /p:BuildId=$(Build.BuildNumber) /p:RepoBranch=$(Build.SourceBranchName) /p:RepoCommit=$(Build.SourceVersion) /p:RepoUri=$(Build.Repository.Uri) /p:ManifestFilePath=$(ManifestFilePath) /p:AccountKey=$(dotnetfeed-storage-access-key-1) - workingDirectory: cli - failOnStderr: true - env: - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true - DOTNET_MULTILEVEL_LOOKUP: true - condition: " and(succeeded(),eq(variables['PublishArtifactsToDotNetBuildAssetRegistry'], 'true'), eq(variables['BuildRTM'], 'false')) " - - - task: PowerShell@1 - displayName: "Upload the build manifest file as a build artifact" - inputs: - scriptType: "inlineScript" - inlineScript: | - Write-Host "##vso[task.uploadfile]$(ManifestFilePath)" - condition: " and(succeeded(),eq(variables['PublishArtifactsToDotNetBuildAssetRegistry'], 'true'), eq(variables['BuildRTM'], 'false')) " - - - task: MSBuild@1 - displayName: "Publish the build manifest file to the .NET Core build asset registry (BAR)" - inputs: - solution: 'build\\publish.proj' - msbuildVersion: 16.0 - configuration: '$(BuildConfiguration)' - msbuildArguments: '/t:PublishManifestToBuildAssetRegistry /p:MaestroApiEndpoint=$(MaestroApiEndpoint) /p:ManifestsDirectoryPath=$(Build.Repository.LocalPath)\artifacts\manifests /p:MaestroAccessToken=$(MaestroAccessToken)' - condition: " and(succeeded(),eq(variables['PublishArtifactsToDotNetBuildAssetRegistry'], 'true'), eq(variables['BuildRTM'], 'false')) " - - - task: MicroBuildCleanup@1 - displayName: "Perform Cleanup Tasks" - - - task: PowerShell@1 - displayName: "Cleanup on Failure" - inputs: - scriptType: "inlineScript" - arguments: "-BuildOutputTargetPath $(BuildOutputTargetPath)" - inlineScript: | - param([string]$BuildOutputTargetPath) - Get-ChildItem $(BuildOutputTargetPath) -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue - Remove-Item -Path $(BuildOutputTargetPath) -Force -Recurse -ErrorAction SilentlyContinue - condition: "eq(variables['Agent.JobStatus'], 'Failed')" - -- phase: Functional_Tests_On_Windows - dependsOn: Initialize_Build - variables: - BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']] - FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] - SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] - condition: "and(succeeded(),eq(variables['RunFunctionalTestsOnWindows'], 'true')) " - queue: - name: VSEng-MicroBuildSxS - timeoutInMinutes: 150 - demands: + steps: + - 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: "Update Build Number" + inputs: + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" + Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize + + - task: PowerShell@1 + displayName: "Define variables" + inputs: + 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" + inputs: + versionSpec: "5.0.0" + + - task: PowerShell@1 + inputs: + scriptName: "$(Build.Repository.LocalPath)\\configure.ps1" + arguments: "-Force" + displayName: "Run Configure.ps1" + + - task: PowerShell@1 + inputs: + scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\ConfigureVstsBuild.ps1" + arguments: "-BuildCounterFile $(BuildCounterFile) -BuildInfoJsonFile $(BuildInfoJsonFile) -BuildRTM $(BuildRTM) -SkipUpdateBuildNumber" + displayName: "Configure VSTS CI Environment" + + - task: PublishBuildArtifacts@1 + displayName: "Publish buildinfo.json as an artifact" + inputs: + ArtifactName: "BuildInfo" + ArtifactType: "Container" + PathToPublish: '$(Build.Repository.LocalPath)\artifacts\buildinfo.json' + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'))" + + - task: PowerShell@1 + displayName: "Print Environment Variables" + inputs: + scriptType: "inlineScript" + inlineScript: | + Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize + + - task: NuGetCommand@2 + displayName: "MicroBuild: install core package" + inputs: + command: "custom" + arguments: 'install Microsoft.VisualStudioEng.MicroBuild.Core -Version 0.4.1 -ConfigFile $(System.DefaultWorkingDirectory)\NuGet.config -OutputDirectory $(System.DefaultWorkingDirectory)\packages' + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: MicroBuildLocalizationPlugin@1 + displayName: "Install Localization Plugin" + + - task: MicroBuildSigningPlugin@1 + inputs: + signType: "$(SigningType)" + esrpSigning: "true" + displayName: "Install Signing Plugin" + + - task: MicroBuildSwixPlugin@1 + displayName: "Install Swix Plugin" + + - task: ms-vseng.MicroBuildTasks.965C8DC6-1483-45C9-B384-5AC75DA1F1A4.MicroBuildOptProfPlugin@4 + displayName: "OptProfV2: install the plugin" + inputs: + getDropNameByDrop: true + optimizationInputsDropNamePrefix: OptimizationInputs/$(System.TeamProject)/$(Build.Repository.Name) + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: MSBuild@1 + displayName: "Restore for VS2019" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:RestoreVS /p:BuildNumber=$(BuildNumber) /p:BuildRTM=$(BuildRTM) /v:m" + + - task: MSBuild@1 + displayName: "Build for VS2019" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:BuildNoVSIX /p:BuildRTM=$(BuildRTM) /p:BuildNumber=$(BuildNumber)" + + - task: MSBuild@1 + displayName: "Ensure msbuild.exe can parse nuget.sln" + continueOnError: "false" + inputs: + solution: "nuget.sln" + msbuildVersion: "16.0" + msbuildArguments: "/t:EnsureNewtonsoftJsonVersion" + condition: "succeeded()" + + - task: MSBuild@1 + displayName: "Run unit tests" + continueOnError: "true" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:CoreUnitTests;UnitTestsVS /p:BuildRTM=$(BuildRTM) /p:BuildNumber=$(BuildNumber) /p:TestResultOutputFormat=xml" + condition: "and(succeeded(),eq(variables['BuildRTM'], 'true'))" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + testRunTitle: "NuGet.Client Unit Tests On Windows" + searchFolder: "$(Build.Repository.LocalPath)\\build\\TestResults" + mergeTestResults: "true" + publishRunAttachments: "false" + condition: "and(succeededOrFailed(),eq(variables['BuildRTM'], 'true'))" + + - task: PowerShell@1 + displayName: "Initialize Git Commit Status on GitHub" + inputs: + scriptType: "inlineScript" + arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" + inlineScript: | + . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 + SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "Unit Tests On Windows" + condition: "and(always(),eq(variables['BuildRTM'], 'true'))" + + - task: PublishBuildArtifacts@1 + displayName: "Publish NuGet.CommandLine.Test as artifact" + inputs: + PathtoPublish: "$(Build.Repository.LocalPath)\\test\\NuGet.Clients.Tests\\NuGet.CommandLine.Test\\bin\\$(BuildConfiguration)\\net472\\win7-x64" + ArtifactName: "NuGet.CommandLine.Test" + ArtifactType: "Container" + condition: "and(succeeded(),eq(variables['BuildRTM'], 'true'))" + + - task: MSBuild@1 + displayName: "Localize Assemblies" + inputs: + solution: "build\\loc.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:AfterBuild" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " + + - task: MSBuild@1 + displayName: "Sign Assemblies" + inputs: + solution: "build\\sign.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:AfterBuild" + + - task: MSBuild@1 + displayName: "Pack Nupkgs" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:Pack /p:BuildRTM=$(BuildRTM) /p:ExcludeTestProjects=$(BuildRTM) /p:BuildNumber=$(BuildNumber)" + + - task: MSBuild@1 + displayName: "Pack VSIX" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:BuildVSIX /p:BuildRTM=$(BuildRTM) /p:ExcludeTestProjects=$(BuildRTM) /p:IsCIBuild=true" + condition: "and(succeeded(),eq(variables['BuildRTM'], 'false'))" + + - task: MSBuild@1 + displayName: "Generate Build Tools package" + inputs: + solution: "setup/Microsoft.VisualStudio.NuGet.BuildTools.vsmanproj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/p:BuildNumber=$(BuildNumber) /p:IsVsixBuild=true" + condition: " and(succeeded(), eq(variables['BuildRTM'], 'false'))" + + - task: MSBuild@1 + displayName: "Sign Nupkgs and VSIX" + inputs: + solution: "build\\sign.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:AfterBuild /p:SignPackages=true" + + - task: NuGetCommand@2 + displayName: "Verify Nupkg Signatures" + inputs: + command: "custom" + arguments: "verify -Signatures $(Build.Repository.LocalPath)\\artifacts\\$(NupkgOutputDir)\\*.nupkg" + + - task: ms-vseng.MicroBuildShipTasks.7c429315-71ba-4cb3-94bb-f829c95f7915.MicroBuildCodesignVerify@1 + displayName: Verify Assembly Signatures and StrongName for the nupkgs + inputs: + TargetFolder: '$(Build.Repository.LocalPath)\\artifacts\\$(NupkgOutputDir)' + + - task: ms-vseng.MicroBuildShipTasks.7c429315-71ba-4cb3-94bb-f829c95f7915.MicroBuildCodesignVerify@1 + displayName: Verify Assembly Signatures and StrongName for the VSIX & exes + inputs: + TargetFolder: '$(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir)' + WhiteListPathForCerts: '$(Build.Repository.LocalPath)\\build\\ignorecodesign.csv' + WhiteListPathForSigs: '$(Build.Repository.LocalPath)\\build\\ignorecodesign.csv' + + - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0 + displayName: "Component Detection" + condition: "and(succeeded(),eq(variables['BuildRTM'], 'true'))" + + - task: CopyFiles@2 + displayName: "Copy Nupkgs" + inputs: + SourceFolder: "artifacts\\$(NupkgOutputDir)" + Contents: "*.nupkg" + TargetFolder: "$(BuildOutputTargetPath)\\artifacts\\$(VsixPublishDir)\\$(NupkgOutputDir)" + + - task: MSBuild@1 + displayName: "Generate VSMAN file for NuGet Core VSIX" + inputs: + solution: "setup\\Microsoft.VisualStudio.NuGet.Core.vsmanproj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " + + - task: MSBuild@1 + displayName: "Generate VSMAN file for Build Tools VSIX" + inputs: + solution: "setup\\Microsoft.VisualStudio.NuGet.BuildTools.vsmanproj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " + + - task: PowerShell@1 + displayName: "Create EndToEnd Test Package" + inputs: + scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\CreateEndToEndTestPackage.ps1" + arguments: "-c $(BuildConfiguration) -tv 16 -out $(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir)" + failOnStandardError: "true" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " + + - task: CopyFiles@2 + displayName: "Copy NuGet.exe, VSIX and EndToEnd" + inputs: + SourceFolder: "artifacts" + Contents: | + $(VsixPublishDir)\\NuGet.exe + $(VsixPublishDir)\\NuGet.pdb + $(VsixPublishDir)\\NuGet.Mssign.exe + $(VsixPublishDir)\\NuGet.Mssign.pdb + $(VsixPublishDir)\\Microsoft.VisualStudio.NuGet.Core.json + $(VsixPublishDir)\\NuGet.Tools.vsix + $(VsixPublishDir)\\Microsoft.VisualStudio.NuGet.BuildTools.vsix + $(VsixPublishDir)\\Microsoft.VisualStudio.NuGet.BuildTools.json + $(VsixPublishDir)\\EndToEnd.zip + TargetFolder: "$(BuildOutputTargetPath)\\artifacts" + + - task: NuGetCommand@2 + displayName: "OptProfV2: add the NuGet package source" + inputs: + command: "custom" + arguments: 'sources add -Name VS -Source $(VsPackageFeedUrl) -UserName $(VsPackageFeedUsername) -Password $(VsPackageFeedPassword) -ConfigFile $(System.DefaultWorkingDirectory)\NuGet.config' + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: NuGetCommand@2 + displayName: "OptProfV2: install the NuGet package for building .runsettingsproj file" + inputs: + command: "custom" + arguments: 'install Microsoft.DevDiv.Validation.TestPlatform.Settings.Tasks -Version 1.0.308 -Source $(VsPackageFeedUrl) -ConfigFile $(System.DefaultWorkingDirectory)\NuGet.config -OutputDirectory $(System.DefaultWorkingDirectory)\packages' + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: ms-vseng.MicroBuildTasks.0e9d0d4d-71ec-4e4e-ae40-db9896f1ae74.MicroBuildBuildVSBootstrapper@2 + displayName: "OptProfV2: build a Visual Studio bootstrapper" + inputs: + channelName: "$(VsTargetChannel)" + vsMajorVersion: "$(VsTargetMajorVersion)" + manifests: '$(Build.Repository.LocalPath)\artifacts\$(VsixPublishDir)\Microsoft.VisualStudio.NuGet.Core.vsman' + outputFolder: '$(Build.Repository.LocalPath)\artifacts\$(VsixPublishDir)' + continueOnError: true + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: PublishBuildArtifacts@1 + displayName: "OptProfV2: publish BootstrapperInfo.json as a build artifact" + inputs: + PathtoPublish: $(Build.StagingDirectory)\MicroBuild\Output + ArtifactName: MicroBuildOutputs + ArtifactType: Container + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: PowerShell@1 + displayName: "OptProfV2: set the TestDrop environment variable" + inputs: + scriptType: "inlineScript" + inlineScript: | + [string] $bootstrapperInfoFilePath = "$Env:BUILD_STAGINGDIRECTORY\MicroBuild\Output\BootstrapperInfo.json" + $json = Get-Content $bootstrapperInfoFilePath | ConvertFrom-Json + [string] $buildDropPath = $json.BuildDrop + Write-Host "Build drop: $buildDropPath" + [string] $testDropPath = $buildDropPath.Replace('/Products/', '/Tests/').Substring('https://vsdrop.corp.microsoft.com/file/v1/'.Length) + Write-Host "Test drop: $testDropPath" + Write-Host "##vso[task.setvariable variable=TestDrop]$testDropPath" + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: MSBuild@1 + displayName: "OptProfV2: generate a .runsettings file" + inputs: + solution: 'build\NuGet.OptProfV2.runsettingsproj' + msbuildVersion: "16.0" + msbuildArguments: '/p:OutputPath="$(Build.Repository.LocalPath)\artifacts\RunSettings" /p:TestDrop="$(TestDrop)" /p:ProfilingInputsDrop="ProfilingInputs/$(System.TeamProject)/$(Build.Repository.Name)/$(Build.SourceBranchName)/$(Build.BuildId)"' + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: ms-vscs-artifact.build-tasks.artifactDropTask-1.artifactDropTask@0 + displayName: "OptProfV2: publish the .runsettings file to artifact services" + inputs: + dropServiceURI: "https://devdiv.artifacts.visualstudio.com" + buildNumber: "RunSettings/$(System.TeamProject)/$(Build.Repository.Name)/$(Build.SourceBranchName)/$(Build.BuildId)" + sourcePath: 'artifacts\RunSettings' + toLowerCase: false + usePat: false + dropMetadataContainerName: RunSettings + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: ms-vscs-artifact.build-tasks.artifactDropTask-1.artifactDropTask@0 + displayName: "OptProfV2: publish profiling inputs to artifact services" + inputs: + dropServiceURI: "https://devdiv.artifacts.visualstudio.com" + buildNumber: "ProfilingInputs/$(System.TeamProject)/$(Build.Repository.Name)/$(Build.SourceBranchName)/$(Build.BuildId)" + sourcePath: '$(Build.ArtifactStagingDirectory)\OptProf\ProfilingInputs' + toLowerCase: false + usePat: false + condition: "and(succeeded(), eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true'))" + + - task: PublishBuildArtifacts@1 + displayName: "Publish NuGet.exe VSIX and EndToEnd.zip as artifact" + inputs: + PathtoPublish: "$(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir)" + ArtifactName: "$(VsixPublishDir)" + ArtifactType: "Container" + condition: "and(succeeded(),eq(variables['BuildRTM'], 'false'))" + + - task: CopyFiles@2 + displayName: "Copy LCG Files" + inputs: + SourceFolder: "artifacts\\" + Contents: "**\\*.lcg" + TargetFolder: "$(CIRoot)\\PLOC\\$(Build.SourceBranchName)\\$(Build.BuildNumber)" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true')) " + + - task: PowerShell@1 + displayName: "Publish Artifacts to MyGet" + continueOnError: "true" + inputs: + scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\PublishArtifactsFromVsts.ps1" + arguments: "-NuGetBuildFeedUrl $(NuGetBuildFeed) -NuGetBuildSymbolsFeedUrl $(NuGetBuildSymbolsFeed) -DotnetCoreFeedUrl $(DotnetCoreBuildFeed) -DotnetCoreSymbolsFeedUrl $(DotnetCoreSymbolsFeed) -NuGetBuildFeedApiKey $(NuGetBuildApiKey) -DotnetCoreFeedApiKey $(DotnetCoreFeedApiKey)" + failOnStandardError: "true" + condition: " and(succeeded(),eq(variables['PublishArtifactsToMyGet'], 'true'), eq(variables['BuildRTM'], 'false')) " + + - task: MSBuild@1 + displayName: "Collect Build Symbols" + inputs: + solution: "build\\symbols.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/p:IsSymbolBuild=true" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true')) " + + - task: CopyFiles@2 + displayName: "Copy Symbols" + inputs: + SourceFolder: "$(Build.Repository.LocalPath)\\artifacts\\symbolstoindex" + Contents: "**\\*" + TargetFolder: "$(BuildOutputTargetPath)\\symbols" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true')) " + + - task: ms-vscs-artifact.build-tasks.artifactSymbolTask-1.artifactSymbolTask@0 + displayName: "Publish Symbols on Symweb" + inputs: + symbolServiceURI: "https://microsoft.artifacts.visualstudio.com/DefaultCollection" + requestName: "CollectionId/$(System.CollectionId)/ProjectId/$(System.TeamProjectId)/$(TeamName)/BuildId/$(Build.BuildId)" + sourcePath: "$(Build.Repository.LocalPath)\\artifacts\\symbolstoindex" + detailedLog: "true" + expirationInDays: "45" + usePat: "false" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false'), eq(variables['IsOfficialBuild'], 'true')) " + + - task: MicroBuildUploadVstsDropFolder@1 + displayName: "Upload VSTS Drop" + inputs: + DropFolder: "$(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir)" + condition: " and(succeeded(),eq(variables['BuildRTM'], 'false')) " + + - task: PowerShell@1 + displayName: "Validate VSIX Localization" + inputs: + scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\BuildValidator.ps1" + arguments: "-BuildRTM $(BuildRTM) -BuildOutputTargetPath $(BuildOutputTargetPath) -ValidateVsix" + condition: "succeeded()" + + - task: PowerShell@1 + displayName: "Validate Repository Artifacts Localization" + inputs: + scriptName: "$(Build.Repository.LocalPath)\\scripts\\cibuild\\BuildValidator.ps1" + arguments: "-BuildRTM $(BuildRTM) -BuildOutputTargetPath $(BuildOutputTargetPath)" + condition: "succeeded()" + + # Use dotnet msbuild instead of MSBuild CLI. + # Using MSBuild CLI results in an assembly binding failure for NuGet.Common.dll 4.4.0.3 because Microsoft.DotNet.Build.Tasks.Feed.dll references SleetLib.dll which references NuGet.Common 4.4.0.3. + # The Microsoft.DotNet.Build.Tasks.Feed package includes NuGet.Common 4.9.0.6 and a binding redirection in Microsoft.DotNet.Build.Tasks.Feed.dll.config but the binding redirection is not processed. + # This would probably solve it: https://github.com/Microsoft/msbuild/issues/1309 + - task: CmdLine@2 + displayName: "Publish the packages to the .NET Core build asset registry (BAR)" + inputs: + script: dotnet msbuild ..\build\publish.proj /t:PublishPackagesToBuildAssetRegistry /p:NuGetClientNupkgsDirectoryPath=$(Build.Repository.LocalPath)\artifacts\$(NupkgOutputDir) /p:FeedUrl=$(DotNetFeedUrl) /p:BuildId=$(Build.BuildNumber) /p:RepoBranch=$(Build.SourceBranchName) /p:RepoCommit=$(Build.SourceVersion) /p:RepoUri=$(Build.Repository.Uri) /p:ManifestFilePath=$(ManifestFilePath) /p:AccountKey=$(dotnetfeed-storage-access-key-1) + workingDirectory: cli + failOnStderr: true + env: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + DOTNET_MULTILEVEL_LOOKUP: true + condition: " and(succeeded(),eq(variables['PublishArtifactsToDotNetBuildAssetRegistry'], 'true'), eq(variables['BuildRTM'], 'false')) " + + - task: PowerShell@1 + displayName: "Upload the build manifest file as a build artifact" + inputs: + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[task.uploadfile]$(ManifestFilePath)" + condition: " and(succeeded(),eq(variables['PublishArtifactsToDotNetBuildAssetRegistry'], 'true'), eq(variables['BuildRTM'], 'false')) " + + - task: MSBuild@1 + displayName: "Publish the build manifest file to the .NET Core build asset registry (BAR)" + inputs: + solution: 'build\\publish.proj' + msbuildVersion: 16.0 + configuration: "$(BuildConfiguration)" + msbuildArguments: '/t:PublishManifestToBuildAssetRegistry /p:MaestroApiEndpoint=$(MaestroApiEndpoint) /p:ManifestsDirectoryPath=$(Build.Repository.LocalPath)\artifacts\manifests /p:MaestroAccessToken=$(MaestroAccessToken)' + condition: " and(succeeded(),eq(variables['PublishArtifactsToDotNetBuildAssetRegistry'], 'true'), eq(variables['BuildRTM'], 'false')) " + + - task: MicroBuildCleanup@1 + displayName: "Perform Cleanup Tasks" + + - task: PowerShell@1 + displayName: "Cleanup on Failure" + inputs: + scriptType: "inlineScript" + arguments: "-BuildOutputTargetPath $(BuildOutputTargetPath)" + inlineScript: | + param([string]$BuildOutputTargetPath) + Get-ChildItem $(BuildOutputTargetPath) -Recurse | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue + Remove-Item -Path $(BuildOutputTargetPath) -Force -Recurse -ErrorAction SilentlyContinue + condition: "eq(variables['Agent.JobStatus'], 'Failed')" + + - phase: Functional_Tests_On_Windows + dependsOn: Initialize_Build + variables: + BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']] + FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + condition: "and(succeeded(),eq(variables['RunFunctionalTestsOnWindows'], 'true')) " + queue: + name: VSEng-MicroBuildSxS + timeoutInMinutes: 150 + demands: + - DotNetFramework + - msbuild + matrix: + IsDesktop: + SkipCoreAssemblies: "true" + IsCore: + SkipDesktopAssemblies: "true" + + steps: + - 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: PowerShell@1 + displayName: "Print Environment Variables" + inputs: + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" + Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize + + - task: PowerShell@1 + displayName: "Download Config Files" + enabled: "false" + inputs: + scriptType: "inlineScript" + inlineScript: | + $url = $(VstsConfigFileRootUrl) -f 'NuGet.Core.FuncTests.Config' + Invoke-RestMethod -Method Get -Uri $url -UseDefaultCredentials -OutFile $(Build.Repository.LocalPath)\\NuGet.Core.FuncTests.Config + $url = $(VstsConfigFileRootUrl) -f 'NuGet.Protocol.FuncTest.Config' + Invoke-RestMethod -Method Get -Uri $url -UseDefaultCredentials -OutFile $(Build.Repository.LocalPath)\\NuGet.Protocol.FuncTest.Config + + - task: PowerShell@1 + displayName: "Run Configure.ps1" + inputs: + scriptName: "$(Build.Repository.LocalPath)\\configure.ps1" + arguments: "-Force -CleanCache" + + - task: MSBuild@1 + displayName: "Restore for VS2019" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:RestoreVS /p:BuildNumber=$(BuildNumber) /p:BuildRTM=false /v:m" + + - task: MSBuild@1 + displayName: "Run Functional Tests" + continueOnError: "true" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:CoreFuncTests /p:BuildRTM=false /p:BuildNumber=$(BuildNumber) /p:TestResultOutputFormat=xml /p:SkipDesktopAssemblies=$(SkipDesktopAssemblies) /p:SkipCoreAssemblies=$(SkipCoreAssemblies)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + continueOnError: "true" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + searchFolder: "$(Build.Repository.LocalPath)\\build\\TestResults" + mergeTestResults: "true" + testRunTitle: "NuGet.Client Functional Tests On Windows" + condition: "succeededOrFailed()" + + - task: PowerShell@1 + displayName: "Initialize Git Commit Status on GitHub" + inputs: + scriptType: "inlineScript" + arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" + inlineScript: | + . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 + SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -CommitSha $(Build.SourceVersion) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -TestName "$env:AGENT_JOBNAME" + condition: "always()" + + - phase: Tests_On_Linux + dependsOn: Initialize_Build + variables: + FULLVSTSBUILDNUMBER: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + MSBUILDDISABLENODEREUSE: 1 + condition: "and(succeeded(),eq(variables['RunTestsOnLinux'], 'true')) " + queue: + name: DDNuGet-Linux + timeoutInMinutes: 60 + demands: sh + + 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: "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: + targetType: "inline" + script: | + Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER" + failOnStderr: "true" + condition: "always()" + + - task: ShellScript@2 + displayName: "Run Tests" + continueOnError: "true" + inputs: + scriptPath: "scripts/funcTests/runFuncTests.sh" + disableAutoCwd: "true" + cwd: "$(Build.Repository.LocalPath)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + testRunTitle: "NuGet.Client Tests On Linux" + searchFolder: "$(Build.Repository.LocalPath)/build/TestResults" + mergeTestResults: "true" + + - task: PowerShell@2 + displayName: "Initialize Git Commit Status on GitHub" + inputs: + targetType: "inline" + arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" + script: | + . $(Build.Repository.LocalPath)/scripts/utils/PostGitCommitStatus.ps1 + SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "Tests On Linux" + failOnStderr: "true" + condition: "always()" + + - phase: Tests_On_Mac + dependsOn: + - Build_and_UnitTest + - Initialize_Build + variables: + FULLVSTSBUILDNUMBER: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + condition: "and(succeeded(),eq(variables['RunTestsOnMac'], 'true')) " + queue: + name: VSEng-MicroBuildMacCustom + timeoutInMinutes: 75 + demands: + - sh + - VSTS_OS -equals Mac_Mojave_10.14 + - Mono -equals 6.4.0 + + 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: + targetType: "inline" + script: | + Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER" + 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: + artifactName: "NuGet.CommandLine.Test" + downloadPath: "$(Build.Repository.LocalPath)/artifacts" + + - task: ShellScript@2 + displayName: "Run Tests" + continueOnError: "true" + inputs: + scriptPath: "scripts/funcTests/runFuncTests.sh" + disableAutoCwd: "true" + cwd: "$(Build.Repository.LocalPath)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + searchFolder: "$(Build.Repository.LocalPath)/build/TestResults" + mergeTestResults: "true" + testRunTitle: "NuGet.Client Tests On Mac" + condition: "succeededOrFailed()" + + - task: PowerShell@2 + displayName: "Initialize Git Commit Status on GitHub" + inputs: + targetType: "inline" + arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" + script: | + . $(Build.Repository.LocalPath)/scripts/utils/PostGitCommitStatus.ps1 + SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "Tests On Mac" + failOnStderr: "true" + condition: "always()" + + - phase: End_To_End_Tests_On_Windows + dependsOn: + - Build_and_UnitTest + - Initialize_Build + variables: + FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + condition: "and(succeeded(),eq(variables['RunEndToEndTests'], 'true')) " + queue: + timeoutInMinutes: 90 + name: DDNuGet-Windows + demands: DotNetFramework + + steps: + - 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: PowerShell@1 + displayName: "Print Environment Variables" + inputs: + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" + Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize + + - task: DownloadBuildArtifacts@0 + displayName: "Download Build artifacts" + inputs: + artifactName: "$(VsixPublishDir)" + downloadPath: "$(Build.Repository.LocalPath)/artifacts" + + - task: PowerShell@1 + displayName: "Bootstrap.ps1" + inputs: + scriptName: "$(System.DefaultWorkingDirectory)/scripts/e2etests/Bootstrap.ps1" + arguments: "-NuGetDropPath $(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir) -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -verbose" + + - task: PowerShell@1 + displayName: "SetupFunctionalTests.ps1" + inputs: + scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\SetupFunctionalTests.ps1" + + - task: PowerShell@1 + displayName: "SetupMachine.ps1" + inputs: + scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\SetupMachine.ps1" + + - task: PowerShell@1 + displayName: "InstallNuGetVSIX.ps1" + inputs: + scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\InstallNuGetVSIX.ps1" + arguments: "-NuGetDropPath $(System.DefaultWorkingDirectory)\\artifacts\\$(VsixPublishDir) -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -NuGetVSIXID $(NuGetVsixId) -ProcessExitTimeoutInSeconds 180 -VSVersion 16.0" + failOnStandardError: "false" + + - task: PowerShell@1 + displayName: "Collect VS Logs" + inputs: + scriptType: "inlineScript" + inlineScript: | + Invoke-WebRequest -Uri $(CollectExeUrl) -OutFile $(System.DefaultWorkingDirectory)\\VSCollect.exe + $(System.DefaultWorkingDirectory)\\VSCollect.exe -zip:$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\e2e-collectlogs.zip + condition: "failed()" + + - task: PowerShell@1 + displayName: "RunFunctionalTests.ps1" + timeoutInMinutes: 75 + continueOnError: "true" + inputs: + scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\RunFunctionalTests.ps1" + arguments: "-PMCCommand $(EndToEndTestCommandToRun) -PMCLaunchWaitTimeInSecs 30 -EachTestTimoutInSecs 600 -NuGetDropPath $(System.DefaultWorkingDirectory)\\artifacts -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -RunCounter $(Build.BuildNumber) -VSVersion 16.0" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "JUnit" + testResultsFiles: "*.xml" + searchFolder: "$(System.DefaultWorkingDirectory)\\testresults" + mergeTestResults: "true" + testRunTitle: "NuGet.Client EndToEnd Tests On Windows" + condition: "succeededOrFailed()" + + - task: PowerShell@1 + displayName: "Initialize Git Commit Status on GitHub" + inputs: + scriptType: "inlineScript" + arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" + inlineScript: | + . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 + SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "EndToEnd Tests On Windows" + condition: "always()" + + - task: PowerShell@1 + displayName: "Kill running instances of DevEnv" + inputs: + scriptType: "inlineScript" + inlineScript: | + . $(Build.Repository.LocalPath)\\scripts\\e2etests\\VSUtils.ps1 + KillRunningInstancesOfVS + condition: "always()" + + - phase: Apex_Tests_On_Windows + dependsOn: + - Build_and_UnitTest + - Initialize_Build + variables: + BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']] + FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + condition: "and(succeeded(),eq(variables['RunApexTests'], 'true')) " + queue: + name: DDNuGet-Windows + demands: DotNetFramework + + steps: + - checkout: self + clean: true + submodules: true + + - task: PowerShell@1 + displayName: "Print Environment Variables" + inputs: + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" + Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize + + - task: DownloadBuildArtifacts@0 + displayName: "Download Build artifacts" + inputs: + artifactName: "$(VsixPublishDir)" + downloadPath: "$(Build.Repository.LocalPath)/artifacts" + + - task: NuGetToolInstaller@0 + displayName: "Use NuGet 4.5.0" + 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: + solution: "build\\bootstrap.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:Restore" + + - task: PowerShell@1 + displayName: "Bootstrap.ps1" + inputs: + scriptName: "$(System.DefaultWorkingDirectory)/scripts/e2etests/Bootstrap.ps1" + arguments: "-NuGetDropPath $(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir) -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -verbose" + + - task: PowerShell@1 + displayName: "SetupFunctionalTests.ps1" + inputs: + scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\SetupFunctionalTests.ps1" + arguments: "-VSVersion 16.0" + + - task: PowerShell@1 + displayName: "InstallNuGetVSIX.ps1" + inputs: + scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\InstallNuGetVSIX.ps1" + arguments: "-NuGetDropPath $(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir) -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -NuGetVSIXID $(NuGetVsixId) -ProcessExitTimeoutInSeconds 180 -VSVersion 16.0" + failOnStandardError: "false" + + # - task: PowerShell@1 + # displayName: "Collect VS Logs" + # inputs: + # scriptType: "inlineScript" + # inlineScript: | + # Invoke-WebRequest -Uri $(CollectExeUrl) -OutFile $(System.DefaultWorkingDirectory)\\VSCollect.exe + # if(-not (Test-Path $(EndToEndResultsDropPath))) + # { + # New-Item -Path $(EndToEndResultsDropPath) -ItemType Directory -Force + # } + # $(System.DefaultWorkingDirectory)\\VSCollect.exe -zip:$(EndToEndResultsDropPath)\\apex-collectlogs.zip + # condition: "failed()" + + - task: NuGetCommand@2 + displayName: "Add Apex Feed Source" + inputs: + command: "custom" + arguments: "sources add -Name ApexFeed -Source $(ApexPackageFeedUrl) -UserName $(ApexPackageFeedUsername) -Password $(ApexPackageFeedPassword) -ConfigFile $(System.DefaultWorkingDirectory)\\NuGet.config" + + - task: MSBuild@1 + displayName: "Restore Apex Tests" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:RestoreApex /p:BuildNumber=$(BuildNumber)" + + - task: MSBuild@1 + displayName: "Run Apex Tests" + timeoutInMinutes: 45 + continueOnError: "true" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:ApexTestsStandalone /p:TestResultOutputFormat=xml /p:BuildNumber=$(BuildNumber)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + searchFolder: "$(System.DefaultWorkingDirectory)\\build\\TestResults" + mergeTestResults: "true" + testRunTitle: "NuGet.Client Apex Tests On Windows" + condition: "succeededOrFailed()" + + - task: PowerShell@1 + displayName: "Initialize Git Commit Status on GitHub" + inputs: + arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" + scriptType: "inlineScript" + inlineScript: | + . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 + SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "Apex Tests On Windows" + condition: "always()" + + - task: PowerShell@1 + displayName: "Kill running instances of DevEnv" + inputs: + scriptType: "inlineScript" + inlineScript: | + . $(Build.Repository.LocalPath)\\scripts\\e2etests\\VSUtils.ps1 + KillRunningInstancesOfVS + condition: "always()" + + - phase: CrossVerify_Generate_Packages_On_Windows + dependsOn: Initialize_Build + variables: + BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']] + FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + condition: "and(succeeded(),eq(variables['RunFunctionalTestsOnWindows'], 'true')) " + queue: + name: VSEng-MicroBuildSxS + timeoutInMinutes: 30 + demands: + - DotNetFramework + - msbuild + matrix: + IsDesktop: + SkipCoreAssemblies: "true" + PreGenPackageFolder: "Windows_NetFulFramework" + IsCore: + SkipDesktopAssemblies: "true" + PreGenPackageFolder: "Windows_NetCore" + + steps: + - 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: PowerShell@1 + displayName: "Print Environment Variables" + inputs: + scriptType: "inlineScript" + inlineScript: | + Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" + gci env:* | sort-object name + + - task: PowerShell@1 + displayName: "Run Configure.ps1" + inputs: + scriptName: "$(Build.Repository.LocalPath)\\configure.ps1" + arguments: "-Force -CleanCache" + + - task: MSBuild@1 + displayName: "Restore Cross Verify projects" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:RestoreCrossVerifyTest /p:BuildNumber=$(BuildNumber) /p:BuildRTM=false /v:m" + + - task: MSBuild@1 + displayName: "Run Generating Signed Package Tests" + continueOnError: "true" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:CrossVerifyGeneratePackageTests /p:BuildRTM=false /p:BuildNumber=$(BuildNumber) /p:TestResultOutputFormat=xml /p:SkipDesktopAssemblies=$(SkipDesktopAssemblies) /p:SkipCoreAssemblies=$(SkipCoreAssemblies)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + continueOnError: "true" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + searchFolder: "$(Build.Repository.LocalPath)\\build\\TestResults" + mergeTestResults: "true" + testRunTitle: "NuGet Generate Signed Packages On Windows" + condition: "succeededOrFailed()" + + - task: PublishBuildArtifacts@1 + displayName: "Publish pre generated packages by $(PreGenPackageFolder)" + continueOnError: "true" + inputs: + pathToPublish: "$(Build.Repository.LocalPath)\\.test\\work\\PreGenPackages\\$(PreGenPackageFolder)" + artifactName: "$(PreGenPackageFolder)" + publishLocation: "Container" + condition: "succeededOrFailed()" + + - phase: CrossVerify_Verify_Packages_On_Windows + dependsOn: + - Initialize_Build + - CrossVerify_Generate_Packages_On_Windows + - CrossVerify_Generate_Packages_On_Linux + - CrossVerify_Generate_Packages_On_Mac + variables: + BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']] + FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + condition: "and(succeeded(),eq(variables['RunFunctionalTestsOnWindows'], 'true')) " + queue: + name: VSEng-MicroBuildSxS + timeoutInMinutes: 30 + demands: - DotNetFramework - msbuild - matrix: - IsDesktop: - SkipCoreAssemblies: "true" - IsCore: - SkipDesktopAssemblies: "true" - - steps: - - 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: PowerShell@1 - displayName: "Print Environment Variables" - inputs: - scriptType: "inlineScript" - inlineScript: | - Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" - Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize - - - task: PowerShell@1 - displayName: "Download Config Files" - enabled: "false" - inputs: - scriptType: "inlineScript" - inlineScript: | - $url = $(VstsConfigFileRootUrl) -f 'NuGet.Core.FuncTests.Config' - Invoke-RestMethod -Method Get -Uri $url -UseDefaultCredentials -OutFile $(Build.Repository.LocalPath)\\NuGet.Core.FuncTests.Config - $url = $(VstsConfigFileRootUrl) -f 'NuGet.Protocol.FuncTest.Config' - Invoke-RestMethod -Method Get -Uri $url -UseDefaultCredentials -OutFile $(Build.Repository.LocalPath)\\NuGet.Protocol.FuncTest.Config - - - task: PowerShell@1 - displayName: "Run Configure.ps1" - inputs: - scriptName: "$(Build.Repository.LocalPath)\\configure.ps1" - arguments: "-Force -CleanCache" - - - task: MSBuild@1 - displayName: "Restore for VS2019" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:RestoreVS /p:BuildNumber=$(BuildNumber) /p:BuildRTM=false /v:m" - - - task: MSBuild@1 - displayName: "Run Functional Tests" - continueOnError: "true" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:CoreFuncTests /p:BuildRTM=false /p:BuildNumber=$(BuildNumber) /p:TestResultOutputFormat=xml /p:SkipDesktopAssemblies=$(SkipDesktopAssemblies) /p:SkipCoreAssemblies=$(SkipCoreAssemblies)" - - - task: PublishTestResults@2 - displayName: "Publish Test Results" - continueOnError: "true" - inputs: - testRunner: "XUnit" - testResultsFiles: "*.xml" - searchFolder: "$(Build.Repository.LocalPath)\\build\\TestResults" - mergeTestResults: "true" - testRunTitle: "NuGet.Client Functional Tests On Windows" - condition: "succeededOrFailed()" - - - task: PowerShell@1 - displayName: "Initialize Git Commit Status on GitHub" - inputs: - scriptType: "inlineScript" - arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" - inlineScript: | - . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 - SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -CommitSha $(Build.SourceVersion) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -TestName "$env:AGENT_JOBNAME" - condition: "always()" - -- phase: Tests_On_Linux - dependsOn: Initialize_Build - variables: - FULLVSTSBUILDNUMBER: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] - SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] - MSBUILDDISABLENODEREUSE: 1 - condition: "and(succeeded(),eq(variables['RunTestsOnLinux'], 'true')) " - queue: - name: DDNuGet-Linux - timeoutInMinutes: 60 - demands: sh - - 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: "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: - targetType: "inline" - script: | - Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER" - failOnStderr: "true" - condition: "always()" - - - task: ShellScript@2 - displayName: "Run Tests" - continueOnError: "true" - inputs: - scriptPath: "scripts/funcTests/runFuncTests.sh" - disableAutoCwd: "true" - cwd: "$(Build.Repository.LocalPath)" - - - task: PublishTestResults@2 - displayName: "Publish Test Results" - inputs: - testRunner: "XUnit" - testResultsFiles: "*.xml" - testRunTitle: "NuGet.Client Tests On Linux" - searchFolder: "$(Build.Repository.LocalPath)/build/TestResults" - mergeTestResults: "true" - - - task: PowerShell@2 - displayName: "Initialize Git Commit Status on GitHub" - inputs: - targetType: "inline" - arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" - script: | - . $(Build.Repository.LocalPath)/scripts/utils/PostGitCommitStatus.ps1 - SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "Tests On Linux" - failOnStderr: "true" - condition: "always()" - -- phase: Tests_On_Mac - dependsOn: - - Build_and_UnitTest - - Initialize_Build - variables: - FULLVSTSBUILDNUMBER: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] - SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] - condition: "and(succeeded(),eq(variables['RunTestsOnMac'], 'true')) " - queue: - name: VSEng-MicroBuildMacCustom - timeoutInMinutes: 75 - demands: - - sh - - VSTS_OS -equals Mac_Mojave_10.14 - - Mono -equals 6.4.0 - - 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: - targetType: "inline" - script: | - Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER" - 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: - artifactName: "NuGet.CommandLine.Test" - downloadPath: "$(Build.Repository.LocalPath)/artifacts" - - - task: ShellScript@2 - displayName: "Run Tests" - continueOnError: "true" - inputs: - scriptPath: "scripts/funcTests/runFuncTests.sh" - disableAutoCwd: "true" - cwd: "$(Build.Repository.LocalPath)" - - - task: PublishTestResults@2 - displayName: "Publish Test Results" - inputs: - testRunner: "XUnit" - testResultsFiles: "*.xml" - searchFolder: "$(Build.Repository.LocalPath)/build/TestResults" - mergeTestResults: "true" - testRunTitle: "NuGet.Client Tests On Mac" - condition: "succeededOrFailed()" - - - task: PowerShell@2 - displayName: "Initialize Git Commit Status on GitHub" - inputs: - targetType: "inline" - arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" - script: | - . $(Build.Repository.LocalPath)/scripts/utils/PostGitCommitStatus.ps1 - SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "Tests On Mac" - failOnStderr: "true" - condition: "always()" - -- phase: End_To_End_Tests_On_Windows - dependsOn: - - Build_and_UnitTest - - Initialize_Build - variables: - FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] - SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] - condition: "and(succeeded(),eq(variables['RunEndToEndTests'], 'true')) " - queue: - timeoutInMinutes: 90 - name: DDNuGet-Windows - demands: DotNetFramework - - steps: - - 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: PowerShell@1 - displayName: "Print Environment Variables" - inputs: - scriptType: "inlineScript" - inlineScript: | - Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" - Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize - - - task: DownloadBuildArtifacts@0 - displayName: "Download Build artifacts" - inputs: - artifactName: "$(VsixPublishDir)" - downloadPath: "$(Build.Repository.LocalPath)/artifacts" - - - task: PowerShell@1 - displayName: "Bootstrap.ps1" - inputs: - scriptName: "$(System.DefaultWorkingDirectory)/scripts/e2etests/Bootstrap.ps1" - arguments: "-NuGetDropPath $(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir) -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -verbose" - - - task: PowerShell@1 - displayName: "SetupFunctionalTests.ps1" - inputs: - scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\SetupFunctionalTests.ps1" - - - task: PowerShell@1 - displayName: "SetupMachine.ps1" - inputs: - scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\SetupMachine.ps1" - - - task: PowerShell@1 - displayName: "InstallNuGetVSIX.ps1" - inputs: - scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\InstallNuGetVSIX.ps1" - arguments: "-NuGetDropPath $(System.DefaultWorkingDirectory)\\artifacts\\$(VsixPublishDir) -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -NuGetVSIXID $(NuGetVsixId) -ProcessExitTimeoutInSeconds 180 -VSVersion 16.0" - failOnStandardError: "false" - - - task: PowerShell@1 - displayName: "Collect VS Logs" - inputs: - scriptType: "inlineScript" - inlineScript: | - Invoke-WebRequest -Uri $(CollectExeUrl) -OutFile $(System.DefaultWorkingDirectory)\\VSCollect.exe - $(System.DefaultWorkingDirectory)\\VSCollect.exe -zip:$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\e2e-collectlogs.zip - condition: "failed()" - - - task: PowerShell@1 - displayName: "RunFunctionalTests.ps1" - timeoutInMinutes: 75 - continueOnError: "true" - inputs: - scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\RunFunctionalTests.ps1" - arguments: "-PMCCommand $(EndToEndTestCommandToRun) -PMCLaunchWaitTimeInSecs 30 -EachTestTimoutInSecs 600 -NuGetDropPath $(System.DefaultWorkingDirectory)\\artifacts -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -RunCounter $(Build.BuildNumber) -VSVersion 16.0" - - - task: PublishTestResults@2 - displayName: "Publish Test Results" - inputs: - testRunner: "JUnit" - testResultsFiles: "*.xml" - searchFolder: "$(System.DefaultWorkingDirectory)\\testresults" - mergeTestResults: "true" - testRunTitle: "NuGet.Client EndToEnd Tests On Windows" - condition: "succeededOrFailed()" - - - task: PowerShell@1 - displayName: "Initialize Git Commit Status on GitHub" - inputs: - scriptType: "inlineScript" - arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" - inlineScript: | - . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 - SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "EndToEnd Tests On Windows" - condition: "always()" - - - task: PowerShell@1 - displayName: "Kill running instances of DevEnv" - inputs: - scriptType: "inlineScript" - inlineScript: | - . $(Build.Repository.LocalPath)\\scripts\\e2etests\\VSUtils.ps1 - KillRunningInstancesOfVS - condition: "always()" - -- phase: Apex_Tests_On_Windows - dependsOn: - - Build_and_UnitTest - - Initialize_Build - variables: - BuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.BuildNumber']] - FullVstsBuildNumber: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] - SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] - condition: "and(succeeded(),eq(variables['RunApexTests'], 'true')) " - queue: - name: DDNuGet-Windows - demands: DotNetFramework - - steps: - - checkout: self - clean: true - submodules: true - - - task: PowerShell@1 - displayName: "Print Environment Variables" - inputs: - scriptType: "inlineScript" - inlineScript: | - Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" - Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize - - - task: DownloadBuildArtifacts@0 - displayName: "Download Build artifacts" - inputs: - artifactName: "$(VsixPublishDir)" - downloadPath: "$(Build.Repository.LocalPath)/artifacts" - - - task: NuGetToolInstaller@0 - displayName: "Use NuGet 4.5.0" - 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: - solution: "build\\bootstrap.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:Restore" - - - task: PowerShell@1 - displayName: "Bootstrap.ps1" - inputs: - scriptName: "$(System.DefaultWorkingDirectory)/scripts/e2etests/Bootstrap.ps1" - arguments: "-NuGetDropPath $(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir) -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -verbose" - - - task: PowerShell@1 - displayName: "SetupFunctionalTests.ps1" - inputs: - scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\SetupFunctionalTests.ps1" - arguments: "-VSVersion 16.0" - - - task: PowerShell@1 - displayName: "InstallNuGetVSIX.ps1" - inputs: - scriptName: "$(System.DefaultWorkingDirectory)\\artifacts\\EndToEnd\\scripts\\InstallNuGetVSIX.ps1" - arguments: "-NuGetDropPath $(Build.Repository.LocalPath)\\artifacts\\$(VsixPublishDir) -FuncTestRoot $(System.DefaultWorkingDirectory)\\artifacts -NuGetVSIXID $(NuGetVsixId) -ProcessExitTimeoutInSeconds 180 -VSVersion 16.0" - failOnStandardError: "false" - - # - task: PowerShell@1 - # displayName: "Collect VS Logs" - # inputs: - # scriptType: "inlineScript" - # inlineScript: | - # Invoke-WebRequest -Uri $(CollectExeUrl) -OutFile $(System.DefaultWorkingDirectory)\\VSCollect.exe - # if(-not (Test-Path $(EndToEndResultsDropPath))) - # { - # New-Item -Path $(EndToEndResultsDropPath) -ItemType Directory -Force - # } - # $(System.DefaultWorkingDirectory)\\VSCollect.exe -zip:$(EndToEndResultsDropPath)\\apex-collectlogs.zip - # condition: "failed()" - - - task: NuGetCommand@2 - displayName: "Add Apex Feed Source" - inputs: - command: "custom" - arguments: "sources add -Name ApexFeed -Source $(ApexPackageFeedUrl) -UserName $(ApexPackageFeedUsername) -Password $(ApexPackageFeedPassword) -ConfigFile $(System.DefaultWorkingDirectory)\\NuGet.config" - - - task: MSBuild@1 - displayName: "Restore Apex Tests" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:RestoreApex /p:BuildNumber=$(BuildNumber)" - - - task: MSBuild@1 - displayName: "Run Apex Tests" - timeoutInMinutes: 45 - continueOnError: "true" - inputs: - solution: "build\\build.proj" - msbuildVersion: "16.0" - configuration: "$(BuildConfiguration)" - msbuildArguments: "/t:ApexTestsStandalone /p:TestResultOutputFormat=xml /p:BuildNumber=$(BuildNumber)" - - - task: PublishTestResults@2 - displayName: "Publish Test Results" - inputs: - testRunner: "XUnit" - testResultsFiles: "*.xml" - searchFolder: "$(System.DefaultWorkingDirectory)\\build\\TestResults" - mergeTestResults: "true" - testRunTitle: "NuGet.Client Apex Tests On Windows" - condition: "succeededOrFailed()" - - - task: PowerShell@1 - displayName: "Initialize Git Commit Status on GitHub" - inputs: - arguments: "-VstsPersonalAccessToken $(VstsPersonalAccessToken)" - scriptType: "inlineScript" - inlineScript: | - . $(Build.Repository.LocalPath)\\scripts\\utils\\PostGitCommitStatus.ps1 - SetCommitStatusForTestResult -PersonalAccessToken $(NuGetLurkerPersonalAccessToken) -VstsPersonalAccessToken $(VstsPersonalAccessToken) -CommitSha $(Build.SourceVersion) -TestName "Apex Tests On Windows" - condition: "always()" - - - task: PowerShell@1 - displayName: "Kill running instances of DevEnv" - inputs: - scriptType: "inlineScript" - inlineScript: | - . $(Build.Repository.LocalPath)\\scripts\\e2etests\\VSUtils.ps1 - KillRunningInstancesOfVS - condition: "always()" + matrix: + IsDesktop: + SkipCoreAssemblies: "true" + IsCore: + SkipDesktopAssemblies: "true" + + steps: + - 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: PowerShell@1 + # displayName: "Print Environment Variables" + # inputs: + # scriptType: "inlineScript" + # inlineScript: | + # Write-Host "##vso[build.updatebuildnumber]$env:FullVstsBuildNumber" + # gci env:* | sort-object name + + - task: PowerShell@1 + displayName: "Run Configure.ps1" + inputs: + scriptName: "$(Build.Repository.LocalPath)\\configure.ps1" + arguments: "-Force -CleanCache" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Windows_NetFulFramework artifacts" + inputs: + artifactName: "Windows_NetFulFramework" + downloadPath: "$(Build.Repository.LocalPath)\\.test\\work\\PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Windows_NetCore artifacts" + inputs: + artifactName: "Windows_NetCore" + downloadPath: "$(Build.Repository.LocalPath)\\.test\\work\\PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Linux_NetCore artifacts" + inputs: + artifactName: "Linux_NetCore" + downloadPath: "$(Build.Repository.LocalPath)\\.test\\work\\PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Mac_NetCore artifacts" + inputs: + artifactName: "Mac_NetCore" + downloadPath: "$(Build.Repository.LocalPath)\\.test\\work\\PreGenPackages" + + - task: MSBuild@1 + displayName: "Restore Cross Verify projects" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:RestoreCrossVerifyTest /p:BuildNumber=$(BuildNumber) /p:BuildRTM=false /v:m" + + - task: MSBuild@1 + displayName: "Run Verify Signed Package Tests" + continueOnError: "true" + inputs: + solution: "build\\build.proj" + msbuildVersion: "16.0" + configuration: "$(BuildConfiguration)" + msbuildArguments: "/t:CrossVerifyVerifyPackageTests /p:BuildRTM=false /p:BuildNumber=$(BuildNumber) /p:TestResultOutputFormat=xml /p:SkipDesktopAssemblies=$(SkipDesktopAssemblies) /p:SkipCoreAssemblies=$(SkipCoreAssemblies)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + continueOnError: "true" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + searchFolder: "$(Build.Repository.LocalPath)\\build\\TestResults" + mergeTestResults: "true" + testRunTitle: "NuGet Verify Signed Packages From All Platforms On Windows" + condition: "succeededOrFailed()" + + - phase: CrossVerify_Generate_Packages_On_Linux + dependsOn: Initialize_Build + variables: + FULLVSTSBUILDNUMBER: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + MSBUILDDISABLENODEREUSE: 1 + condition: "and(succeeded(),eq(variables['RunTestsOnLinux'], 'true')) " + queue: + name: DDNuGet-Linux + timeoutInMinutes: 30 + demands: sh + + 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: "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: + # targetType: "inline" + # script: | + # Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER" + # failOnStderr: "true" + # condition: "always()" + + - task: ShellScript@2 + displayName: "Generate Signed Packages" + continueOnError: "true" + inputs: + scriptPath: "scripts/funcTests/runGenSignedPackages.sh" + disableAutoCwd: "true" + cwd: "$(Build.Repository.LocalPath)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + testRunTitle: "NuGet.Client Tests On Linux" + searchFolder: "$(Build.Repository.LocalPath)/build/TestResults" + mergeTestResults: "true" + + - task: PublishBuildArtifacts@1 + displayName: "Publish pre generated packages by Linux_NetCore" + continueOnError: "true" + inputs: + pathToPublish: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages/Linux_NetCore" + artifactName: "Linux_NetCore" + publishLocation: "Container" + condition: "succeededOrFailed()" + + - phase: CrossVerify_Verify_Tests_On_Linux + dependsOn: + - Initialize_Build + - CrossVerify_Generate_Packages_On_Windows + - CrossVerify_Generate_Packages_On_Linux + - CrossVerify_Generate_Packages_On_Mac + variables: + FULLVSTSBUILDNUMBER: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + MSBUILDDISABLENODEREUSE: 1 + condition: "and(succeeded(),eq(variables['RunTestsOnLinux'], 'true')) " + queue: + name: DDNuGet-Linux + timeoutInMinutes: 30 + demands: sh + + 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: "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: + # targetType: "inline" + # script: | + # Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER" + # failOnStderr: "true" + # condition: "always()" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Windows_NetFulFramework artifacts" + inputs: + artifactName: "Windows_NetFulFramework" + downloadPath: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Windows_NetCore artifacts" + inputs: + artifactName: "Windows_NetCore" + downloadPath: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Linux_NetCore artifacts" + inputs: + artifactName: "Linux_NetCore" + downloadPath: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Mac_NetCore artifacts" + inputs: + artifactName: "Mac_NetCore" + downloadPath: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages" + + - task: ShellScript@2 + displayName: "Verify Signed Packages" + continueOnError: "true" + inputs: + scriptPath: "scripts/funcTests/runVerifySignedPackages.sh" + disableAutoCwd: "true" + cwd: "$(Build.Repository.LocalPath)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + testRunTitle: "NuGet Verify Signed Packages From All Platforms On Linux" + searchFolder: "$(Build.Repository.LocalPath)/build/TestResults" + mergeTestResults: "true" + + - phase: CrossVerify_Generate_Packages_On_Mac + dependsOn: Initialize_Build + variables: + FULLVSTSBUILDNUMBER: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + MSBUILDDISABLENODEREUSE: 1 + condition: "and(succeeded(),eq(variables['RunTestsOnMac'], 'true')) " + queue: + name: VSEng-MicroBuildMacCustom + timeoutInMinutes: 30 + demands: + - sh + - VSTS_OS -equals Mac_Mojave_10.14 + + 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: "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: + # targetType: "inline" + # script: | + # Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER" + # failOnStderr: "true" + # condition: "always()" + + - task: ShellScript@2 + displayName: "Generate Signed Packages" + continueOnError: "true" + inputs: + scriptPath: "scripts/funcTests/runGenSignedPackages.sh" + disableAutoCwd: "true" + cwd: "$(Build.Repository.LocalPath)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + testRunTitle: "NuGet.Client Tests On Mac" + searchFolder: "$(Build.Repository.LocalPath)/build/TestResults" + mergeTestResults: "true" + + - task: PublishBuildArtifacts@1 + displayName: "Publish pre generated packages by Mac_NetCore" + continueOnError: "true" + inputs: + pathToPublish: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages/Mac_NetCore" + artifactName: "Mac_NetCore" + publishLocation: "Container" + condition: "succeededOrFailed()" + + - phase: CrossVerify_Verify_Tests_On_Mac + dependsOn: + - Initialize_Build + - CrossVerify_Generate_Packages_On_Windows + - CrossVerify_Generate_Packages_On_Mac + - CrossVerify_Generate_Packages_On_Linux + variables: + FULLVSTSBUILDNUMBER: $[dependencies.Initialize_Build.outputs['updatebuildnumber.FullVstsBuildNumber']] + SDKVersionForBuild: $[dependencies.Initialize_Build.outputs['getSDKVersionForBuild.SDKVersionForBuild']] + MSBUILDDISABLENODEREUSE: 1 + condition: "and(succeeded(),eq(variables['RunTestsOnMac'], 'true')) " + queue: + name: VSEng-MicroBuildMacCustom + timeoutInMinutes: 75 + demands: + - sh + - VSTS_OS -equals Mac_Mojave_10.14 + - Mono -equals 6.4.0 + + 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: "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: + # targetType: "inline" + # script: | + # Write-Host "##vso[build.updatebuildnumber]$env:FULLVSTSBUILDNUMBER" + # failOnStderr: "true" + # condition: "always()" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Windows_NetFulFramework artifacts" + inputs: + artifactName: "Windows_NetFulFramework" + downloadPath: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Windows_NetCore artifacts" + inputs: + artifactName: "Windows_NetCore" + downloadPath: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Linux_NetCore artifacts" + inputs: + artifactName: "Linux_NetCore" + downloadPath: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages" + + - task: DownloadBuildArtifacts@0 + displayName: "Download Signed Packages from Mac_NetCore artifacts" + inputs: + artifactName: "Mac_NetCore" + downloadPath: "$(Build.Repository.LocalPath)/.test/work/PreGenPackages" + + - task: ShellScript@2 + displayName: "Verify Signed Packages" + continueOnError: "true" + inputs: + scriptPath: "scripts/funcTests/runVerifySignedPackages.sh" + disableAutoCwd: "true" + cwd: "$(Build.Repository.LocalPath)" + + - task: PublishTestResults@2 + displayName: "Publish Test Results" + inputs: + testRunner: "XUnit" + testResultsFiles: "*.xml" + testRunTitle: "NuGet Verify Signed Packages From All Platforms On Mac" + searchFolder: "$(Build.Repository.LocalPath)/build/TestResults" + mergeTestResults: "true" diff --git a/scripts/funcTests/runGenSignedPackages.sh b/scripts/funcTests/runGenSignedPackages.sh new file mode 100644 index 00000000000..c6ec75da048 --- /dev/null +++ b/scripts/funcTests/runGenSignedPackages.sh @@ -0,0 +1,124 @@ +#!/usr/bin/env bash +env + +while true ; do + case "$1" in + -c|--clear-cache) CLEAR_CACHE=1 ; shift ;; + --) shift ; break ;; + *) shift ; break ;; + esac +done + +RESULTCODE=0 + +# move up to the repo root +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR=$SCRIPTDIR/../../ +pushd $DIR + +mono --version + +# Download the CLI install script to cli +echo "Installing dotnet CLI" +mkdir -p cli +# Issue 8936 - DISABLED TEMPORARILY curl -o cli/dotnet-install.sh -L https://dot.net/v1/dotnet-install.sh + +# Run install.sh +# Issue 8936 chmod +x cli/dotnet-install.sh +chmod +x scripts/funcTests/dotnet-install.sh + +# Get recommended version for bootstrapping testing version +# Issue 8936 - DISABLED TEMPORARILY cli/dotnet-install.sh -i cli -c 2.2 +scripts/funcTests/dotnet-install.sh -i cli -c 2.2 -NoPath +# cli/dotnet-install.sh -runtime dotnet -Channel 2.2 -i cli -NoPath + +DOTNET="$(pwd)/cli/dotnet" + +echo "dotnet msbuild build/config.props /v:m /nologo /t:GetCliBranchForTesting" + +# run it twice so dotnet cli can expand and decompress without affecting the result of the target +dotnet msbuild build/config.props /v:m /nologo /t:GetCliBranchForTesting +DOTNET_BRANCHES="$(dotnet msbuild build/config.props /v:m /nologo /t:GetCliBranchForTesting)" +echo $DOTNET_BRANCHES | tr ";" "\n" | while read -r DOTNET_BRANCH +do + echo $DOTNET_BRANCH + ChannelAndVersion=($DOTNET_BRANCH) + Channel=${ChannelAndVersion[0]} + if [ ${#ChannelAndVersion[@]} -eq 1 ] + then + Version="latest" + else + Version=${ChannelAndVersion[1]} + fi + echo "Channel is: $Channel" + echo "Version is: $Version" + scripts/funcTests/dotnet-install.sh -i cli -c $Channel -v $Version -nopath + + # Display current version + $DOTNET --version + dotnet --info +done +echo "=================" + +# install SDK2 runtime as we encounter problems on running dotnet vstest command when only download SDK3. +cli/dotnet-install.sh -runtime dotnet -Channel 2.2 -i cli -NoPath + +echo "Deleting .NET Core temporary files" +rm -rf "/tmp/"dotnet.* + +echo "=================" + +#restore solution packages +$DOTNET msbuild -t:restore "$DIR/build/bootstrap.proj" +if [ $? -ne 0 ]; then + echo "Restore failed!!" + exit 1 +fi + +# init the repo + +git submodule init +git submodule update + +# clear caches +if [ "$CLEAR_CACHE" == "1" ] +then + # echo "Clearing the nuget web cache folder" + # rm -r -f ~/.local/share/NuGet/* + + echo "Clearing the nuget packages folder" + rm -r -f ~/.nuget/packages/* +fi + +# restore packages +echo "dotnet msbuild build/build.proj /t:RestoreCrossVerifyTest /p:VisualStudioVersion=16.0 /p:Configuration=Release /p:BuildNumber=1 /p:ReleaseLabel=beta" +dotnet msbuild build/build.proj /t:RestoreCrossVerifyTest /p:VisualStudioVersion=16.0 /p:Configuration=Release /p:BuildNumber=1 /p:ReleaseLabel=beta +if [ $? -ne 0 ]; then + echo "Restore failed!!" + exit 1 +fi + +# Generate signed packages tests +echo "dotnet msbuild build/build.proj /t:CrossVerifyGeneratePackageTests /p:VisualStudioVersion=16.0 /p:Configuration=Release /p:BuildNumber=1 /p:ReleaseLabel=beta" +dotnet msbuild build/build.proj /t:CrossVerifyGeneratePackageTests /p:VisualStudioVersion=16.0 /p:Configuration=Release /p:BuildNumber=1 /p:ReleaseLabel=beta + +if [ $? -ne 0 ]; then + echo "CoreUnitTests failed!!" + RESULTCODE=1 +fi + +RESULTFILE="build/TestResults/TestResults.xml" + +echo "Checking if result file exists at $DIR$RESULTFILE" +if [ -f "$DIR$RESULTFILE" ] +then + echo "Renaming $DIR$RESULTFILE" + mv "$RESULTFILE" "$DIR/build/TestResults/TestResults.$(date +%H%M%S).xml" +else + echo "$DIR$RESULTFILE not found." +fi + +if [ -z "$CI" ]; then + popd + exit $RESULTCODE +fi diff --git a/scripts/funcTests/runVerifySignedPackages.sh b/scripts/funcTests/runVerifySignedPackages.sh new file mode 100644 index 00000000000..e4ca20d8de8 --- /dev/null +++ b/scripts/funcTests/runVerifySignedPackages.sh @@ -0,0 +1,124 @@ +#!/usr/bin/env bash +env + +while true ; do + case "$1" in + -c|--clear-cache) CLEAR_CACHE=1 ; shift ;; + --) shift ; break ;; + *) shift ; break ;; + esac +done + +RESULTCODE=0 + +# move up to the repo root +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +DIR=$SCRIPTDIR/../../ +pushd $DIR + +mono --version + +# Download the CLI install script to cli +echo "Installing dotnet CLI" +mkdir -p cli +# Issue 8936 - DISABLED TEMPORARILY curl -o cli/dotnet-install.sh -L https://dot.net/v1/dotnet-install.sh + +# Run install.sh +# Issue 8936 chmod +x cli/dotnet-install.sh +chmod +x scripts/funcTests/dotnet-install.sh + +# Get recommended version for bootstrapping testing version +# Issue 8936 - DISABLED TEMPORARILY cli/dotnet-install.sh -i cli -c 2.2 +scripts/funcTests/dotnet-install.sh -i cli -c 2.2 -NoPath +# cli/dotnet-install.sh -runtime dotnet -Channel 2.2 -i cli -NoPath + +DOTNET="$(pwd)/cli/dotnet" + +echo "dotnet msbuild build/config.props /v:m /nologo /t:GetCliBranchForTesting" + +# run it twice so dotnet cli can expand and decompress without affecting the result of the target +dotnet msbuild build/config.props /v:m /nologo /t:GetCliBranchForTesting +DOTNET_BRANCHES="$(dotnet msbuild build/config.props /v:m /nologo /t:GetCliBranchForTesting)" +echo $DOTNET_BRANCHES | tr ";" "\n" | while read -r DOTNET_BRANCH +do + echo $DOTNET_BRANCH + ChannelAndVersion=($DOTNET_BRANCH) + Channel=${ChannelAndVersion[0]} + if [ ${#ChannelAndVersion[@]} -eq 1 ] + then + Version="latest" + else + Version=${ChannelAndVersion[1]} + fi + echo "Channel is: $Channel" + echo "Version is: $Version" + scripts/funcTests/dotnet-install.sh -i cli -c $Channel -v $Version -nopath + + # Display current version + $DOTNET --version + dotnet --info +done +echo "=================" + +# install SDK2 runtime as we encounter problems on running dotnet vstest command when only download SDK3. +cli/dotnet-install.sh -runtime dotnet -Channel 2.2 -i cli -NoPath + +echo "Deleting .NET Core temporary files" +rm -rf "/tmp/"dotnet.* + +echo "=================" + +#restore solution packages +$DOTNET msbuild -t:restore "$DIR/build/bootstrap.proj" +if [ $? -ne 0 ]; then + echo "Restore failed!!" + exit 1 +fi + +# init the repo + +git submodule init +git submodule update + +# clear caches +if [ "$CLEAR_CACHE" == "1" ] +then + # echo "Clearing the nuget web cache folder" + # rm -r -f ~/.local/share/NuGet/* + + echo "Clearing the nuget packages folder" + rm -r -f ~/.nuget/packages/* +fi + +# restore packages +echo "dotnet msbuild build/build.proj /t:RestoreCrossVerifyTest /p:VisualStudioVersion=16.0 /p:Configuration=Release /p:BuildNumber=1 /p:ReleaseLabel=beta" +dotnet msbuild build/build.proj /t:RestoreCrossVerifyTest /p:VisualStudioVersion=16.0 /p:Configuration=Release /p:BuildNumber=1 /p:ReleaseLabel=beta +if [ $? -ne 0 ]; then + echo "Restore failed!!" + exit 1 +fi + +# Generate signed packages tests +echo "dotnet msbuild build/build.proj /t:CrossVerifyVerifyPackageTests /p:VisualStudioVersion=16.0 /p:Configuration=Release /p:BuildNumber=1 /p:ReleaseLabel=beta" +dotnet msbuild build/build.proj /t:CrossVerifyVerifyPackageTests /p:VisualStudioVersion=16.0 /p:Configuration=Release /p:BuildNumber=1 /p:ReleaseLabel=beta + +if [ $? -ne 0 ]; then + echo "CoreUnitTests failed!!" + RESULTCODE=1 +fi + +RESULTFILE="build/TestResults/TestResults.xml" + +echo "Checking if result file exists at $DIR$RESULTFILE" +if [ -f "$DIR$RESULTFILE" ] +then + echo "Renaming $DIR$RESULTFILE" + mv "$RESULTFILE" "$DIR/build/TestResults/TestResults.$(date +%H%M%S).xml" +else + echo "$DIR$RESULTFILE not found." +fi + +if [ -z "$CI" ]; then + popd + exit $RESULTCODE +fi diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/CrossVerifyCollection.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/CrossVerifyCollection.cs new file mode 100644 index 00000000000..5af11693d6e --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/CrossVerifyCollection.cs @@ -0,0 +1,14 @@ +using Xunit; + +namespace NuGet.Packaging.CrossVerify.Generate.Test +{ + [CollectionDefinition(Name)] + public class CrossVerifyCollection : ICollectionFixture + { + public const string Name = "Cross Verify Test Collection"; + + // This class has no code, and is never created. Its purpose is simply + // to be the place to apply [CollectionDefinition] and all the + // ICollectionFixture<> interfaces. + } +} diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/GenerateFixture.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/GenerateFixture.cs new file mode 100644 index 00000000000..e60f4034add --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/GenerateFixture.cs @@ -0,0 +1,56 @@ +using System.IO; +using NuGet.Common; +using NuGet.Test.Utility; + +namespace NuGet.Packaging.CrossVerify.Generate.Test +{ + public class GenerateFixture + { + private const string PreGeneratePackageFolderName = "PreGenPackages"; + + public string _dir; + + public GenerateFixture() + { + _dir = CreatePreGenPackageForEachPlatform(); + } + private static string CreatePreGenPackageForEachPlatform() + { + var root = TestFileSystemUtility.NuGetTestFolder; + var path = Path.Combine(root, PreGeneratePackageFolderName); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + + //Create a folder for a each platform, under PreGenPackages folder. + //For functional test on windows, 2 folders will be created. + var platform = ""; +#if IS_DESKTOP + platform = "Windows_NetFulFramework"; +#else + if (RuntimeEnvironmentHelper.IsWindows) + { + platform = "Windows_NetCore"; + } + else if (RuntimeEnvironmentHelper.IsMacOSX) + { + platform = "Mac_NetCore"; + } + else + { + platform = "Linux_NetCore"; + } +#endif + var pathForEachPlatform = Path.Combine(path, platform); + + if (Directory.Exists(pathForEachPlatform)) + { + Directory.Delete(pathForEachPlatform, recursive: true); + } + Directory.CreateDirectory(pathForEachPlatform); + + return pathForEachPlatform; + } + } +} diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/GenerateSignedPackages.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/GenerateSignedPackages.cs new file mode 100644 index 00000000000..dd6709ea154 --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/GenerateSignedPackages.cs @@ -0,0 +1,368 @@ +#if IS_SIGNING_SUPPORTED +using System; +using System.IO; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; +using NuGet.Packaging.FuncTest; +using NuGet.Test.Utility; +using Test.Utility.Signing; +using Xunit; +namespace NuGet.Packaging.CrossVerify.Generate.Test +{ + [Collection(CrossVerifyCollection.Name)] + public class GenerateSignedPackages + { + private readonly GenerateFixture _generateFixture; + private string _dir; + + private readonly SigningTestFixture _signingTestFixture_Author; + private readonly TrustedTestCert _authorSignningCert; + private readonly X509Certificate2 _authorTSARootCert; + + private readonly SigningTestFixture _signingTestFixture_Repository; + private readonly TrustedTestCert _repoSignningCert; + private readonly X509Certificate2 _repoTSARootCert; + + public GenerateSignedPackages(GenerateFixture fixture) + { + _generateFixture = fixture; + _dir = _generateFixture._dir; + + _signingTestFixture_Author = new SigningTestFixture(); + _authorSignningCert = _signingTestFixture_Author.TrustedTestCertificate; + _authorTSARootCert = _signingTestFixture_Author.TrustedServerRootCertificate; + + _signingTestFixture_Repository = new SigningTestFixture(); + _repoSignningCert = _signingTestFixture_Repository.TrustedRepositoryCertificate; + _repoTSARootCert = _signingTestFixture_Repository.TrustedServerRootCertificate; + } + [Fact] + public async Task PreGenerateSignedPackages_AuthorSigned() + { +            // Arrange + var caseName = "A"; + string caseFolder = System.IO.Path.Combine(_dir, caseName); + Directory.CreateDirectory(caseFolder); + + var nupkg = new SimpleTestPackageContext(); + + using (var primaryCertificate = new X509Certificate2(_authorSignningCert.Source.Cert)) + { + //Creat signed package under _dir\package folder + string packagePath = Path.Combine(caseFolder, "package"); + Directory.CreateDirectory(packagePath); + + var signedPackagePath = await SignedArchiveTestUtility.AuthorSignPackageAsync( + primaryCertificate, + nupkg, + packagePath); + + //Creat certificate under _dir\cert folder + string certFolder = System.IO.Path.Combine(caseFolder, "cert"); + Directory.CreateDirectory(certFolder); + + var CertFile = new FileInfo(Path.Combine(certFolder, "Author.cer")); + var bytes = primaryCertificate.RawData; + File.WriteAllBytes(CertFile.FullName, bytes); + } + } + + [Fact] + public async Task PreGenerateSignedPackages_AuthorSigned_TimeStamped() + { +            // Arrange + var caseName = "AT"; + string caseFolder = System.IO.Path.Combine(_dir, caseName); + Directory.CreateDirectory(caseFolder); + + var nupkg = new SimpleTestPackageContext(); + + var timestampService = await _signingTestFixture_Author.GetDefaultTrustedTimestampServiceAsync(); + + using (var primaryCertificate = new X509Certificate2(_authorSignningCert.Source.Cert)) + { + string packagePath = Path.Combine(caseFolder, "package"); + Directory.CreateDirectory(packagePath); + + var signedPackagePath = await SignedArchiveTestUtility.AuthorSignPackageAsync( + primaryCertificate, + nupkg, + packagePath, + timestampService.Url); + + string certFolder = System.IO.Path.Combine(caseFolder, "cert"); + Directory.CreateDirectory(certFolder); + + var CertFile = new FileInfo(Path.Combine(certFolder, "Author.cer")); + var certbytes = primaryCertificate.RawData; + File.WriteAllBytes(CertFile.FullName, certbytes); + + var tsaRootCertPath = new FileInfo(Path.Combine(certFolder, "AuthorTSARoot.cer")); + var tsaRootCertbytes = _authorTSARootCert.RawData; + File.WriteAllBytes(tsaRootCertPath.FullName, tsaRootCertbytes); + } + } + + [Fact] + public async Task PreGenerateSignedPackages_RepositorySigned() + { +            // Arrange + var caseName = "R"; + string caseFolder = System.IO.Path.Combine(_dir, caseName); + Directory.CreateDirectory(caseFolder); + + var nupkg = new SimpleTestPackageContext(); + + using (var primaryCertificate = new X509Certificate2(_repoSignningCert.Source.Cert)) + { + string packagePath = Path.Combine(caseFolder, "package"); + Directory.CreateDirectory(packagePath); + + var signedPackagePath = await SignedArchiveTestUtility.RepositorySignPackageAsync( + primaryCertificate, + nupkg, + packagePath, + new Uri("https://v3serviceIndex.test/api/index.json")); + + string certFolder = System.IO.Path.Combine(caseFolder, "cert"); + Directory.CreateDirectory(certFolder); + + var CertFile = new FileInfo(Path.Combine(certFolder, "Repo.cer")); + var bytes = primaryCertificate.RawData; + File.WriteAllBytes(CertFile.FullName, bytes); + } + } + + [Fact] + public async Task PreGenerateSignedPackages_RepositorySigned_TimeStamped() + { +            // Arrange + var caseName = "RT"; + string caseFolder = System.IO.Path.Combine(_dir, caseName); + Directory.CreateDirectory(caseFolder); + + var nupkg = new SimpleTestPackageContext(); + + var timestampService = await _signingTestFixture_Repository.GetDefaultTrustedTimestampServiceAsync(); + + using (var testCertificate = new X509Certificate2(_repoSignningCert.Source.Cert)) + { + string packagePath = Path.Combine(caseFolder, "package"); + Directory.CreateDirectory(packagePath); + + var signedPackagePath = await SignedArchiveTestUtility.RepositorySignPackageAsync( + testCertificate, + nupkg, + packagePath, + new Uri("https://v3serviceIndex.test/api/index.json"), + timestampService.Url); + + string certFolder = System.IO.Path.Combine(caseFolder, "cert"); + Directory.CreateDirectory(certFolder); + + var CertFile = new FileInfo(Path.Combine(certFolder, "Repo.cer")); + var bytes = testCertificate.RawData; + File.WriteAllBytes(CertFile.FullName, bytes); + + var tsaRootCertPath = new FileInfo(Path.Combine(certFolder, "RepoTSARoot.cer")); + var tsaRootCertbytes = _repoTSARootCert.RawData; + File.WriteAllBytes(tsaRootCertPath.FullName, tsaRootCertbytes); + + } + } + + [Fact] + public async Task PreGenerateSignedPackages_AuthorSigned_RepositoryCounterSigned() + { +            // Arrange + var caseName = "AR"; + string caseFolder = System.IO.Path.Combine(_dir, caseName); + Directory.CreateDirectory(caseFolder); + + var nupkg = new SimpleTestPackageContext(); + + using (var primaryCertificate = new X509Certificate2(_authorSignningCert.Source.Cert)) + using (var counterCertificate = new X509Certificate2(_repoSignningCert.Source.Cert)) + { + string packagePath = Path.Combine(caseFolder, "package"); + Directory.CreateDirectory(packagePath); + + var signedPackagePath = await SignedArchiveTestUtility.AuthorSignPackageAsync( + primaryCertificate, + nupkg, + packagePath); + + var countersignedPackagePath = await SignedArchiveTestUtility.RepositorySignPackageAsync( + counterCertificate, signedPackagePath, + packagePath, + new Uri("https://v3serviceIndex.test/api/index.json")); + + + string certFolder = System.IO.Path.Combine(caseFolder, "cert"); + Directory.CreateDirectory(certFolder); + + var CertFile1 = new FileInfo(Path.Combine(certFolder, "Author.cer")); + var bytes1 = primaryCertificate.RawData; + File.WriteAllBytes(CertFile1.FullName, bytes1); + + var CertFile2 = new FileInfo(Path.Combine(certFolder, "Repo.cer")); + var bytes2 = counterCertificate.RawData; + File.WriteAllBytes(CertFile2.FullName, bytes2); + } + } + + + [Fact] + public async Task PreGenerateSignedPackages_AuthorSigned_Timestamped_RepositoryCounterSigned() + { + // Arrange + var caseName = "ATR"; + string caseFolder = System.IO.Path.Combine(_dir, caseName); + Directory.CreateDirectory(caseFolder); + + var nupkg = new SimpleTestPackageContext(); + + var timestampServicePrimary = await _signingTestFixture_Author.GetDefaultTrustedTimestampServiceAsync(); + + using (var primaryCertificate = new X509Certificate2(_authorSignningCert.Source.Cert)) + using (var counterCertificate = new X509Certificate2(_repoSignningCert.Source.Cert)) + { + string packagePath = Path.Combine(caseFolder, "package"); + Directory.CreateDirectory(packagePath); + + var signedPackagePath = await SignedArchiveTestUtility.AuthorSignPackageAsync( + primaryCertificate, + nupkg, + packagePath, + timestampServicePrimary.Url); + + var countersignedPackagePath = await SignedArchiveTestUtility.RepositorySignPackageAsync( + counterCertificate, + signedPackagePath, + packagePath, + new Uri("https://v3serviceIndex.test/api/index.json")); + + + string certFolder = System.IO.Path.Combine(caseFolder, "cert"); + Directory.CreateDirectory(certFolder); + + var CertFile1 = new FileInfo(Path.Combine(certFolder, "Author.cer")); + var bytes1 = primaryCertificate.RawData; + File.WriteAllBytes(CertFile1.FullName, bytes1); + + var CertFile2 = new FileInfo(Path.Combine(certFolder, "Repo.cer")); + var bytes2 = counterCertificate.RawData; + File.WriteAllBytes(CertFile2.FullName, bytes2); + + var tsaRootCertPath = new FileInfo(Path.Combine(certFolder, "AuthorTSARoot.cer")); + var tsaRootCertbytes = _authorTSARootCert.RawData; + File.WriteAllBytes(tsaRootCertPath.FullName, tsaRootCertbytes); + } + } + + [Fact] + public async Task PreGenerateSignedPackages_AuthorSigned_RepositoryCounterSigned_Timestamped() + { + // Arrange + var caseName = "ART"; + string caseFolder = System.IO.Path.Combine(_dir, caseName); + Directory.CreateDirectory(caseFolder); + + var nupkg = new SimpleTestPackageContext(); + + var timestampServiceCounter = await _signingTestFixture_Repository.GetDefaultTrustedTimestampServiceAsync(); + + using (var primaryCertificate = new X509Certificate2(_authorSignningCert.Source.Cert)) + using (var counterCertificate = new X509Certificate2(_repoSignningCert.Source.Cert)) + { + string packagePath = Path.Combine(caseFolder, "package"); + Directory.CreateDirectory(packagePath); + + var signedPackagePath = await SignedArchiveTestUtility.AuthorSignPackageAsync( + primaryCertificate, + nupkg, + packagePath); + + var countersignedPackagePath = await SignedArchiveTestUtility.RepositorySignPackageAsync( + counterCertificate, signedPackagePath, + packagePath, + new Uri("https://v3serviceIndex.test/api/index.json"), + timestampServiceCounter.Url); + + + string certFolder = System.IO.Path.Combine(caseFolder, "cert"); + Directory.CreateDirectory(certFolder); + + var CertFile1 = new FileInfo(Path.Combine(certFolder, "Author.cer")); + var bytes1 = primaryCertificate.RawData; + File.WriteAllBytes(CertFile1.FullName, bytes1); + + var CertFile2 = new FileInfo(Path.Combine(certFolder, "Repo.cer")); + var bytes2 = counterCertificate.RawData; + File.WriteAllBytes(CertFile2.FullName, bytes2); + + var tsaRootCertPath = new FileInfo(Path.Combine(certFolder, "RepoTSARoot.cer")); + var tsaRootCertbytes = _repoTSARootCert.RawData; + File.WriteAllBytes(tsaRootCertPath.FullName, tsaRootCertbytes); + + } + } + + [Fact] + public async Task PreGenerateSignedPackages_AuthorSigned_Timestamped_RepositoryCounterSigned_Timestamped() + { + // Arrange + var caseName = "ATRT"; + string caseFolder = System.IO.Path.Combine(_dir, caseName); + Directory.CreateDirectory(caseFolder); + + var nupkg = new SimpleTestPackageContext(); + + var timestampServicePrimary = await _signingTestFixture_Author.GetDefaultTrustedTimestampServiceAsync(); + var timestampServiceCounter = await _signingTestFixture_Repository.GetDefaultTrustedTimestampServiceAsync(); + + using (var primaryCertificate = new X509Certificate2(_authorSignningCert.Source.Cert)) + using (var counterCertificate = new X509Certificate2(_repoSignningCert.Source.Cert)) + { + string packagePath = Path.Combine(caseFolder, "package"); + Directory.CreateDirectory(packagePath); + + var signedPackagePath = await SignedArchiveTestUtility.AuthorSignPackageAsync( + primaryCertificate, + nupkg, + packagePath, + timestampServicePrimary.Url); + + var countersignedPackagePath = await SignedArchiveTestUtility.RepositorySignPackageAsync( + counterCertificate, signedPackagePath, + packagePath, + new Uri("https://v3serviceIndex.test/api/index.json"), + timestampServiceCounter.Url); + + + string certFolder = System.IO.Path.Combine(caseFolder, "cert"); + Directory.CreateDirectory(certFolder); + + var CertFile1 = new FileInfo(Path.Combine(certFolder, "Author.cer")); + var bytes1 = primaryCertificate.RawData; + File.WriteAllBytes(CertFile1.FullName, bytes1); + + var CertFile2 = new FileInfo(Path.Combine(certFolder, "Repo.cer")); + var bytes2 = counterCertificate.RawData; + File.WriteAllBytes(CertFile2.FullName, bytes2); + + var authorTsaRootCertPath = new FileInfo(Path.Combine(certFolder, "AuthorTSARoot.cer")); + var authorTsaRootCertbytes = _authorTSARootCert.RawData; + File.WriteAllBytes(authorTsaRootCertPath.FullName, authorTsaRootCertbytes); + + var repoTsaRootCertPath = new FileInfo(Path.Combine(certFolder, "RepoTSARoot.cer")); + var repoTsaRootCertbytes = _repoTSARootCert.RawData; + File.WriteAllBytes(repoTsaRootCertPath.FullName, repoTsaRootCertbytes); + + } + } + } +} +#endif + + diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/NuGet.Packaging.CrossVerify.Generate.Test.csproj b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/NuGet.Packaging.CrossVerify.Generate.Test.csproj new file mode 100644 index 00000000000..0c09c7b6378 --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/NuGet.Packaging.CrossVerify.Generate.Test.csproj @@ -0,0 +1,55 @@ + + + true + true + + + + + + + $(TargetFrameworksExe) + $(NETCoreTargetFrameworks) + true + true + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + + + + + + + + + + + + diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/global.json b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/global.json new file mode 100644 index 00000000000..a32d2892027 --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "5.0.100-alpha1" + } +} \ No newline at end of file diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/xunit.runner.json b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/xunit.runner.json new file mode 100644 index 00000000000..4c62fd7c26c --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Generate.Test/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "maxParallelThreads": 1, + "parallelizeTestCollections": false +} \ No newline at end of file diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/NuGet.Packaging.CrossVerify.Verify.Test.csproj b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/NuGet.Packaging.CrossVerify.Verify.Test.csproj new file mode 100644 index 00000000000..0c09c7b6378 --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/NuGet.Packaging.CrossVerify.Verify.Test.csproj @@ -0,0 +1,55 @@ + + + true + true + + + + + + + $(TargetFrameworksExe) + $(NETCoreTargetFrameworks) + true + true + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + + + + + + + + + + + + diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/VerifySignedPackages.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/VerifySignedPackages.cs new file mode 100644 index 00000000000..f6a56e979ea --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/VerifySignedPackages.cs @@ -0,0 +1,459 @@ +#if IS_SIGNING_SUPPORTED +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Threading; +using System.Threading.Tasks; +using FluentAssertions; +using NuGet.Common; +using NuGet.Packaging.FuncTest; +using NuGet.Packaging.Signing; +using NuGet.Test.Utility; +using Xunit; + +namespace NuGet.Packaging.CrossVerify.Verify.Test +{ + [Collection(SigningTestCollection.Name)] + public class VerifySignedPackages + { + private readonly IList _trustProviders; + private string _dir; + + public VerifySignedPackages() + { + _trustProviders = new List() + { + new IntegrityVerificationProvider(), + new SignatureTrustAndValidityVerificationProvider() + }; + _dir = GetPreGenPackageRootPath(); + } + + [Theory] + [MemberData(nameof(FolderForEachPlatform))] + public async Task VerifySignaturesAsync_PreGenerateSignedPackages_AuthorSigned(string dir) + { + // Arrange + var caseName = "A"; + + var settings = SignedPackageVerifierSettings.GetVerifyCommandDefaultPolicy(); + + var signedPackageFolder = Path.Combine(dir, caseName, "package"); + var signedPackagePath = Directory.GetFiles(signedPackageFolder).Where(f => f.EndsWith(".nupkg")).First(); + + var certFolder = Path.Combine(dir, caseName, "cert"); + var authorCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Author.cer")).First(); + + using (var primaryCertificate = new X509Certificate2(File.ReadAllBytes(authorCertFile))) + using (var packageReader = new PackageArchiveReader(signedPackagePath)) + using (var store = new X509Store(StoreName.Root, + RuntimeEnvironmentHelper.IsWindows ? StoreLocation.LocalMachine : StoreLocation.CurrentUser)) + { + AddCertificateToStore(primaryCertificate, store); + + var verifier = new PackageSignatureVerifier(_trustProviders); + // Act + var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); + var resultsWithErrors = result.Results.Where(r => r.GetErrorIssues().Any()); + var resultsWithWarnings = result.Results.Where(r => r.GetWarningIssues().Any()); + + // Assert + try + { + result.IsValid.Should().BeTrue(); + resultsWithErrors.Count().Should().Be(0); + resultsWithWarnings.Count().Should().Be(0); + } + catch (Exception e) + { + throw new Exception(e.Message + GetResultIssues(result, dir)); + } + } + } + + [Theory] + [MemberData(nameof(FolderForEachPlatform))] + public async Task VerifySignaturesAsync_PreGenerateSignedPackages_AuthorSigned_TimeStamped(string dir) + { + // Arrange + var caseName = "AT"; + + var settings = SignedPackageVerifierSettings.GetVerifyCommandDefaultPolicy(); + + var signedPackageFolder = Path.Combine(dir, caseName, "package"); + var signedPackagePath = Directory.GetFiles(signedPackageFolder).Where(f => f.EndsWith(".nupkg")).First(); + + var certFolder = Path.Combine(dir, caseName, "cert"); + var authorCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Author.cer")).First(); + var authorTsaRootCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("AuthorTSARoot.cer")).First(); + + using (var primaryCertificate = new X509Certificate2(File.ReadAllBytes(authorCertFile))) + using (var tsaRootCertificate = new X509Certificate2(File.ReadAllBytes(authorTsaRootCertFile))) + using (var packageReader = new PackageArchiveReader(signedPackagePath)) + using (var store = new X509Store(StoreName.Root, + RuntimeEnvironmentHelper.IsWindows ? StoreLocation.LocalMachine : StoreLocation.CurrentUser)) + { + AddCertificateToStore(primaryCertificate, store); + AddCertificateToStore(tsaRootCertificate, store); + + var verifier = new PackageSignatureVerifier(_trustProviders); + // Act + var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); + var resultsWithErrors = result.Results.Where(r => r.GetErrorIssues().Any()); + var resultsWithWarnings = result.Results.Where(r => r.GetWarningIssues().Any()); + + // Assert + try + { + result.IsValid.Should().BeTrue(); + resultsWithErrors.Count().Should().Be(0); + resultsWithWarnings.Count().Should().Be(0); + } + catch (Exception e) + { + throw new Exception(e.Message + GetResultIssues(result, dir)); + } + } + } + + [Theory] + [MemberData(nameof(FolderForEachPlatform))] + public async Task VerifySignaturesAsync_PreGenerateSignedPackages_RepositorySigned(string dir) + { + // Arrange + var caseName = "R"; + + var settings = SignedPackageVerifierSettings.GetVerifyCommandDefaultPolicy(); + + var signedPackageFolder = Path.Combine(dir, caseName, "package"); + var signedPackagePath = Directory.GetFiles(signedPackageFolder).Where(f => f.EndsWith(".nupkg")).First(); + + var certFolder = Path.Combine(dir, caseName, "cert"); + var repoCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Repo.cer")).First(); + + using (var primaryCertificate = new X509Certificate2(File.ReadAllBytes(repoCertFile))) + using (var packageReader = new PackageArchiveReader(signedPackagePath)) + using (var store = new X509Store(StoreName.Root, + RuntimeEnvironmentHelper.IsWindows ? StoreLocation.LocalMachine : StoreLocation.CurrentUser)) + { + AddCertificateToStore(primaryCertificate, store); + + var verifier = new PackageSignatureVerifier(_trustProviders); + // Act + var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); + var resultsWithErrors = result.Results.Where(r => r.GetErrorIssues().Any()); + var resultsWithWarnings = result.Results.Where(r => r.GetWarningIssues().Any()); + + // Assert + try + { + result.IsValid.Should().BeTrue(); + resultsWithErrors.Count().Should().Be(0); + resultsWithWarnings.Count().Should().Be(0); + } + catch (Exception e) + { + throw new Exception(e.Message + GetResultIssues(result, dir)); + } + } + } + + [Theory] + [MemberData(nameof(FolderForEachPlatform))] + public async Task VerifySignaturesAsync_PreGenerateSignedPackages_RepositorySigned_Timestamped(string dir) + { + // Arrange + var caseName = "RT"; + + var settings = SignedPackageVerifierSettings.GetVerifyCommandDefaultPolicy(); + + var signedPackageFolder = Path.Combine(dir, caseName, "package"); + var signedPackagePath = Directory.GetFiles(signedPackageFolder).Where(f => f.EndsWith(".nupkg")).First(); + + var certFolder = Path.Combine(dir, caseName, "cert"); + var repoCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Repo.cer")).First(); + var repoTsaRootCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("RepoTSARoot.cer")).First(); + + using (var primaryCertificate = new X509Certificate2(File.ReadAllBytes(repoCertFile))) + using (var tsaRootCertificate = new X509Certificate2(File.ReadAllBytes(repoTsaRootCertFile))) + using (var packageReader = new PackageArchiveReader(signedPackagePath)) + using (var store = new X509Store(StoreName.Root, + RuntimeEnvironmentHelper.IsWindows ? StoreLocation.LocalMachine : StoreLocation.CurrentUser)) + { + AddCertificateToStore(primaryCertificate, store); + AddCertificateToStore(tsaRootCertificate, store); + + var verifier = new PackageSignatureVerifier(_trustProviders); + // Act + var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); + var resultsWithErrors = result.Results.Where(r => r.GetErrorIssues().Any()); + var resultsWithWarnings = result.Results.Where(r => r.GetWarningIssues().Any()); + + // Assert + try + { + result.IsValid.Should().BeTrue(); + resultsWithErrors.Count().Should().Be(0); + resultsWithWarnings.Count().Should().Be(0); + } + catch (Exception e) + { + throw new Exception(e.Message + GetResultIssues(result, dir)); + } + } + } + + [Theory] + [MemberData(nameof(FolderForEachPlatform))] + public async Task VerifySignaturesAsync_PreGenerateSignedPackages_AuthorSigned_RepositorySigned(string dir) + { + // Arrange + var caseName = "AR"; + + var settings = SignedPackageVerifierSettings.GetVerifyCommandDefaultPolicy(); + + var signedPackageFolder = Path.Combine(dir, caseName, "package"); + var signedPackagePath = Directory.GetFiles(signedPackageFolder).Where(f => f.EndsWith(".nupkg")).First(); + + var certFolder = Path.Combine(dir, caseName, "cert"); + var authorCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Author.cer")).First(); + var repoCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Repo.cer")).First(); + + using (var primaryCertificate = new X509Certificate2(File.ReadAllBytes(authorCertFile))) + using (var counterCertificate = new X509Certificate2(File.ReadAllBytes(repoCertFile))) + using (var packageReader = new PackageArchiveReader(signedPackagePath)) + using (var store = new X509Store(StoreName.Root, + RuntimeEnvironmentHelper.IsWindows ? StoreLocation.LocalMachine : StoreLocation.CurrentUser)) + { + AddCertificateToStore(primaryCertificate, store); + AddCertificateToStore(counterCertificate, store); + + var verifier = new PackageSignatureVerifier(_trustProviders); + // Act + var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); + var resultsWithErrors = result.Results.Where(r => r.GetErrorIssues().Any()); + var resultsWithWarnings = result.Results.Where(r => r.GetWarningIssues().Any()); + + // Assert + try + { + result.IsValid.Should().BeTrue(); + resultsWithErrors.Count().Should().Be(0); + resultsWithWarnings.Count().Should().Be(0); + } + catch (Exception e) + { + throw new Exception(e.Message + GetResultIssues(result, dir)); + } + } + } + + [Theory] + [MemberData(nameof(FolderForEachPlatform))] + public async Task VerifySignaturesAsync_PreGenerateSignedPackages_AuthorSigned_Timestamped_RepositorySigned(string dir) + { + // Arrange + var caseName = "ATR"; + + var settings = SignedPackageVerifierSettings.GetVerifyCommandDefaultPolicy(); + + var signedPackageFolder = Path.Combine(dir, caseName, "package"); + var signedPackagePath = Directory.GetFiles(signedPackageFolder).Where(f => f.EndsWith(".nupkg")).First(); + + var certFolder = Path.Combine(dir, caseName, "cert"); + var authorCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Author.cer")).First(); + var authorTsaRootCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("AuthorTSARoot.cer")).First(); + var repoCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Repo.cer")).First(); + + using (var primaryCertificate = new X509Certificate2(File.ReadAllBytes(authorCertFile))) + using (var counterCertificate = new X509Certificate2(File.ReadAllBytes(repoCertFile))) + using (var tsaRootCertificate = new X509Certificate2(File.ReadAllBytes(authorTsaRootCertFile))) + using (var packageReader = new PackageArchiveReader(signedPackagePath)) + using (var store = new X509Store(StoreName.Root, + RuntimeEnvironmentHelper.IsWindows ? StoreLocation.LocalMachine : StoreLocation.CurrentUser)) + { + AddCertificateToStore(primaryCertificate, store); + AddCertificateToStore(counterCertificate, store); + AddCertificateToStore(tsaRootCertificate, store); + + var verifier = new PackageSignatureVerifier(_trustProviders); + // Act + var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); + var resultsWithErrors = result.Results.Where(r => r.GetErrorIssues().Any()); + var resultsWithWarnings = result.Results.Where(r => r.GetWarningIssues().Any()); + + // Assert + try + { + result.IsValid.Should().BeTrue(); + resultsWithErrors.Count().Should().Be(0); + resultsWithWarnings.Count().Should().Be(0); + } + catch (Exception e) + { + throw new Exception(e.Message + GetResultIssues(result, dir)); + } + } + } + + [Theory] + [MemberData(nameof(FolderForEachPlatform))] + public async Task VerifySignaturesAsync_PreGenerateSignedPackages_AuthorSigned_RepositorySigned_Timestamped(string dir) + { + // Arrange + var caseName = "ART"; + + var settings = SignedPackageVerifierSettings.GetVerifyCommandDefaultPolicy(); + + var signedPackageFolder = Path.Combine(dir, caseName, "package"); + var signedPackagePath = Directory.GetFiles(signedPackageFolder).Where(f => f.EndsWith(".nupkg")).First(); + + var certFolder = Path.Combine(dir, caseName, "cert"); + var authorCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Author.cer")).First(); + var repoCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Repo.cer")).First(); + var repoTsaRootCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("RepoTSARoot.cer")).First(); + + using (var primaryCertificate = new X509Certificate2(File.ReadAllBytes(authorCertFile))) + using (var counterCertificate = new X509Certificate2(File.ReadAllBytes(repoCertFile))) + using (var tsaRootCertificate = new X509Certificate2(File.ReadAllBytes(repoTsaRootCertFile))) + using (var packageReader = new PackageArchiveReader(signedPackagePath)) + using (var store = new X509Store(StoreName.Root, + RuntimeEnvironmentHelper.IsWindows ? StoreLocation.LocalMachine : StoreLocation.CurrentUser)) + { + AddCertificateToStore(primaryCertificate, store); + AddCertificateToStore(counterCertificate, store); + AddCertificateToStore(tsaRootCertificate, store); + + var verifier = new PackageSignatureVerifier(_trustProviders); + // Act + var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); + var resultsWithErrors = result.Results.Where(r => r.GetErrorIssues().Any()); + var resultsWithWarnings = result.Results.Where(r => r.GetWarningIssues().Any()); + + // Assert + try + { + result.IsValid.Should().BeTrue(); + resultsWithErrors.Count().Should().Be(0); + resultsWithWarnings.Count().Should().Be(0); + } + catch (Exception e) + { + throw new Exception(e.Message + GetResultIssues(result, dir)); + } + } + } + + [Theory] + [MemberData(nameof(FolderForEachPlatform))] + public async Task VerifySignaturesAsync_PreGenerateSignedPackages_AuthorSigned_Timestamped_RepositorySigned_Timestamped(string dir) + { + // Arrange + var caseName = "ATRT"; + + var settings = SignedPackageVerifierSettings.GetVerifyCommandDefaultPolicy(); + + var signedPackageFolder = Path.Combine(dir, caseName, "package"); + var signedPackagePath = Directory.GetFiles(signedPackageFolder).Where(f => f.EndsWith(".nupkg")).First(); + + var certFolder = Path.Combine(dir, caseName, "cert"); + var authorCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Author.cer")).First(); + var authorTsaRootCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("AuthorTSARoot.cer")).First(); + var repoCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("Repo.cer")).First(); + var repoTsaRootCertFile = Directory.GetFiles(certFolder).Where(f => f.EndsWith("RepoTSARoot.cer")).First(); + + using (var primaryCertificate = new X509Certificate2(File.ReadAllBytes(authorCertFile))) + using (var authorTsaRootCertificate = new X509Certificate2(File.ReadAllBytes(authorTsaRootCertFile))) + using (var counterCertificate = new X509Certificate2(File.ReadAllBytes(repoCertFile))) + using (var repoTsaRootCertificate = new X509Certificate2(File.ReadAllBytes(repoTsaRootCertFile))) + using (var packageReader = new PackageArchiveReader(signedPackagePath)) + using (var store = new X509Store(StoreName.Root, + RuntimeEnvironmentHelper.IsWindows ? StoreLocation.LocalMachine : StoreLocation.CurrentUser)) + { + AddCertificateToStore(primaryCertificate, store); + AddCertificateToStore(counterCertificate, store); + AddCertificateToStore(authorTsaRootCertificate, store); + AddCertificateToStore(repoTsaRootCertificate, store); + + var verifier = new PackageSignatureVerifier(_trustProviders); + // Act + var result = await verifier.VerifySignaturesAsync(packageReader, settings, CancellationToken.None); + var resultsWithErrors = result.Results.Where(r => r.GetErrorIssues().Any()); + var resultsWithWarnings = result.Results.Where(r => r.GetWarningIssues().Any()); + + // Assert + try + { + result.IsValid.Should().BeTrue(); + resultsWithErrors.Count().Should().Be(0); + resultsWithWarnings.Count().Should().Be(0); + } + catch (Exception e) + { + throw new Exception(e.Message + GetResultIssues(result, dir)); + } + } + } + + private void AddCertificateToStore(X509Certificate2 cert, X509Store store) + { + store.Open(OpenFlags.ReadWrite); + store.Add(cert); + + } + + private string GetResultIssues(VerifySignaturesResult result, string dir) + { + var sb = new System.Text.StringBuilder(); + sb.AppendLine($"verify package from : {dir}"); + int i = 0; + foreach (var rst in result.Results) + { + sb.AppendLine($"result {i}: {rst.Trust.ToString()}"); + foreach (var error in rst.Issues.Where(issue => issue.Level == LogLevel.Error)) + { + sb.AppendLine($" error : {error.Code} : {error.Message}"); + } + foreach (var warning in rst.Issues.Where(issue => issue.Level == LogLevel.Warning)) + { + sb.AppendLine($" warning : {warning.Code} : {warning.Message}"); + } + i++; + } + return sb.ToString(); + } + + private static string GetPreGenPackageRootPath() + { + var root = TestFileSystemUtility.NuGetTestFolder; + var path = System.IO.Path.Combine(root, "PreGenPackages"); + + return path; + + } + + public static TheoryData FolderForEachPlatform + { + get + { + /* should have 4 folders: + "Windows_NetFulFramework", + "Windows_NetCore", + "Mac_NetCore", + "Linux_NetCore", + */ + var folders = new TheoryData(); + foreach (var folder in Directory.GetDirectories(GetPreGenPackageRootPath())) + { + folders.Add(folder); + } + + return folders; + } + } + } +} +#endif + diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/global.json b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/global.json new file mode 100644 index 00000000000..a32d2892027 --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "5.0.100-alpha1" + } +} \ No newline at end of file diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/xunit.runner.json b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/xunit.runner.json new file mode 100644 index 00000000000..4c62fd7c26c --- /dev/null +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.CrossVerify.Verify.Test/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "maxParallelThreads": 1, + "parallelizeTestCollections": false +} \ No newline at end of file diff --git a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SigningTestFixture.cs b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SigningTestFixture.cs index dda8b45b6d6..ce400260b84 100644 --- a/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SigningTestFixture.cs +++ b/test/NuGet.Core.FuncTests/NuGet.Packaging.FuncTest/SigningTests/SigningTestFixture.cs @@ -23,6 +23,7 @@ public class SigningTestFixture : IDisposable private TrustedTestCert _trustedTestCertExpired; private TrustedTestCert _trustedTestCertNotYetValid; private TrustedTestCert _trustedServerRoot; + private X509Certificate2 _trustedServerRootCertificate; private TestCertificate _untrustedTestCert; private IReadOnlyList> _trustedTestCertificateWithReissuedCertificate; private IList _trustProviders; @@ -38,6 +39,7 @@ public SigningTestFixture() _defaultTrustedCertificateAuthority = new Lazy>(CreateDefaultTrustedCertificateAuthorityAsync); _defaultTrustedTimestampService = new Lazy>(CreateDefaultTrustedTimestampServiceAsync); _responders = new DisposableList(); + _trustedServerRootCertificate = new X509Certificate2(_defaultTrustedCertificateAuthority.Value.Result.Parent.Certificate.GetEncoded()); } public TrustedTestCert TrustedTestCertificate @@ -94,6 +96,14 @@ public TrustedTestCert TrustedTestCertificateNotYetValid } } + public X509Certificate2 TrustedServerRootCertificate + { + get + { + return _trustedServerRootCertificate; + } + } + public IReadOnlyList> TrustedTestCertificateWithReissuedCertificate { get @@ -198,6 +208,7 @@ private async Task CreateDefaultTrustedCertificateAuthorit var intermediateCa = rootCa.CreateIntermediateCertificateAuthority(); var rootCertificate = new X509Certificate2(rootCa.Certificate.GetEncoded()); StoreLocation storeLocation = CertificateStoreUtilities.GetTrustedCertificateStoreLocation(); + _trustedServerRootCertificate = rootCertificate; _trustedServerRoot = TrustedTestCert.Create( rootCertificate,