Skip to content

Commit 2ef0ebe

Browse files
committed
Add build caches
1 parent e6fce56 commit 2ef0ebe

19 files changed

Lines changed: 116 additions & 19 deletions

File tree

azure-pipelines.yml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pool:
2020
variables:
2121
solution: 'src\AppInstallerCLI.sln'
2222
EnableDetectorVcpkg: true
23+
EnablePipelineCache: true
24+
VCPKG_BINARY_SOURCES: "clear;nuget,https://pkgs.dev.azure.com/shine-oss/winget-cli/_packaging/WinGetDependencies/nuget/v3/index.json,readwrite"
2325

2426
# Do not set the build version for a PR build.
2527

@@ -57,7 +59,6 @@ jobs:
5759
artifactIdentifier: 'x64release'
5860

5961
variables:
60-
BuildVer: $[counter(dependencies.GetReleaseTag.outputs['GetTag.tag'], 1)]
6162
buildOutDir: $(Build.SourcesDirectory)\src\$(buildPlatform)\$(buildConfiguration)
6263
buildOutDirAnyCpu: $(Build.SourcesDirectory)\src\AnyCPU\$(buildConfiguration)
6364
artifactsDir: $(Build.ArtifactStagingDirectory)\$(buildPlatform)
@@ -67,6 +68,21 @@ jobs:
6768
- task: NuGetToolInstaller@1
6869
displayName: Install Nuget
6970

71+
- task: NuGetAuthenticate@1
72+
displayName: Authenticate to NuGet Feed
73+
74+
- task: PowerShell@2
75+
displayName: Configure vcpkg NuGet binary cache credentials
76+
inputs:
77+
targetType: inline
78+
script: |
79+
$nugetExe = (& "$(VCPKG_INSTALLATION_ROOT)\vcpkg.exe" fetch nuget) | Select-Object -Last 1
80+
$feedUrl = "https://pkgs.dev.azure.com/shine-oss/winget-cli/_packaging/WinGetDependencies/nuget/v3/index.json"
81+
& $nugetExe sources add -Name "WinGetDependencies" -Source $feedUrl -Username "AzureDevOps" -Password "$env:SYSTEM_ACCESSTOKEN" -StorePasswordInClearText
82+
& $nugetExe setapikey "AzureDevOps" -Source $feedUrl
83+
env:
84+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
85+
7086
# Restores all projects, including native (vcxproj) projects
7187
- task: NuGetCommand@2
7288
displayName: Restore Solution
@@ -104,7 +120,7 @@ jobs:
104120
condition: not(eq(variables['Build.Reason'], 'PullRequest'))
105121
inputs:
106122
filePath: 'src\binver\Update-BinVer.ps1'
107-
arguments: '-TargetFile binver\binver\version.h -BuildVersion $(BuildVer)'
123+
arguments: '-TargetFile binver\binver\version.h'
108124
workingDirectory: 'src'
109125

110126
# Build all solutions in the root directory.
@@ -114,13 +130,17 @@ jobs:
114130
platform: '$(buildPlatform)'
115131
solution: '$(solution)'
116132
configuration: '$(buildConfiguration)'
117-
msbuildArgs: '/bl:$(artifactsDir)\msbuild.binlog
133+
msbuildArgs: '/graph /reportfileaccesses
134+
/bl:$(artifactsDir)\msbuild.binlog
118135
/p:AppxBundlePlatforms="$(buildPlatform)"
119136
/p:AppxPackageDir="$(appxPackageDir)"
120137
/p:AppxBundle=Always
121138
/p:UapAppxPackageBuildMode=SideloadOnly
122-
/p:WingetCleanIntermediateFiles=true'
139+
/p:WingetCleanIntermediateFiles=false'
123140
maximumCpuCount: true
141+
msbuildArchitecture: x64
142+
env:
143+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
124144

125145
- task: MSBuild@1
126146
displayName: Build MSIX Test Installer File
@@ -672,6 +692,21 @@ jobs:
672692
- task: NuGetToolInstaller@1
673693
displayName: Install Nuget
674694

695+
- task: NuGetAuthenticate@1
696+
displayName: Authenticate to NuGet Feed
697+
698+
- task: PowerShell@2
699+
displayName: Configure vcpkg NuGet binary cache credentials
700+
inputs:
701+
targetType: inline
702+
script: |
703+
$nugetExe = (& "$(VCPKG_INSTALLATION_ROOT)\vcpkg.exe" fetch nuget) | Select-Object -Last 1
704+
$feedUrl = "https://pkgs.dev.azure.com/shine-oss/winget-cli/_packaging/WinGetDependencies/nuget/v3/index.json"
705+
& $nugetExe sources add -Name "WinGetDependencies" -Source $feedUrl -Username "AzureDevOps" -Password "$env:SYSTEM_ACCESSTOKEN" -StorePasswordInClearText
706+
& $nugetExe setapikey "AzureDevOps" -Source $feedUrl
707+
env:
708+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
709+
675710
- task: NuGetCommand@2
676711
displayName: Restore Solution
677712
inputs:
@@ -690,7 +725,7 @@ jobs:
690725
platform: '$(buildPlatform)'
691726
solution: '$(solution)'
692727
configuration: '$(buildConfiguration)'
693-
msbuildArgs: '/bl:$(artifactsDir)\msbuild.binlog'
728+
msbuildArgs: '/bl:$(artifactsDir)\msbuild.binlog /p:MSBuildCacheEnabled=false'
694729
maximumCpuCount: true
695730

696731
- task: CopyFiles@2
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<packages>
2+
<packages>
3+
<package id="Microsoft.MSBuildCache.AzurePipelines" version="0.1.328-preview" targetFramework="native" developmentDependency="true" />
34
<package id="Microsoft.Windows.CppWinRT" version="2.0.250303.1" targetFramework="native" />
45
</packages>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<packages>
2+
<packages>
3+
<package id="Microsoft.MSBuildCache.AzurePipelines" version="0.1.328-preview" targetFramework="native" developmentDependency="true" />
34
<package id="Microsoft.Windows.CppWinRT" version="2.0.250303.1" targetFramework="native" />
45
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.250325.1" targetFramework="native" />
56
</packages>

src/AppInstallerCLITests/AppInstallerCLITests.vcxproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,11 @@
11161116
<ProjectReference Include="..\Microsoft.Management.Configuration\Microsoft.Management.Configuration.vcxproj">
11171117
<Project>{ca460806-5e41-4e97-9a3d-1d74b433b663}</Project>
11181118
</ProjectReference>
1119+
<ProjectReference Include="..\AppInstallerCLIPackage\AppInstallerCLIPackage.wapproj">
1120+
<Project>{6aa3791a-0713-4548-a357-87a323e7ac3a}</Project>
1121+
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
1122+
<LinkLibraryDependencies>false</LinkLibraryDependencies>
1123+
</ProjectReference>
11191124
</ItemGroup>
11201125
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
11211126
<ImportGroup Label="ExtensionTargets">
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<packages>
2+
<packages>
3+
<package id="Microsoft.MSBuildCache.AzurePipelines" version="0.1.328-preview" targetFramework="native" developmentDependency="true" />
34
<package id="Microsoft.Windows.CppWinRT" version="2.0.250303.1" targetFramework="native" />
45
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.250325.1" targetFramework="native" />
56
</packages>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<packages>
2+
<packages>
3+
<package id="Microsoft.MSBuildCache.AzurePipelines" version="0.1.328-preview" targetFramework="native" developmentDependency="true" />
34
<package id="Microsoft.Windows.CppWinRT" version="2.0.250303.1" targetFramework="native" />
45
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.250325.1" targetFramework="native" />
56
</packages>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<packages>
2+
<packages>
3+
<package id="Microsoft.MSBuildCache.AzurePipelines" version="0.1.328-preview" targetFramework="native" developmentDependency="true" />
34
<package id="Microsoft.Windows.CppWinRT" version="2.0.250303.1" targetFramework="native" />
45
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.250325.1" targetFramework="native" />
56
</packages>

src/Directory.Build.props

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@
4545
<DefineConstants>$(WinGetMacros)$(DefineConstants)</DefineConstants>
4646
</PropertyGroup>
4747

48+
<!-- MSBuildCache for C++ projects: props must be imported first. -->
49+
<!-- The package is restored via packages.config; Directory.Build.targets imports the corresponding .targets file. -->
50+
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
51+
<MSBuildCachePackageName>Microsoft.MSBuildCache.AzurePipelines</MSBuildCachePackageName>
52+
<MSBuildCachePackageVersion>0.1.328-preview</MSBuildCachePackageVersion>
53+
<MSBuildCachePackageRoot>$(SolutionDir)\packages\$(MSBuildCachePackageName).$(MSBuildCachePackageVersion)</MSBuildCachePackageRoot>
54+
<!-- VS Application Insights writes telemetry files asynchronously after a project finishes. -->
55+
<!-- Leading \ is required: PluginSettings strips it to produce **\..., otherwise the pattern gets
56+
rooted under the repo root (D:\a\1\s) and never matches C:\Users\...\VSApplicationInsights\... -->
57+
<MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns>$(MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns);\**\VSApplicationInsights\*</MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns>
58+
</PropertyGroup>
59+
<Import Project="$(MSBuildCachePackageRoot)\build\$(MSBuildCachePackageName).props"
60+
Condition="'$(MSBuildProjectExtension)' == '.vcxproj' and Exists('$(MSBuildCachePackageRoot)\build\$(MSBuildCachePackageName).props')" />
61+
62+
<!-- MSBuildCache for C# projects: auto-imported via PackageReference (SDK-style). -->
63+
<!-- SharedCompilation handles Roslyn's VBCSCompiler.exe shared compiler daemon. -->
64+
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
65+
<MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns>$(MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns);\**\VSApplicationInsights\*</MSBuildCacheAllowFileAccessAfterProjectFinishFilePatterns>
66+
</PropertyGroup>
67+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
68+
<PackageReference Include="Microsoft.MSBuildCache.AzurePipelines" PrivateAssets="all" />
69+
<PackageReference Include="Microsoft.MSBuildCache.SharedCompilation" PrivateAssets="all" />
70+
</ItemGroup>
71+
4872
<!-- To prevent build agents from running out of disk space, clean as we go. -->
4973
<Target Name="CleanIntermediateFiles" AfterTargets="Build" Condition="'$(WingetCleanIntermediateFiles)'=='true'">
5074
<RemoveDir Directories="$(IntDir)" />

src/Directory.Build.targets

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!-- MSBuildCache for C++ projects: targets must be imported last. -->
4+
<Import Project="$(MSBuildCachePackageRoot)\build\$(MSBuildCachePackageName).targets"
5+
Condition="'$(MSBuildProjectExtension)' == '.vcxproj' and Exists('$(MSBuildCachePackageRoot)\build\$(MSBuildCachePackageName).targets')" />
6+
7+
<!-- Override vcpkg's WriteProjectTripletToFile to handle the /graph parallel build race condition.
8+
With /graph, _IsBuildingSln is false so the solution-level WriteSolutionTripletToFile never
9+
runs; all parallel projects simultaneously attempt the per-project fallback and race to create
10+
the same .solution-triplet file. ContinueOnError lets the first writer win; losing writers
11+
fail gracefully and proceed to EnsureNoTripletMismatch, which will find the already-written file. -->
12+
<Target Name="WriteProjectTripletToFile"
13+
BeforeTargets="EnsureNoTripletMismatch"
14+
Condition="!Exists('$(_TripletFile)')">
15+
<WriteLinesToFile File="$(_TripletFile)" Lines="$(VcpkgTriplet)" Overwrite="true" ContinueOnError="WarnAndContinue" />
16+
</Target>
17+
</Project>

src/Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="5.2.9" />
1414
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.6" />
1515
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
16+
<PackageVersion Include="Microsoft.MSBuildCache.AzurePipelines" Version="0.1.328-preview" />
17+
<PackageVersion Include="Microsoft.MSBuildCache.SharedCompilation" Version="0.1.328-preview" />
1618
<PackageVersion Include="Microsoft.Msix.Utils" Version="2.1.1" />
1719
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
1820
<PackageVersion Include="Microsoft.PowerShell.SDK" Version="7.4.12" />

0 commit comments

Comments
 (0)