Merge branch 'master' into validate/microbuild
This commit is contained in:
Коммит
97bdc36be0
|
@ -9,6 +9,10 @@ indent_style = space
|
|||
|
||||
# (Please don't specify an indent_size here; that has too many unintended consequences.)
|
||||
|
||||
[*.yml]
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
|
||||
# Code files
|
||||
[*.{cs,csx,vb,vbx,h,cpp,idl}]
|
||||
indent_size = 4
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: nuget
|
||||
directory: /
|
||||
schedule:
|
||||
interval: weekly
|
|
@ -16,6 +16,8 @@ with any additional questions or comments.
|
|||
|
||||
All dependencies can be installed by running the `init.ps1` script at the root of the repository
|
||||
using Windows PowerShell or [PowerShell Core][pwsh] (on any OS).
|
||||
Some dependencies installed by `init.ps1` may only be discoverable from the same command line environment the init script was run from due to environment variables, so be sure to launch Visual Studio or build the repo from that same environment.
|
||||
Alternatively, run `init.ps1 -InstallLocality Machine` (which may require elevation) in order to install dependencies at machine-wide locations so Visual Studio and builds work everywhere.
|
||||
|
||||
The only prerequisite for building, testing, and deploying from this repository
|
||||
is the [.NET SDK](https://get.dot.net/).
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MicroBuild.VisualStudio" Version="$(MicroBuildVersion)" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<!-- <PackageReference Include="Microsoft.SourceLink.AzureRepos.Git" Version="1.0.0" PrivateAssets="All" /> -->
|
||||
<PackageReference Include="Nerdbank.GitVersioning" Version="3.1.91" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.6.0" PrivateAssets="all" />
|
||||
<PackageReference Include="Nerdbank.GitVersioning" Version="3.2.31" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.7.0" PrivateAssets="all" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -41,4 +41,31 @@
|
|||
<!-- We always want MSBuild properties generated that point at the restored location of each package. -->
|
||||
<PackageReference GeneratePathProperty="true" />
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(IsWpfTempProject)' == ''">
|
||||
<IsWpfTempProject>false</IsWpfTempProject>
|
||||
<IsWpfTempProject Condition="$(MSBuildProjectName.EndsWith('_wpftmp'))">true</IsWpfTempProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
Inspired by https://github.com/dotnet/arcade/blob/cbfa29d4e859622ada3d226f90f103f659665d31/src/Microsoft.DotNet.Arcade.Sdk/tools/Workarounds.props#L14-L31
|
||||
WPF temp-projects do not import .props and .targets files from NuGet packages.
|
||||
(see https://github.com/dotnet/sourcelink/issues/91).
|
||||
|
||||
Property _TargetAssemblyProjectName is set by GenerateTemporaryTargetAssembly task.
|
||||
Disable Source Link and Xliff in WPF temp projects to avoid generating non-deterministic file names to obj dir.
|
||||
The project name is non-deterministic and is included in the Source Link json file name and xlf directory names.
|
||||
It's also not necessary to generate these assets.
|
||||
-->
|
||||
<PropertyGroup Condition="'$(IsWpfTempProject)' == 'true'">
|
||||
<_WpfTempProjectNuGetFilePathNoExt>$(RepoRootPath)obj\$(_TargetAssemblyProjectName)\$(_TargetAssemblyProjectName)$(MSBuildProjectExtension).nuget.g</_WpfTempProjectNuGetFilePathNoExt>
|
||||
|
||||
<EnableSourceLink>false</EnableSourceLink>
|
||||
<EmbedUntrackedSources>false</EmbedUntrackedSources>
|
||||
<DeterministicSourcePaths>false</DeterministicSourcePaths>
|
||||
<EnableXlfLocalization>false</EnableXlfLocalization>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Workaround https://github.com/dotnet/wpf/issues/810 -->
|
||||
<Import Project="$(_WpfTempProjectNuGetFilePathNoExt).props" Condition="'$(_WpfTempProjectNuGetFilePathNoExt)' != '' and Exists('$(_WpfTempProjectNuGetFilePathNoExt).props')"/>
|
||||
</Project>
|
||||
|
|
|
@ -1,2 +1,8 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<!-- Workaround https://github.com/dotnet/wpf/issues/1718 -->
|
||||
<EmbedUntrackedSources Condition=" '$(UseWPF)' == 'true' ">false</EmbedUntrackedSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(_WpfTempProjectNuGetFilePathNoExt).targets" Condition="'$(_WpfTempProjectNuGetFilePathNoExt)' != '' and Exists('$(_WpfTempProjectNuGetFilePathNoExt).targets')"/>
|
||||
</Project>
|
||||
|
|
|
@ -13,7 +13,7 @@ but can be added later by editing the Azure Pipelines YAML file.
|
|||
.PARAMETER Squash
|
||||
A switch that causes all of git history to be squashed to just one initial commit for the template, and one for its expansion.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='Medium')]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$LibraryName,
|
||||
|
@ -52,6 +52,10 @@ function Replace-Placeholders {
|
|||
# Try to find sn.exe if it isn't on the PATH
|
||||
$sn = Get-Command sn -ErrorAction SilentlyContinue
|
||||
if (-not $sn) {
|
||||
if ($IsMacOS -or $IsLinux) {
|
||||
Write-Error "sn command not found on PATH. Install mono and/or vote up this issue: https://github.com/dotnet/sdk/issues/13560"
|
||||
exit(1)
|
||||
}
|
||||
$snExes = Get-ChildItem -Recurse "${env:ProgramFiles(x86)}\Microsoft SDKs\Windows\sn.exe"
|
||||
if ($snExes) {
|
||||
$sn = Get-Command $snExes[0].FullName
|
||||
|
@ -61,6 +65,15 @@ if (-not $sn) {
|
|||
}
|
||||
}
|
||||
|
||||
if (-not (& "$PSScriptRoot\tools\Check-DotNetSdk.ps1")) {
|
||||
if ($PSCmdlet.ShouldProcess('Install .NET Core SDK?')) {
|
||||
& "$PSScriptRoot\tools\Install-DotNetSdk.ps1"
|
||||
} else {
|
||||
Write-Error "Matching .NET Core SDK version not found. Install now?"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# Verify all commands we use are on the PATH
|
||||
('git','dotnet') |% {
|
||||
if (-not (Get-Command $_ -ErrorAction SilentlyContinue)) {
|
||||
|
@ -74,27 +87,42 @@ try {
|
|||
if ($Squash) {
|
||||
$originalCommitId = git rev-parse HEAD
|
||||
git reset --soft $(git rev-list --max-parents=0 HEAD)
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
git commit --amend -qm "Initial template from https://github.com/AArnott/Library.Template" -m "Original commit from template $originalCommitId"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
}
|
||||
|
||||
# Rename project directories and solution
|
||||
git mv Library.sln "$LibraryName.sln"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
git mv src/Library/Library.csproj "src/Library/$LibraryName.csproj"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
git mv src/Library "src/$LibraryName"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
git mv test/Library.Tests/Library.Tests.csproj "test/Library.Tests/$LibraryName.Tests.csproj"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
git mv test/Library.Tests "test/$LibraryName.Tests"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
# Refresh solution file both to update paths and give the projects unique GUIDs
|
||||
dotnet sln remove src/Library/Library.csproj
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
dotnet sln remove test/Library.Tests/Library.Tests.csproj
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
dotnet sln add "src/$LibraryName"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
dotnet sln add "test/$LibraryName.Tests"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
git add "$LibraryName.sln"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
# Update project reference in test project. Add before removal to keep the same ItemGroup in place.
|
||||
dotnet add "test/$LibraryName.Tests" reference "src/$LibraryName"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
dotnet remove "test/$LibraryName.Tests" reference src/Library/Library.csproj
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
git add "test/$LibraryName.Tests/$LibraryName.Tests.csproj"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
# Replace placeholders in source files
|
||||
Replace-Placeholders -Path "src/$LibraryName/Calculator.cs" -Replacements @{
|
||||
|
@ -148,7 +176,9 @@ try {
|
|||
|
||||
# Self destruct
|
||||
git rm Expand-Template.*
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
git rm :/azure-pipelines/expand-template.yml
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
# Self-integrity check
|
||||
Get-ChildItem -Recurse -File -Exclude bin,obj,README.md,Expand-Template.* |? { -not $_.FullName.Contains("obj") } |% {
|
||||
|
@ -160,6 +190,7 @@ try {
|
|||
|
||||
# Commit the changes
|
||||
git commit -qm "Expanded template for $LibraryName" -m "This expansion done by the (now removed) Expand-Template.ps1 script."
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
|
||||
Write-Host -ForegroundColor Green "Template successfully expanded."
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ steps:
|
|||
command: test
|
||||
arguments: --no-build -c $(BuildConfiguration) -f net472 --filter "TestCategory!=FailsInCloudTest" -v n /p:CollectCoverage=true --settings "$(Build.Repository.LocalPath)/azure-pipelines/$(Agent.OS).runsettings"
|
||||
testRunTitle: net472-$(Agent.JobName)
|
||||
condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))
|
||||
condition: succeededOrFailed()
|
||||
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: dotnet test -f netcoreapp2.1
|
||||
|
@ -30,6 +30,7 @@ steps:
|
|||
command: test
|
||||
arguments: --no-build -c $(BuildConfiguration) -f netcoreapp2.1 --filter "TestCategory!=FailsInCloudTest" -v n /p:CollectCoverage=true --settings "$(Build.Repository.LocalPath)/azure-pipelines/$(Agent.OS).runsettings"
|
||||
testRunTitle: netcoreapp2.1-$(Agent.JobName)
|
||||
condition: succeededOrFailed()
|
||||
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: dotnet test -f netcoreapp3.1
|
||||
|
@ -37,6 +38,7 @@ steps:
|
|||
command: test
|
||||
arguments: --no-build -c $(BuildConfiguration) -f netcoreapp3.1 --filter "TestCategory!=FailsInCloudTest" -v n /p:CollectCoverage=true --settings "$(Build.Repository.LocalPath)/azure-pipelines/$(Agent.OS).runsettings"
|
||||
testRunTitle: netcoreapp3.1-$(Agent.JobName)
|
||||
condition: succeededOrFailed()
|
||||
|
||||
- powershell: azure-pipelines/variables/_pipelines.ps1
|
||||
failOnStderr: true
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
trigger: none # We only want to trigger manually or based on resources
|
||||
pr: none
|
||||
|
||||
resources:
|
||||
pipelines:
|
||||
- pipeline: CI
|
||||
source: Library # TODO: This should match the name of your CI pipeline
|
||||
trigger:
|
||||
tags:
|
||||
- auto-release
|
||||
|
||||
stages:
|
||||
- stage: GitHubRelease
|
||||
displayName: GitHub Release
|
||||
jobs:
|
||||
- deployment: create
|
||||
pool:
|
||||
vmImage: ubuntu-latest
|
||||
environment: No-Approval
|
||||
strategy:
|
||||
runOnce:
|
||||
deploy:
|
||||
steps:
|
||||
- download: none
|
||||
- powershell: |
|
||||
Write-Host "##vso[build.updatebuildnumber]$(resources.pipeline.CI.runName)"
|
||||
displayName: Set pipeline name
|
||||
- task: GitHubRelease@1
|
||||
displayName: GitHub release (create)
|
||||
inputs:
|
||||
gitHubConnection: # TODO: fill in service connection here
|
||||
repositoryName: $(Build.Repository.Name)
|
||||
target: $(resources.pipeline.CI.sourceCommit)
|
||||
tagSource: userSpecifiedTag
|
||||
tag: v$(resources.pipeline.CI.runName)
|
||||
title: v$(resources.pipeline.CI.runName)
|
||||
isDraft: true # After running this step, visit the new draft release, edit, and publish.
|
||||
changeLogCompareToRelease: lastNonDraftRelease
|
||||
changeLogType: issueBased
|
||||
changeLogLabels: |
|
||||
[
|
||||
{ "label" : "bug", "displayName" : "Fixes", "state" : "closed" },
|
||||
{ "label" : "enhancement", "displayName": "Enhancements", "state" : "closed" }
|
||||
]
|
||||
|
||||
- stage: nuget_org
|
||||
displayName: nuget.org
|
||||
dependsOn: GitHubRelease
|
||||
jobs:
|
||||
- deployment: push
|
||||
pool:
|
||||
vmImage: ubuntu-latest
|
||||
environment: No-Approval
|
||||
strategy:
|
||||
runOnce:
|
||||
deploy:
|
||||
steps:
|
||||
- download: CI
|
||||
artifact: deployables-Windows
|
||||
displayName: Download deployables-Windows artifact
|
||||
patterns: 'deployables-Windows/*'
|
||||
- task: NuGetToolInstaller@1
|
||||
displayName: Use NuGet 5.x
|
||||
inputs:
|
||||
versionSpec: 5.x
|
||||
- task: NuGetCommand@2
|
||||
displayName: NuGet push
|
||||
inputs:
|
||||
command: push
|
||||
packagesToPush: $(Pipeline.Workspace)/CI/deployables-Windows/*.nupkg
|
||||
nuGetFeedType: external
|
||||
publishFeedCredentials: # TODO: fill in service connection here
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"sdk": {
|
||||
"version": "3.1.301",
|
||||
"version": "3.1.302",
|
||||
"rollForward": "patch",
|
||||
"allowPrerelease": false
|
||||
}
|
||||
|
|
16
init.cmd
16
init.cmd
|
@ -1,4 +1,20 @@
|
|||
@echo off
|
||||
SETLOCAL
|
||||
set PS1UnderCmd=1
|
||||
|
||||
:: Get the datetime in a format that can go in a filename.
|
||||
set _my_datetime=%date%_%time%
|
||||
set _my_datetime=%_my_datetime: =_%
|
||||
set _my_datetime=%_my_datetime::=%
|
||||
set _my_datetime=%_my_datetime:/=_%
|
||||
set _my_datetime=%_my_datetime:.=_%
|
||||
set CmdEnvScriptPath=%temp%\envvarscript_%_my_datetime%.cmd
|
||||
|
||||
powershell.exe -NoProfile -NoLogo -ExecutionPolicy bypass -Command "try { & '%~dpn0.ps1' %*; exit $LASTEXITCODE } catch { write-host $_; exit 1 }"
|
||||
|
||||
:: Set environment variables in the parent cmd.exe process.
|
||||
IF EXIST "%CmdEnvScriptPath%" (
|
||||
ENDLOCAL
|
||||
CALL "%CmdEnvScriptPath%"
|
||||
DEL "%CmdEnvScriptPath%"
|
||||
)
|
||||
|
|
51
init.ps1
51
init.ps1
|
@ -2,39 +2,42 @@
|
|||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs dependencies required to build and test the projects in this repository.
|
||||
Installs dependencies required to build and test the projects in this repository.
|
||||
.DESCRIPTION
|
||||
This MAY not require elevation, as the SDK and runtimes are installed to a per-user location,
|
||||
unless the `-InstallLocality` switch is specified directing to a per-repo or per-machine location.
|
||||
See detailed help on that switch for more information.
|
||||
This MAY not require elevation, as the SDK and runtimes are installed to a per-user location,
|
||||
unless the `-InstallLocality` switch is specified directing to a per-repo or per-machine location.
|
||||
See detailed help on that switch for more information.
|
||||
|
||||
The CmdEnvScriptPath environment variable may be optionally set to a path to a cmd shell script to be created (or appended to if it already exists) that will set the environment variables in cmd.exe that are set within the PowerShell environment.
|
||||
This is used by init.cmd in order to reapply any new environment variables to the parent cmd.exe process that were set in the powershell child process.
|
||||
.PARAMETER InstallLocality
|
||||
A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
|
||||
Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
|
||||
Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
|
||||
Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
|
||||
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.
|
||||
A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
|
||||
Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
|
||||
Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
|
||||
Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
|
||||
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 NoPrerequisites
|
||||
Skips the installation of prerequisite software (e.g. SDKs, tools).
|
||||
Skips the installation of prerequisite software (e.g. SDKs, tools).
|
||||
.PARAMETER UpgradePrerequisites
|
||||
Takes time to install prerequisites even if they are already present in case they need to be upgraded.
|
||||
No effect if -NoPrerequisites is specified.
|
||||
Takes time to install prerequisites even if they are already present in case they need to be upgraded.
|
||||
No effect if -NoPrerequisites is specified.
|
||||
.PARAMETER NoRestore
|
||||
Skips the package restore step.
|
||||
Skips the package restore step.
|
||||
.PARAMETER Signing
|
||||
Install the MicroBuild signing plugin for building test-signed builds on desktop machines.
|
||||
Install the MicroBuild signing plugin for building test-signed builds on desktop machines.
|
||||
.PARAMETER Localization
|
||||
Install the MicroBuild localization plugin for building loc builds on desktop machines.
|
||||
The environment is configured to build pseudo-loc for JPN only, but may be used to build
|
||||
all languages with shipping-style loc by using the `/p:loctype=full,loclanguages=vs`
|
||||
when building.
|
||||
Install the MicroBuild localization plugin for building loc builds on desktop machines.
|
||||
The environment is configured to build pseudo-loc for JPN only, but may be used to build
|
||||
all languages with shipping-style loc by using the `/p:loctype=full,loclanguages=vs`
|
||||
when building.
|
||||
.PARAMETER Setup
|
||||
Install the MicroBuild setup plugin for building VSIXv3 packages.
|
||||
Install the MicroBuild setup plugin for building VSIXv3 packages.
|
||||
.PARAMETER OptProf
|
||||
Install the MicroBuild OptProf plugin for building optimized assemblies on desktop machines.
|
||||
Install the MicroBuild OptProf plugin for building optimized assemblies on desktop machines.
|
||||
.PARAMETER AccessToken
|
||||
An optional access token for authenticating to Azure Artifacts authenticated feeds.
|
||||
An optional access token for authenticating to Azure Artifacts authenticated feeds.
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess=$true)]
|
||||
Param (
|
||||
|
@ -118,7 +121,7 @@ try {
|
|||
$EnvVars['LocLanguages'] = "JPN"
|
||||
}
|
||||
|
||||
& "$PSScriptRoot\azure-pipelines\Set-EnvVars.ps1" -Variables $EnvVars | Out-Null
|
||||
& "$PSScriptRoot/tools/Set-EnvVars.ps1" -Variables $EnvVars | Out-Null
|
||||
}
|
||||
catch {
|
||||
Write-Error $error[0]
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<!-- Workaround https://github.com/dotnet/wpf/issues/1718 -->
|
||||
<EmbedUntrackedSources Condition=" '$(UseWPF)' == 'true' ">false</EmbedUntrackedSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)../, Directory.Build.targets))\Directory.Build.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)../, Directory.Build.targets))' != '' " />
|
||||
</Project>
|
||||
|
|
|
@ -38,3 +38,6 @@ dotnet_diagnostic.CA1063.severity = silent
|
|||
|
||||
# CA1816: Dispose methods should call SuppressFinalize
|
||||
dotnet_diagnostic.CA1816.severity = silent
|
||||
|
||||
# CA2007: Consider calling ConfigureAwait on the awaited task
|
||||
dotnet_diagnostic.CA2007.severity = none
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.msbuild" Version="2.8.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
|
||||
<PackageReference Include="coverlet.msbuild" Version="2.9.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Checks whether a given .NET Core runtime is installed.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param (
|
||||
[Parameter()]
|
||||
[ValidateSet('Microsoft.AspNetCore.App','Microsoft.NETCore.App')]
|
||||
[string]$Runtime='Microsoft.NETCore.App',
|
||||
[Parameter(Mandatory=$true)]
|
||||
[Version]$Version
|
||||
)
|
||||
|
||||
$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue
|
||||
if (!$dotnet) {
|
||||
# Nothing is installed.
|
||||
Write-Output $false
|
||||
exit 1
|
||||
}
|
||||
|
||||
Function IsVersionMatch {
|
||||
Param(
|
||||
[Parameter()]
|
||||
$actualVersion
|
||||
)
|
||||
return $actualVersion -and
|
||||
$Version.Major -eq $actualVersion.Major -and
|
||||
$Version.Minor -eq $actualVersion.Minor -and
|
||||
(($Version.Build -eq -1) -or ($Version.Build -eq $actualVersion.Build)) -and
|
||||
(($Version.Revision -eq -1) -or ($Version.Revision -eq $actualVersion.Revision))
|
||||
}
|
||||
|
||||
$installedRuntimes = dotnet --list-runtimes |? { $_.Split()[0] -ieq $Runtime } |% { $v = $null; [Version]::tryparse($_.Split()[1], [ref] $v); $v }
|
||||
$matchingRuntimes = $installedRuntimes |? { IsVersionMatch -actualVersion $_ }
|
||||
if (!$matchingRuntimes) {
|
||||
Write-Output $false
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Output $true
|
||||
exit 0
|
|
@ -0,0 +1,37 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Checks whether the .NET Core SDK required by this repo is installed.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param (
|
||||
)
|
||||
|
||||
$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue
|
||||
if (!$dotnet) {
|
||||
# Nothing is installed.
|
||||
Write-Output $false
|
||||
exit 1
|
||||
}
|
||||
|
||||
# We need to set the current directory so dotnet considers the SDK required by our global.json file.
|
||||
Push-Location "$PSScriptRoot\.."
|
||||
try {
|
||||
dotnet -h 2>&1 | Out-Null
|
||||
if (($LASTEXITCODE -eq 129) -or # On Linux
|
||||
($LASTEXITCODE -eq -2147450751) # On Windows
|
||||
) {
|
||||
# These exit codes indicate no matching SDK exists.
|
||||
Write-Output $false
|
||||
exit 2
|
||||
}
|
||||
|
||||
# The required SDK is already installed!
|
||||
Write-Output $true
|
||||
exit 0
|
||||
} catch {
|
||||
# I don't know why, but on some build agents (e.g. MicroBuild), an exception is thrown from the `dotnet` invocation when a match is not found.
|
||||
Write-Output $false
|
||||
exit 3
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
|
@ -2,24 +2,27 @@
|
|||
|
||||
<#
|
||||
.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.
|
||||
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.
|
||||
.DESCRIPTION
|
||||
This MAY not require elevation, as the SDK and runtimes are installed locally to this repo location,
|
||||
unless `-InstallLocality machine` is specified.
|
||||
This MAY not require elevation, as the SDK and runtimes are installed locally to this repo location,
|
||||
unless `-InstallLocality machine` is specified.
|
||||
.PARAMETER InstallLocality
|
||||
A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
|
||||
Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
|
||||
Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
|
||||
Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
|
||||
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.
|
||||
A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
|
||||
Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
|
||||
Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
|
||||
Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
|
||||
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 Force
|
||||
Installs the preferred .NET SDK and runtime versions even if compatible versions are found to already be installed.
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium')]
|
||||
Param (
|
||||
[ValidateSet('repo','user','machine')]
|
||||
[string]$InstallLocality='user'
|
||||
[string]$InstallLocality='user',
|
||||
[switch]$Force
|
||||
)
|
||||
|
||||
$DotNetInstallScriptRoot = "$PSScriptRoot/../obj/tools"
|
||||
|
@ -98,15 +101,23 @@ if ($InstallLocality -eq 'machine') {
|
|||
$DotNetInstallDir = '/usr/share/dotnet'
|
||||
} else {
|
||||
$restartRequired = $false
|
||||
if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
|
||||
Install-DotNet -Version $sdkVersion
|
||||
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
|
||||
if ($Force -or (-not (& "$PSScriptRoot/Check-DotNetSdk.ps1"))) {
|
||||
if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
|
||||
Install-DotNet -Version $sdkVersion
|
||||
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
|
||||
}
|
||||
} else {
|
||||
Write-Verbose "A .NET SDK version compatible with $sdkVersion is already installed."
|
||||
}
|
||||
|
||||
$runtimeVersions | Get-Unique |% {
|
||||
if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
|
||||
Install-DotNet -Version $_ -Runtime
|
||||
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
|
||||
if ($Force -or (-not (& "$PSScriptRoot/Check-DotNetRuntime.ps1" -Version $_))) {
|
||||
if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
|
||||
Install-DotNet -Version $_ -Runtime
|
||||
$restartRequired = $restartRequired -or ($LASTEXITCODE -eq 3010)
|
||||
}
|
||||
} else {
|
||||
Write-Verbose ".NET runtime $_ is already installed."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,22 +159,38 @@ if (-not (Test-Path $DotNetInstallScriptPath)) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
|
||||
Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches"
|
||||
$anythingInstalled = $false
|
||||
|
||||
if ($Force -or (-not (& "$PSScriptRoot/Check-DotNetSdk.ps1"))) {
|
||||
if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
|
||||
$anythingInstalled = $true
|
||||
Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches"
|
||||
} else {
|
||||
Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches -DryRun"
|
||||
}
|
||||
} else {
|
||||
Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches -DryRun"
|
||||
Write-Verbose "A .NET SDK version compatible with $sdkVersion is already installed."
|
||||
}
|
||||
|
||||
$switches += '-Runtime','dotnet'
|
||||
|
||||
$runtimeVersions | Get-Unique |% {
|
||||
if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
|
||||
Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches"
|
||||
if ($Force -or (-not (& "$PSScriptRoot/Check-DotNetRuntime.ps1" -Version $_))) {
|
||||
if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
|
||||
$anythingInstalled = $true
|
||||
Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches"
|
||||
} else {
|
||||
Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches -DryRun"
|
||||
}
|
||||
} else {
|
||||
Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches -DryRun"
|
||||
Write-Verbose ".NET runtime $_ is already installed."
|
||||
}
|
||||
}
|
||||
|
||||
if ($PSCmdlet.ShouldProcess("Set DOTNET environment variables to discover these installed runtimes?")) {
|
||||
& "$PSScriptRoot/../azure-pipelines/Set-EnvVars.ps1" -Variables $envVars -PrependPath $DotNetInstallDir | Out-Null
|
||||
& "$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."
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ Param (
|
|||
[string]$AccessToken
|
||||
)
|
||||
|
||||
$envVars = @{}
|
||||
|
||||
$toolsPath = & "$PSScriptRoot\..\azure-pipelines\Get-TempToolsPath.ps1"
|
||||
|
||||
if ($IsMacOS -or $IsLinux) {
|
||||
|
@ -66,9 +68,9 @@ if ($AccessToken) {
|
|||
Add-Member -InputObject $auth -MemberType NoteProperty -Name endpointCredentials -Value $endpoints
|
||||
|
||||
$authJson = ConvertTo-Json -InputObject $auth
|
||||
$envVars = @{
|
||||
$envVars += @{
|
||||
'VSS_NUGET_EXTERNAL_FEED_ENDPOINTS'=$authJson;
|
||||
}
|
||||
|
||||
& "$PSScriptRoot\..\azure-pipelines\Set-EnvVars.ps1" -Variables $envVars | Out-Null
|
||||
}
|
||||
|
||||
& "$PSScriptRoot/Set-EnvVars.ps1" -Variables $envVars | Out-Null
|
||||
|
|
|
@ -4,8 +4,13 @@
|
|||
Azure Pipeline and CMD environments are considered.
|
||||
.PARAMETER Variables
|
||||
A hashtable of variables to be set.
|
||||
.PARAMETER PrependPath
|
||||
A set of paths to prepend to the PATH environment variable.
|
||||
.OUTPUTS
|
||||
A boolean indicating whether the environment variables can be expected to propagate to the caller's environment.
|
||||
.DESCRIPTION
|
||||
The CmdEnvScriptPath environment variable may be optionally set to a path to a cmd shell script to be created (or appended to if it already exists) that will set the environment variables in cmd.exe that are set within the PowerShell environment.
|
||||
This is used by init.cmd in order to reapply any new environment variables to the parent cmd.exe process that were set in the powershell child process.
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess=$true)]
|
||||
Param(
|
||||
|
@ -18,7 +23,7 @@ if ($Variables.Count -eq 0) {
|
|||
return $true
|
||||
}
|
||||
|
||||
$cmdInstructions = !$env:TF_BUILD -and !$env:GITHUB_ACTIONS -and $env:PS1UnderCmd -eq '1'
|
||||
$cmdInstructions = !$env:TF_BUILD -and !$env:GITHUB_ACTIONS -and !$env:CmdEnvScriptPath -and ($env:PS1UnderCmd -eq '1')
|
||||
if ($cmdInstructions) {
|
||||
Write-Warning "Environment variables have been set that will be lost because you're running under cmd.exe"
|
||||
Write-Host "Environment variables that must be set manually:" -ForegroundColor Blue
|
||||
|
@ -38,6 +43,7 @@ if ($env:GITHUB_ACTIONS) {
|
|||
Write-Host "GitHub Actions detected. Logging commands will be used to propagate environment variables and prepend path."
|
||||
}
|
||||
|
||||
$CmdEnvScript = ''
|
||||
$Variables.GetEnumerator() |% {
|
||||
Set-Item -Path env:$($_.Key) -Value $_.Value
|
||||
|
||||
|
@ -52,6 +58,8 @@ $Variables.GetEnumerator() |% {
|
|||
if ($cmdInstructions) {
|
||||
Write-Host "SET $($_.Key)=$($_.Value)"
|
||||
}
|
||||
|
||||
$CmdEnvScript += "SET $($_.Key)=$($_.Value)`r`n"
|
||||
}
|
||||
|
||||
$pathDelimiter = ';'
|
||||
|
@ -73,7 +81,17 @@ if ($PrependPath) {
|
|||
if ($env:GITHUB_ACTIONS) {
|
||||
Write-Host "::add-path::$_"
|
||||
}
|
||||
|
||||
$CmdEnvScript += "SET PATH=$_$pathDelimiter%PATH%"
|
||||
}
|
||||
}
|
||||
|
||||
if ($env:CmdEnvScriptPath) {
|
||||
if (Test-Path $env:CmdEnvScriptPath) {
|
||||
$CmdEnvScript = (Get-Content -Path $env:CmdEnvScriptPath) + $CmdEnvScript
|
||||
}
|
||||
|
||||
Set-Content -Path $env:CmdEnvScriptPath -Value $CmdEnvScript
|
||||
}
|
||||
|
||||
return !$cmdInstructions
|
Загрузка…
Ссылка в новой задаче