Merge remote-tracking branch 'libtemplate/microbuild' into libtemplateUpdate

This commit is contained in:
Andrew Arnott 2023-04-03 13:33:55 -06:00
Родитель e6830a5e03 52178047cb
Коммит ff6e334707
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F33A420C60ED9C6F
11 изменённых файлов: 179 добавлений и 95 удалений

30
.config/dotnet-tools.json Normal file
Просмотреть файл

@ -0,0 +1,30 @@
{
"version": 1,
"isRoot": true,
"tools": {
"powershell": {
"version": "7.3.3",
"commands": [
"pwsh"
]
},
"dotnet-format": {
"version": "5.1.250801",
"commands": [
"dotnet-format"
]
},
"dotnet-coverage": {
"version": "17.6.11",
"commands": [
"dotnet-coverage"
]
},
"nbgv": {
"version": "3.5.119",
"commands": [
"nbgv"
]
}
}
}

Просмотреть файл

@ -3,7 +3,7 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<MicroBuildVersion>2.0.113</MicroBuildVersion>
<MicroBuildVersion>2.0.115</MicroBuildVersion>
<CodeAnalysisVersion>3.11.0</CodeAnalysisVersion>
<CodeAnalysisVersion Condition="'$(IsTestProject)'=='true'">4.4.0</CodeAnalysisVersion>
<CodefixTestingVersion>1.1.1</CodefixTestingVersion>
@ -20,7 +20,6 @@
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.0-beta2.final" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" Version="$(CodeAnalysisVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit" Version="$(CodefixTestingVersion)" />
<PackageVersion Include="Microsoft.CodeCoverage" Version="17.5.0" />
<PackageVersion Include="Microsoft.Diagnostics.Runtime.Utilities" Version="$(MicrosoftDiagnosticsRuntimeVersion)" />
<PackageVersion Include="Microsoft.Diagnostics.Runtime" Version="$(MicrosoftDiagnosticsRuntimeVersion)" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />

Просмотреть файл

@ -1,24 +0,0 @@
<#
.SYNOPSIS
Gets the path to the nbgv CLI tool, installing it if necessary.
#>
Param(
)
$existingTool = Get-Command "nbgv" -ErrorAction SilentlyContinue
if ($existingTool) {
return $existingTool.Path
}
$toolInstallDir = & "$PSScriptRoot/Get-TempToolsPath.ps1"
$toolPath = "$toolInstallDir/nbgv"
if (!(Test-Path $toolInstallDir)) { New-Item -Path $toolInstallDir -ItemType Directory | Out-Null }
if (!(Get-Command $toolPath -ErrorAction SilentlyContinue)) {
Write-Host "Installing nbgv to $toolInstallDir"
dotnet tool install --tool-path "$toolInstallDir" nbgv --configfile "$PSScriptRoot/justnugetorg.nuget.config" | Out-Null
}
# Normalize the path on the way out.
return (Get-Command $toolPath).Path

Просмотреть файл

@ -20,32 +20,32 @@ Param(
)
$RepoRoot = [string](Resolve-Path $PSScriptRoot/..)
Push-Location $RepoRoot
try {
Write-Verbose "Searching $Path for *.cobertura.xml files"
$reports = Get-ChildItem -Recurse $Path -Filter *.cobertura.xml
if (!(Test-Path $RepoRoot/obj/dotnet-coverage*)) {
dotnet tool install --tool-path $RepoRoot/obj dotnet-coverage --version 17.4.3 --configfile $PSScriptRoot/justnugetorg.nuget.config
}
if ($reports) {
$reports |% { $_.FullName } |% {
# In addition to replacing {reporoot}, we also normalize on one kind of slash so that the report aggregates data for a file whether data was collected on Windows or not.
$xml = [xml](Get-Content -Path $_)
$xml.coverage.packages.package.classes.class |? { $_.filename} |% {
$_.filename = $_.filename.Replace('{reporoot}', $RepoRoot).Replace([IO.Path]::AltDirectorySeparatorChar, [IO.Path]::DirectorySeparatorChar)
}
Write-Verbose "Searching $Path for *.cobertura.xml files"
$reports = Get-ChildItem -Recurse $Path -Filter *.cobertura.xml
if ($reports) {
$reports |% { $_.FullName } |% {
# In addition to replacing {reporoot}, we also normalize on one kind of slash so that the report aggregates data for a file whether data was collected on Windows or not.
$xml = [xml](Get-Content -Path $_)
$xml.coverage.packages.package.classes.class |? { $_.filename} |% {
$_.filename = $_.filename.Replace('{reporoot}', $RepoRoot).Replace([IO.Path]::AltDirectorySeparatorChar, [IO.Path]::DirectorySeparatorChar)
$xml.Save($_)
}
$xml.Save($_)
$Inputs = $reports |% { Resolve-Path -relative $_.FullName }
if ((Split-Path $OutputFile) -and -not (Test-Path (Split-Path $OutputFile))) {
New-Item -Type Directory -Path (Split-Path $OutputFile) | Out-Null
}
& dotnet tool run dotnet-coverage merge $Inputs -o $OutputFile -f cobertura
} else {
Write-Error "No reports found to merge."
}
$Inputs = $reports |% { Resolve-Path -relative $_.FullName }
if ((Split-Path $OutputFile) -and -not (Test-Path (Split-Path $OutputFile))) {
New-Item -Type Directory -Path (Split-Path $OutputFile) | Out-Null
}
& "$RepoRoot/obj/dotnet-coverage" merge $Inputs -o $OutputFile -f cobertura
} else {
Write-Error "No reports found to merge."
} finally {
Pop-Location
}

Просмотреть файл

@ -33,7 +33,7 @@ jobs:
- template: install-dependencies.yml
- powershell: '& (./azure-pipelines/Get-nbgv.ps1) cloud -ca'
- script: dotnet tool run nbgv cloud -ca
displayName: ⚙ Set build number
- ${{ if eq(variables['system.collectionId'], '011b8bdf-6d56-4f87-be0d-0092136884d9') }}:

Просмотреть файл

@ -26,7 +26,7 @@ steps:
languages: $(LocLanguages)
displayName: 🔧 Install MicroBuild Localization Plugin
- task: MicroBuildSigningPlugin@3
- task: MicroBuildSigningPlugin@4
inputs:
signType: $(SignType)
zipSources: false

Просмотреть файл

@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.101",
"version": "7.0.201",
"rollForward": "patch",
"allowPrerelease": false
},

Просмотреть файл

@ -28,6 +28,8 @@
No effect if -NoPrerequisites is specified.
.PARAMETER NoRestore
Skips the package restore step.
.PARAMETER NoToolRestore
Skips the dotnet tool restore step.
.PARAMETER Signing
Install the MicroBuild signing plugin for building test-signed builds on desktop machines.
.PARAMETER Localization
@ -57,6 +59,8 @@ Param (
[Parameter()]
[switch]$NoRestore,
[Parameter()]
[switch]$NoToolRestore,
[Parameter()]
[switch]$Signing,
[Parameter()]
[switch]$Localization,
@ -112,6 +116,13 @@ try {
}
}
if (!$NoToolRestore -and $PSCmdlet.ShouldProcess("dotnet tool", "restore")) {
dotnet tool restore @RestoreArguments
if ($lastexitcode -ne 0) {
throw "Failure while restoring dotnet CLI tools."
}
}
$InstallNuGetPkgScriptPath = "$PSScriptRoot\azure-pipelines\Install-NuGetPackage.ps1"
$nugetVerbosity = 'quiet'
if ($Verbose) { $nugetVerbosity = 'normal' }

Просмотреть файл

@ -22,7 +22,6 @@
<ProjectReference Include="..\..\src\Microsoft.VisualStudio.Threading\Microsoft.VisualStudio.Threading.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeCoverage" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeFix.Testing.XUnit" />
<PackageReference Include="Microsoft.CodeAnalysis" />

Просмотреть файл

@ -28,7 +28,6 @@
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeCoverage" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Nullable" PrivateAssets="all" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" />

Просмотреть файл

@ -3,7 +3,7 @@
<#
.SYNOPSIS
Installs the .NET SDK specified in the global.json file at the root of this repository,
along with supporting .NET Core runtimes used for testing.
along with supporting .NET runtimes used for testing.
.DESCRIPTION
This MAY not require elevation, as the SDK and runtimes are installed locally to this repo location,
unless `-InstallLocality machine` is specified.
@ -15,14 +15,20 @@
When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used.
Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`.
Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it.
.PARAMETER SdkOnly
Skips installing the runtime.
.PARAMETER IncludeX86
Installs a x86 SDK and runtimes in addition to the x64 ones. Only supported on Windows. Ignored on others.
.PARAMETER IncludeAspNetCore
Installs the ASP.NET Core runtime along with the .NET runtime.
#>
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium')]
Param (
[ValidateSet('repo','user','machine')]
[string]$InstallLocality='user',
[switch]$IncludeX86
[switch]$SdkOnly,
[switch]$IncludeX86,
[switch]$IncludeAspNetCore
)
$DotNetInstallScriptRoot = "$PSScriptRoot/../obj/tools"
@ -43,37 +49,46 @@ if (!$arch) { # Windows Powershell leaves this blank
if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { $arch = 'ARM64' }
}
# Search for all .NET Core runtime versions referenced from MSBuild projects and arrange to install them.
# Search for all .NET runtime versions referenced from MSBuild projects and arrange to install them.
$runtimeVersions = @()
$windowsDesktopRuntimeVersions = @()
Get-ChildItem "$PSScriptRoot\..\src\*.*proj","$PSScriptRoot\..\test\*.*proj","$PSScriptRoot\..\Directory.Build.props" -Recurse |% {
$projXml = [xml](Get-Content -Path $_)
$pg = $projXml.Project.PropertyGroup
if ($pg) {
$targetFrameworks = @()
$tf = $pg.TargetFramework
$targetFrameworks += $tf
$tfs = $pg.TargetFrameworks
if ($tfs) {
$targetFrameworks = $tfs -Split ';'
$aspnetRuntimeVersions = @()
if (!$SdkOnly) {
Get-ChildItem "$PSScriptRoot\..\src\*.*proj","$PSScriptRoot\..\test\*.*proj","$PSScriptRoot\..\Directory.Build.props" -Recurse |% {
$projXml = [xml](Get-Content -Path $_)
$pg = $projXml.Project.PropertyGroup
if ($pg) {
$targetFrameworks = @()
$tf = $pg.TargetFramework
$targetFrameworks += $tf
$tfs = $pg.TargetFrameworks
if ($tfs) {
$targetFrameworks = $tfs -Split ';'
}
}
}
$targetFrameworks |? { $_ -match 'net(?:coreapp)?(\d+\.\d+)' } |% {
$v = $Matches[1]
$runtimeVersions += $v
if ($v -ge '3.0' -and -not ($IsMacOS -or $IsLinux)) {
$windowsDesktopRuntimeVersions += $v
$targetFrameworks |? { $_ -match 'net(?:coreapp)?(\d+\.\d+)' } |% {
$v = $Matches[1]
$runtimeVersions += $v
$aspnetRuntimeVersions += $v
if ($v -ge '3.0' -and -not ($IsMacOS -or $IsLinux)) {
$windowsDesktopRuntimeVersions += $v
}
}
}
# Add target frameworks of the form: netXX
$targetFrameworks |? { $_ -match 'net(\d+\.\d+)' } |% {
$v = $Matches[1]
$runtimeVersions += $v
if (-not ($IsMacOS -or $IsLinux)) {
$windowsDesktopRuntimeVersions += $v
# Add target frameworks of the form: netXX
$targetFrameworks |? { $_ -match 'net(\d+\.\d+)' } |% {
$v = $Matches[1]
$runtimeVersions += $v
$aspnetRuntimeVersions += $v
if (-not ($IsMacOS -or $IsLinux)) {
$windowsDesktopRuntimeVersions += $v
}
}
}
}
}
if (!$IncludeAspNetCore) {
$aspnetRuntimeVersions = @()
}
Function Get-FileFromWeb([Uri]$Uri, $OutDir) {
@ -92,18 +107,24 @@ Function Get-FileFromWeb([Uri]$Uri, $OutDir) {
}
Function Get-InstallerExe(
[Version]$Version,
$Version,
$Architecture,
[ValidateSet('Sdk','Runtime','WindowsDesktop')]
[string]$sku
) {
# Get the latest/actual version for the specified one
if ($Version.Build -eq -1) {
$TypedVersion = $null
if (![Version]::TryParse($Version, [ref] $TypedVersion)) {
Write-Error "Unable to parse $Version into an a.b.c.d version. This version cannot be installed machine-wide."
exit 1
}
if ($TypedVersion.Build -eq -1) {
$versionInfo = -Split (Invoke-WebRequest -Uri "https://dotnetcli.blob.core.windows.net/dotnet/$sku/$Version/latest.version" -UseBasicParsing)
$Version = $versionInfo[-1]
}
$majorMinor = "$($Version.Major).$($Version.Minor)"
$majorMinor = "$($TypedVersion.Major).$($TypedVersion.Minor)"
$ReleasesFile = Join-Path $DotNetInstallScriptRoot "$majorMinor\releases.json"
if (!(Test-Path $ReleasesFile)) {
Get-FileFromWeb -Uri "https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/$majorMinor/releases.json" -OutDir (Split-Path $ReleasesFile) | Out-Null
@ -116,6 +137,14 @@ Function Get-InstallerExe(
if ($release.$sku.version -eq $Version) {
$filesElement = $release.$sku.files
}
if (!$filesElement -and ($sku -eq 'sdk') -and $release.sdks) {
foreach ($sdk in $release.sdks) {
if ($sdk.version -eq $Version) {
$filesElement = $sdk.files
break
}
}
}
if ($filesElement) {
foreach ($file in $filesElement) {
@ -134,14 +163,14 @@ Function Get-InstallerExe(
if ($url) {
Get-FileFromWeb -Uri $url -OutDir $DotNetInstallScriptRoot
} else {
Write-Error "Unable to find release of $sku v$Version"
throw "Unable to find release of $sku v$Version"
}
}
Function Install-DotNet($Version, $Architecture, [ValidateSet('Sdk','Runtime','WindowsDesktop')][string]$sku = 'Sdk') {
Write-Host "Downloading .NET Core $sku $Version..."
Function Install-DotNet($Version, $Architecture, [ValidateSet('Sdk','Runtime','WindowsDesktop','AspNetCore')][string]$sku = 'Sdk') {
Write-Host "Downloading .NET $sku $Version..."
$Installer = Get-InstallerExe -Version $Version -Architecture $Architecture -sku $sku
Write-Host "Installing .NET Core $sku $Version..."
Write-Host "Installing .NET $sku $Version..."
cmd /c start /wait $Installer /install /passive /norestart
if ($LASTEXITCODE -eq 3010) {
Write-Verbose "Restart required"
@ -195,6 +224,17 @@ if ($InstallLocality -eq 'machine') {
}
}
$aspnetRuntimeVersions | Sort-Object | Get-Unique |% {
if ($PSCmdlet.ShouldProcess("ASP.NET Core $_", "Install")) {
Install-DotNet -Version $_ -sku AspNetCore -Architecture $arch
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
if ($IncludeX86) {
Install-DotNet -Version $_ -sku AspNetCore -Architecture x86
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
}
}
}
if ($restartRequired) {
Write-Host -ForegroundColor Yellow "System restart required"
Exit 3010
@ -233,10 +273,10 @@ if ($IncludeX86) {
}
if ($IsMacOS -or $IsLinux) {
$DownloadUri = "https://raw.githubusercontent.com/dotnet/install-scripts/781752509a890ca7520f1182e8bae71f9a53d754/src/dotnet-install.sh"
$DownloadUri = "https://raw.githubusercontent.com/dotnet/install-scripts/0b09de9bc136cacb5f849a6957ebd4062173c148/src/dotnet-install.sh"
$DotNetInstallScriptPath = "$DotNetInstallScriptRoot/dotnet-install.sh"
} else {
$DownloadUri = "https://raw.githubusercontent.com/dotnet/install-scripts/781752509a890ca7520f1182e8bae71f9a53d754/src/dotnet-install.ps1"
$DownloadUri = "https://raw.githubusercontent.com/dotnet/install-scripts/0b09de9bc136cacb5f849a6957ebd4062173c148/src/dotnet-install.ps1"
$DotNetInstallScriptPath = "$DotNetInstallScriptRoot/dotnet-install.ps1"
}
@ -284,7 +324,7 @@ if ($IncludeX86) {
$dotnetRuntimeSwitches = $switches + '-Runtime','dotnet'
$runtimeVersions | Sort-Object -Unique |% {
if ($PSCmdlet.ShouldProcess(".NET Core $Arch runtime $_", "Install")) {
if ($PSCmdlet.ShouldProcess(".NET $Arch runtime $_", "Install")) {
$anythingInstalled = $true
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ -Architecture $arch -InstallDir $DotNetInstallDir $dotnetRuntimeSwitches"
@ -297,7 +337,7 @@ $runtimeVersions | Sort-Object -Unique |% {
}
if ($IncludeX86) {
if ($PSCmdlet.ShouldProcess(".NET Core x86 runtime $_", "Install")) {
if ($PSCmdlet.ShouldProcess(".NET x86 runtime $_", "Install")) {
$anythingInstalled = $true
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ -Architecture x86 -InstallDir $DotNetX86InstallDir $dotnetRuntimeSwitches"
@ -314,7 +354,7 @@ $runtimeVersions | Sort-Object -Unique |% {
$windowsDesktopRuntimeSwitches = $switches + '-Runtime','windowsdesktop'
$windowsDesktopRuntimeVersions | Sort-Object -Unique |% {
if ($PSCmdlet.ShouldProcess(".NET Core WindowsDesktop $arch runtime $_", "Install")) {
if ($PSCmdlet.ShouldProcess(".NET WindowsDesktop $arch runtime $_", "Install")) {
$anythingInstalled = $true
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ -Architecture $arch -InstallDir $DotNetInstallDir $windowsDesktopRuntimeSwitches"
@ -327,7 +367,7 @@ $windowsDesktopRuntimeVersions | Sort-Object -Unique |% {
}
if ($IncludeX86) {
if ($PSCmdlet.ShouldProcess(".NET Core WindowsDesktop x86 runtime $_", "Install")) {
if ($PSCmdlet.ShouldProcess(".NET WindowsDesktop x86 runtime $_", "Install")) {
$anythingInstalled = $true
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ -Architecture x86 -InstallDir $DotNetX86InstallDir $windowsDesktopRuntimeSwitches"
@ -341,10 +381,40 @@ $windowsDesktopRuntimeVersions | Sort-Object -Unique |% {
}
}
$aspnetRuntimeSwitches = $switches + '-Runtime','aspnetcore'
$aspnetRuntimeVersions | Sort-Object -Unique |% {
if ($PSCmdlet.ShouldProcess(".NET ASP.NET Core $arch runtime $_", "Install")) {
$anythingInstalled = $true
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ -Architecture $arch -InstallDir $DotNetInstallDir $aspnetRuntimeSwitches"
if ($LASTEXITCODE -ne 0) {
Write-Error ".NET SDK installation failure: $LASTEXITCODE"
exit $LASTEXITCODE
}
} else {
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ -Architecture $arch -InstallDir $DotNetInstallDir $aspnetRuntimeSwitches -DryRun"
}
if ($IncludeX86) {
if ($PSCmdlet.ShouldProcess(".NET ASP.NET Core x86 runtime $_", "Install")) {
$anythingInstalled = $true
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ -Architecture x86 -InstallDir $DotNetX86InstallDir $aspnetRuntimeSwitches"
if ($LASTEXITCODE -ne 0) {
Write-Error ".NET SDK installation failure: $LASTEXITCODE"
exit $LASTEXITCODE
}
} else {
Invoke-Expression -Command "$DotNetInstallScriptPathExpression -Channel $_ -Architecture x86 -InstallDir $DotNetX86InstallDir $aspnetRuntimeSwitches -DryRun"
}
}
}
if ($PSCmdlet.ShouldProcess("Set DOTNET environment variables to discover these installed runtimes?")) {
& "$PSScriptRoot/Set-EnvVars.ps1" -Variables $envVars -PrependPath $DotNetInstallDir | Out-Null
}
if ($anythingInstalled -and ($InstallLocality -ne 'machine') -and !$env:TF_BUILD -and !$env:GITHUB_ACTIONS) {
Write-Warning ".NET Core runtimes or SDKs were installed to a non-machine location. Perform your builds or open Visual Studio from this same environment in order for tools to discover the location of these dependencies."
Write-Warning ".NET runtimes or SDKs were installed to a non-machine location. Perform your builds or open Visual Studio from this same environment in order for tools to discover the location of these dependencies."
}