Skip to content

Commit 0ef0c4e

Browse files
committed
Add vcpkg initialization script and use it in pipeline
1 parent 5d302e4 commit 0ef0c4e

5 files changed

Lines changed: 47 additions & 62 deletions

File tree

‎azure-pipelines.yml‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,10 @@ jobs:
7979
feedsToUse: 'config'
8080
nugetConfigPath: '$(nugetConfig)'
8181

82-
- task: CmdLine@2
83-
displayName: Enable Vcpkg Install
82+
- task: PowerShell@2
83+
displayName: Initialize Vcpkg
8484
inputs:
85-
script: |
86-
$(VCPKG_INSTALLATION_ROOT)\vcpkg.exe integrate install
87-
workingDirectory: '$(VCPKG_INSTALLATION_ROOT)'
85+
filePath: 'tools\Initialize-Vcpkg.ps1'
8886

8987
- task: VSBuild@1
9088
displayName: Build Fuzzing Artifacts
@@ -95,14 +93,6 @@ jobs:
9593
msbuildArgs: '/bl:$(artifactsDir)\msbuild.binlog'
9694
maximumCpuCount: true
9795

98-
- task: CopyFiles@2
99-
displayName: Copy vcpkg logs
100-
inputs:
101-
SourceFolder: $(VCPKG_INSTALLATION_ROOT)\buildtrees
102-
Contents: '**\*.log'
103-
TargetFolder: '$(artifactsDir)\vcpkgLogs'
104-
condition: succeededOrFailed()
105-
10696
- task: CopyFiles@2
10797
displayName: Copy Fuzzing Artifacts for Publishing
10898
inputs:

‎doc/Developing.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ For naming, formatting, error handling, casts, `std::move()` usage, and resource
3232
- For VS Community: `winget configure .config/configuration.winget`
3333
- For VS Professional: `winget configure .config/configuration.vsProfessional.winget`
3434
- For VS Enterprise: `winget configure .config/configuration.vsEnterprise.winget`
35-
3. Run `vcpkg integrate install` from the Developer Command Prompt / Developer PowerShell for VS. This is a one-time setup step until the configuration file in step 2 is updated to work with vcpkg setup.
35+
3. From PowerShell at the repository root, run [`.\tools\Initialize-Vcpkg.ps1`](../tools/Initialize-Vcpkg.ps1) to enable MSBuild integration with Visual Studio's bundled vcpkg.
36+
This replaces any existing vcpkg integration for the current user.
37+
This is a one-time setup step until the configuration file in step 2 is updated to work with vcpkg setup.
3638

3739
Open `winget-cli\src\AppInstallerCLI.sln` in Visual Studio and build. We currently only build using the solution; command-line methods of building a VS solution should work as well.
3840

‎templates/README.md‎

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,9 @@ Paths that belong to the agent or to the build output are deliberately **not** r
5353
they do not move with the subtree:
5454

5555
- `$(Build.ArtifactStagingDirectory)`, `$(Pipeline.Workspace)`
56-
- `$(Agent.TempDirectory)`, `$(VCPKG_INSTALLATION_ROOT)`
56+
- `$(Agent.TempDirectory)`
5757
- `$(buildOutDir)`, `$(buildOutDirAnyCpu)`, `$(artifactsDir)`, `$(packageLayoutDir)`
5858

59-
`$(VCPKG_INSTALLATION_ROOT)` is the exception worth calling out: it is correctly *not* rooted, but a
60-
consumer may not use the installation it points at. See `useAgentVcpkg` below.
61-
6259
Nested template references need no help. Azure Pipelines resolves a `- template:` reference inside a
6360
template file relative to *that file*, so the job templates find their siblings at any depth. Only
6461
the entry point has to know where the subtree lives.
@@ -84,9 +81,10 @@ is neither a parameter nor a path in this directory.
8481
**Pipeline variables.** None. `jobs-build.yml` sets what it needs at job scope — `solution`, so it
8582
can be rooted, and `EnableDetectorVcpkg`, so Component Governance detects the vcpkg dependencies.
8683

87-
**A Windows agent** with Visual Studio 2022 and vcpkg, exposing `VCPKG_INSTALLATION_ROOT`. The
88-
Microsoft-hosted `windows-2025` image qualifies. **The `Test` and `BuildPowerShellModule` jobs need
89-
more than the `Build` job does — see "Agent requirements" below.**
84+
**A Windows agent** with Visual Studio 2022 or newer and its vcpkg component installed. The `Build` job
85+
runs [tools\Initialize-Vcpkg.ps1](../tools/Initialize-Vcpkg.ps1) to enable user-wide MSBuild integration
86+
with Visual Studio's bundled vcpkg.
87+
**The `Test` and `BuildPowerShellModule` jobs need more than the `Build` job does — see "Agent requirements" below.**
9088

9189
**Outbound network access.** The test jobs reach several public endpoints, which is worth checking
9290
before wiring this up on a restricted network:
@@ -194,24 +192,6 @@ does not even build.
194192
/p:UseProdCLSIDs=false
195193
```
196194

197-
## `useAgentVcpkg`
198-
199-
Defaults to `true`, matching the Microsoft-hosted images, where `VCPKG_INSTALLATION_ROOT` points at
200-
a real vcpkg installation that this pipeline integrates and builds the native dependencies with.
201-
202-
Set it to `false` when the consuming repository supplies vcpkg some other way — for example through
203-
an MSBuild SDK that restores the ports itself. `VCPKG_INSTALLATION_ROOT` may well still be defined in
204-
that case, since the agent image sets it, but nothing builds there. Two steps then become
205-
meaningless and are dropped together:
206-
207-
- *Enable Vcpkg Install*, which integrates an installation the build does not use.
208-
- *Copy vcpkg logs*, which reads `$(VCPKG_INSTALLATION_ROOT)\buildtrees` — a directory that will not
209-
exist, failing the job after a successful build.
210-
211-
Dropping the log collection loses no real diagnostics: `Build Solution` writes an MSBuild binary log
212-
to `$(artifactsDir)\msbuild.binlog`, which is published with the rest of the build artifacts and
213-
records the vcpkg invocation and its output.
214-
215195
## `releaseTagJob`
216196

217197
`jobs-build.yml` stamps a build version obtained from a separate job. That job is named by the

‎templates/jobs-build.yml‎

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ parameters:
2424
- name: additionalMSBuildArgs
2525
type: string
2626
default: ''
27-
# Whether the agent's own vcpkg installation, at VCPKG_INSTALLATION_ROOT, is what builds the native
28-
# dependencies. Set to false when a consuming repository supplies vcpkg by other means, such as an
29-
# MSBuild SDK; the integrate step and the port log collection below are then both meaningless,
30-
# because that variable points at an installation this build never uses.
31-
- name: useAgentVcpkg
32-
type: boolean
33-
default: true
3427
# Agent pool for this job. Leave empty to inherit the pipeline's pool, which is what a pipeline
3528
# with a single suitable pool wants. See the "Agent requirements" section of README.md.
3629
- name: pool
@@ -126,13 +119,10 @@ jobs:
126119
feedsToUse: 'config'
127120
nugetConfigPath: '$(nugetConfig)'
128121

129-
- ${{ if parameters.useAgentVcpkg }}:
130-
- task: CmdLine@2
131-
displayName: Enable Vcpkg Install
132-
inputs:
133-
script: |
134-
$(VCPKG_INSTALLATION_ROOT)\vcpkg.exe integrate install
135-
workingDirectory: '$(VCPKG_INSTALLATION_ROOT)'
122+
- task: PowerShell@2
123+
displayName: Initialize Vcpkg
124+
inputs:
125+
filePath: '${{ parameters.sourceRoot }}\tools\Initialize-Vcpkg.ps1'
136126

137127
- ${{ if ne(parameters.releaseTagJob, '') }}:
138128
- task: PowerShell@2
@@ -180,15 +170,6 @@ jobs:
180170
${{ parameters.additionalMSBuildArgs }}'
181171
maximumCpuCount: true
182172

183-
- ${{ if parameters.useAgentVcpkg }}:
184-
- task: CopyFiles@2
185-
displayName: Copy vcpkg logs
186-
inputs:
187-
SourceFolder: $(VCPKG_INSTALLATION_ROOT)\buildtrees
188-
Contents: '**\*.log'
189-
TargetFolder: '$(artifactsDir)\vcpkgLogs'
190-
condition: succeededOrFailed()
191-
192173
- task: CopyFiles@2
193174
displayName: 'Copy specific build artifacts'
194175
inputs:

‎tools/Initialize-Vcpkg.ps1‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<#
2+
.SYNOPSIS
3+
Enables user-wide MSBuild integration for Visual Studio's bundled vcpkg.
4+
#>
5+
6+
$ErrorActionPreference = 'Stop'
7+
8+
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
9+
if (-not (Test-Path -LiteralPath $vswhere -PathType Leaf))
10+
{
11+
throw "vswhere.exe not found at $vswhere."
12+
}
13+
14+
$vcpkg = & $vswhere -latest -products '*' `
15+
-requires Microsoft.VisualStudio.Component.Vcpkg `
16+
-find 'VC\vcpkg\vcpkg.exe'
17+
if ($LASTEXITCODE -ne 0)
18+
{
19+
throw "vswhere.exe failed with exit code $LASTEXITCODE."
20+
}
21+
22+
if (-not $vcpkg -or -not (Test-Path -LiteralPath $vcpkg -PathType Leaf))
23+
{
24+
throw 'No Visual Studio installation with vcpkg.exe found.'
25+
}
26+
27+
Write-Host "Running: `"$vcpkg`" integrate install"
28+
& $vcpkg integrate install
29+
if ($LASTEXITCODE -ne 0)
30+
{
31+
throw "vcpkg integrate install failed with exit code $LASTEXITCODE."
32+
}

0 commit comments

Comments
 (0)