From 8b130496f5012dd71560e99e44e268dc4b7e9f21 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Sun, 18 Sep 2022 09:03:25 +0530 Subject: [PATCH 1/2] Refactor and Simplify build definition - Use 'windows-latest' image. - Narrow Test Results path pattern. - Do Restore separately from Build step. - Don't do previous steps like restore/build. - Use 'Build.Configuration' for 'Release' build. - Remove tools that are already present in the image. - Use Multi-Level lookup to use installed runtime(s). This reduces the build time by 20% approx. If .NET SDKs and NuGet packages are cached, the build time further reduces by another 20%! --- azure-pipelines.yml | 67 ++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 47dccdaf7..fdd423a81 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,45 +9,24 @@ pr: - rel/* pool: - vmImage: windows-2022 + vmImage: windows-latest + +variables: + Build.Configuration: Release jobs: - job: BuildBits + displayName: Build and Test solution timeoutInMinutes: 60 steps: - # Install the .NET Core 3.1 SDK - - task: UseDotNet@2 - displayName: Install the .NET Core 3.1 SDK - inputs: - version: 3.1.x - - # Install the .NET 6 SDK - - task: UseDotNet@2 - displayName: Install the .NET 6 SDK - inputs: - version: 6.0.x - # Install the .NET 7 SDK - task: UseDotNet@2 displayName: Install the .NET 7 SDK inputs: version: 7.0.x includePreviewVersions: true - - # Install NuGet - - task: NuGetToolInstaller@0 - displayName: Install NuGet 6.0 - inputs: - versionSpec: 6.0.0 - - # Install NerdBank GitVersioning - - task: DotNetCoreCLI@2 - displayName: Install NBGV tool - inputs: - command: custom - custom: tool - arguments: update -g nbgv + performMultiLevelLookup: true # Set Build Version - script: nbgv cloud @@ -57,42 +36,48 @@ jobs: - pwsh: build/Update-Headers.ps1 -Verify displayName: Verify headers + # Restore solution + - script: dotnet restore -p:Configuration=$(Build.Configuration) + displayName: Restore solution + # Build solution - - script: dotnet build -c Release + - script: dotnet build --no-restore -c $(Build.Configuration) displayName: Build solution - # Run .NET 6 tests - - script: dotnet test -c Release -f net6.0 -l "trx;LogFileName=VSTestResults_net6.0.trx" + # Test solution # + + # Run .NET 6 unit tests + - script: dotnet test --no-build -c $(Build.Configuration) -f net6.0 -l "trx;LogFileName=VSTestResults_net6.0.trx" displayName: Run .NET 6 unit tests - # Run .NET Core 3.1 tests - - script: dotnet test -c Release -f netcoreapp3.1 -l "trx;LogFileName=VSTestResults_netcoreapp3.1.trx" + # Run .NET Core 3.1 unit tests + - script: dotnet test --no-build -c $(Build.Configuration) -f netcoreapp3.1 -l "trx;LogFileName=VSTestResults_netcoreapp3.1.trx" displayName: Run .NET Core 3.1 unit tests - # Run .NET Framework 4.7.2 tests - - script: dotnet test -c Release -f net472 -l "trx;LogFileName=VSTestResults_net472.trx" + # Run .NET Framework 4.7.2 unit tests + - script: dotnet test --no-build -c $(Build.Configuration) -f net472 -l "trx;LogFileName=VSTestResults_net472.trx" displayName: Run .NET Framework 4.7.2 unit tests # Publish test results - task: PublishTestResults@2 displayName: Publish test results inputs: - testResultsFormat: 'VSTest' - testResultsFiles: '**/VSTestResults*.trx' + testResultsFormat: VSTest + testResultsFiles: '**/TestResults/VSTestResults*.trx' condition: always() - # Create the NuGet package(s) - - script: dotnet pack -c Release - displayName: Create NuGet package(s) + # Pack solution + - script: dotnet pack --no-build -c $(Build.Configuration) + displayName: Pack solution - # Sign package(s) + # Sign packages - pwsh: build/Sign-Package.ps1 displayName: Authenticode sign packages env: SignClientUser: $(SignClientUser) SignClientSecret: $(SignClientSecret) ArtifactDirectory: bin/nupkg - condition: and(succeeded(), not(eq(variables['Build.Reason'], 'PullRequest')), not(eq(variables['SignClientSecret'], '')), not(eq(variables['SignClientUser'], ''))) + condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'), ne(variables['SignClientUser'], ''), ne(variables['SignClientSecret'], '')) # Publish build artifacts - publish: bin/nupkg From 9b1ebda8f7fa2a4db49e301926c60dee30de1b61 Mon Sep 17 00:00:00 2001 From: Nirmal Guru Date: Sun, 18 Sep 2022 09:10:45 +0530 Subject: [PATCH 2/2] Cache .NET SDKs and Tools - Cache everything under '$(Agent.ToolsDirectory)/dotnet' directory to speed up the build. Check for changes in the .NET SDK Version to invalidate and rebuild the cache during subsequent builds. --- azure-pipelines.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index fdd423a81..039a7c914 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,6 +13,8 @@ pool: variables: Build.Configuration: Release + DotNet.Tools: $(Agent.ToolsDirectory)/dotnet + DotNet.Version: 7.0.x jobs: - job: BuildBits @@ -20,11 +22,21 @@ jobs: timeoutInMinutes: 60 steps: + # Cache .NET SDKs and Tools across pipeline runs + - task: Cache@2 + displayName: Cache .NET SDKs + inputs: + key: 'dotnet | "$(Agent.OS)" | "$(DotNet.Version)"' + restoreKeys: | + dotnet | "$(Agent.OS)" + dotnet + path: $(DotNet.Tools) + # Install the .NET 7 SDK - task: UseDotNet@2 displayName: Install the .NET 7 SDK inputs: - version: 7.0.x + version: $(DotNet.Version) includePreviewVersions: true performMultiLevelLookup: true