Skip to content

Commit 8693638

Browse files
committed
Simple vcpkg script
1 parent b3ebc37 commit 8693638

6 files changed

Lines changed: 43 additions & 45 deletions

File tree

‎azure-pipelines.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ jobs:
8484
nugetConfigPath: '$(nugetConfig)'
8585

8686
- task: PowerShell@2
87-
displayName: Find and Integrate Vcpkg
87+
displayName: Initialize Vcpkg
8888
inputs:
89-
filePath: 'templates\Find-AndIntegrate-Vcpkg.ps1'
89+
filePath: 'tools\Initialize-Vcpkg.ps1'
9090

9191
- task: VSBuild@1
9292
displayName: Build Fuzzing Artifacts

‎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/Find-AndIntegrate-Vcpkg.ps1‎

Lines changed: 0 additions & 38 deletions
This file was deleted.

‎templates/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ is neither a parameter nor a path in this directory.
8181
**Pipeline variables.** None. `jobs-build.yml` sets what it needs at job scope — `solution`, so it
8282
can be rooted, and `EnableDetectorVcpkg`, so Component Governance detects the vcpkg dependencies.
8383

84-
**A Windows agent** with Visual Studio 2022 and vcpkg. **The `Test` and `BuildPowerShellModule` jobs need
85-
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.**
8688

8789
**Outbound network access.** The test jobs reach several public endpoints, which is worth checking
8890
before wiring this up on a restricted network:

‎templates/jobs-build.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ jobs:
120120
nugetConfigPath: '$(nugetConfig)'
121121

122122
- task: PowerShell@2
123-
displayName: Find and Integrate Vcpkg
123+
displayName: Initialize Vcpkg
124124
inputs:
125-
filePath: '${{ parameters.sourceRoot }}\templates\Find-AndIntegrate-Vcpkg.ps1'
125+
filePath: '${{ parameters.sourceRoot }}\tools\Initialize-Vcpkg.ps1'
126126

127127
- ${{ if ne(parameters.releaseTagJob, '') }}:
128128
- task: PowerShell@2

‎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)