Files
PowerToys/src/modules/cmdpal/extensionsdk/nuget/BuildSDKHelper.ps1
Dustin L. Howett 898e7c6352 build: strong name sign the Extension Toolkit (#39469)
Strong-name signing embeds publisher identity into the signature of a
.NET assembly.

This is required if *any other* strong name signed project wants to take
a dependency on it.

To make this work, we need to delay-sign it with a public key (.snk
file)--e.g. say we are going to sign it, but not actually sign it--to
give it an identity and then later submit it to ESRP for final signing.

The snk file does not contain any private material.

Some minor changes were required to build properly:
- `InternalsVisibleTo` requires a PublicKeyToken, but we aren't using
  it in the SDK build so it's fine to just leave it out.
- I had to mark a class `sealed` and I can only guess it's because
  strong named assemblies have more guarantees?
2025-05-15 16:47:03 -05:00

115 lines
3.2 KiB
PowerShell

Param(
[string]$Configuration = "release",
[string]$VersionOfSDK = "",
[string]$BuildStep = "all",
[switch]$IsAzurePipelineBuild = $false,
[switch]$Help = $false
)
If ([String]::IsNullOrEmpty($VersionOfSDK)) {
$VersionOfSDK = $Env:XES_PACKAGEVERSIONNUMBER
}
If ([String]::IsNullOrEmpty($VersionOfSDK)) {
$VersionOfSDK = "0.0.0"
}
$StartTime = Get-Date
if ($Help) {
Write-Host @"
Copyright (c) Microsoft Corporation.
Licensed under the MIT License.
Syntax:
Build.cmd [options]
Description:
Builds the Command Palette SDK
Options:
-Configuration <configuration>
Only build the selected configuration(s)
Example: -Configuration Release
Example: -Configuration "Debug,Release"
-VersionOfSDK <version>
Set the version number of the build sdk nuget package
Example: -VersionOfSDK "1.0.0"
-Help
Display this usage message.
"@
Exit
}
$ErrorActionPreference = "Stop"
$buildPlatforms = "x64","arm64"
$msbuildPath = &"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe
if ($IsAzurePipelineBuild) {
$nugetPath = "nuget.exe";
} else {
$nugetPath = (Join-Path $PSScriptRoot "NugetWrapper.cmd")
}
if (($BuildStep -ieq "all") -Or ($BuildStep -ieq "build")) {
& $nugetPath restore (Join-Path $PSScriptRoot "..\..\..\..\..\PowerToys.sln")
Try {
foreach ($config in $Configuration.Split(",")) {
foreach ($platform in $buildPlatforms) {
$msbuildArgs = @(
("$PSScriptRoot\..\Microsoft.CommandPalette.Extensions.Toolkit\Microsoft.CommandPalette.Extensions.Toolkit.csproj"),
("/p:Platform="+$platform),
("/p:Configuration="+$config),
("/binaryLogger:CmdPal.Extensions.$platform.$config.binlog"),
("/p:VersionNumber="+$VersionOfSDK)
)
if ($IsAzurePipelineBuild) {
$msbuildArgs += "/p:CIBuild=true"
}
& $msbuildPath $msbuildArgs
}
}
} Catch {
$formatString = "`n{0}`n`n{1}`n`n"
$fields = $_, $_.ScriptStackTrace
Write-Host ($formatString -f $fields) -ForegroundColor RED
Exit 1
}
}
if (($BuildStep -ieq "all") -Or ($BuildStep -ieq "pack")) {
foreach ($config in $Configuration.Split(",")) {
if ($config -eq "release")
{
New-Item -ItemType Directory -Force -Path "$PSScriptRoot\..\_build"
& $nugetPath pack (Join-Path $PSScriptRoot "Microsoft.CommandPalette.Extensions.SDK.nuspec") -Version $VersionOfSDK -OutputDirectory "$PSScriptRoot\..\_build"
} else {
Write-Host @"
WARNING: You are currently building as '$config' configuration.
CmdPalSDK nuget creation only supports 'release' configuration right now.
"@ -ForegroundColor YELLOW
}
}
}
if ($IsAzurePipelineBuild) {
Write-Host "##vso[task.setvariable variable=VersionOfSDK;]$VersionOfSDK"
Write-Host "##vso[task.setvariable variable=VersionOfSDK;isOutput=true;]$VersionOfSDK"
}
$TotalTime = (Get-Date)-$StartTime
$TotalMinutes = [math]::Floor($TotalTime.TotalMinutes)
$TotalSeconds = [math]::Ceiling($TotalTime.TotalSeconds)
Write-Host @"
Total Running Time:
$TotalMinutes minutes and $TotalSeconds seconds
"@ -ForegroundColor CYAN