Skip to content

Commit

Permalink
Add MicroBuild packages to enable signing and more
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Jul 22, 2019
1 parent 194cdc9 commit 4ec792f
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
## Features

* Follow the best and simplest patterns of build, pack and test with dotnet CLI.
* MicroBuild signing built-in, with several more MicroBuild plugins' use streamlined for local installation.
* Insertions to VS streamlined and automated with all inputs computed during the build and saved for the release pipeline.
* Static analyzers: [FxCop](https://docs.microsoft.com/en-us/visualstudio/code-quality/fxcop-analyzers?view=vs-2019) and [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers)
* Read-only source tree (builds to top-level bin/obj folders)
* Auto-versioning (via [Nerdbank.GitVersioning](https://github.com/aarnott/nerdbank.gitversioning))
Expand Down
50 changes: 50 additions & 0 deletions azure-pipelines/Install-NuGetPackage.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<#
.SYNOPSIS
Installs a NuGet package.
.PARAMETER PackageID
The Package ID to install.
.PARAMETER Version
The version of the package to install. If unspecified, the latest stable release is installed.
.PARAMETER Source
The package source feed to find the package to install from.
.PARAMETER PackagesDir
The directory to install the package to. By default, it uses the Packages folder at the root of the repo.
.PARAMETER ConfigFile
The nuget.config file to use. By default, it uses :/nuget.config.
#>
[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Low')]
Param(
[Parameter(Position=1,Mandatory=$true)]
[string]$PackageId,
[Parameter()]
[string]$Version,
[Parameter()]
[string]$Source,
[Parameter()]
[switch]$Prerelease,
[Parameter()]
[string]$PackagesDir="$PSScriptRoot\..\packages",
[Parameter()]
[string]$ConfigFile="$PSScriptRoot\..\nuget.config",
[Parameter()]
[ValidateSet('Quiet','Normal','Detailed')]
[string]$Verbosity='normal'
)

$nugetPath = & "$PSScriptRoot\Get-NuGetTool.ps1"

try {
Write-Verbose "Installing $PackageId..."
$nugetArgs = "Install",$PackageId,"-OutputDirectory",$PackagesDir,'-ConfigFile',$ConfigFile
if ($Version) { $nugetArgs += "-Version",$Version }
if ($Source) { $nugetArgs += "-FallbackSource",$Source }
if ($Prerelease) { $nugetArgs += "-Prerelease" }
$nugetArgs += '-Verbosity',$Verbosity

if ($PSCmdlet.ShouldProcess($PackageId, 'nuget install')) {
$p = Start-Process $nugetPath $nugetArgs -NoNewWindow -Wait -PassThru
if ($p.ExitCode -ne 0) { throw }
}
} finally {
Pop-Location
}
10 changes: 10 additions & 0 deletions azure-pipelines/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
steps:
# We use VSBuild instead of "dotnet build" on Windows where MicroBuild tasks have to run (since they don't support MSBuild Core yet).
- task: VSBuild@1
displayName: Build Visual Studio solution
inputs:
msbuildArgs: /t:build,pack /m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/msbuild.binlog"
platform: Any CPU
configuration: $(BuildConfiguration)
condition: eq(variables['Agent.OS'], 'Windows_NT')

- script: dotnet build --no-restore -c $(BuildConfiguration) /v:m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/build.binlog"
displayName: dotnet build
workingDirectory: src
condition: ne(variables['Agent.OS'], 'Windows_NT')

- script: dotnet pack --no-build -c $(BuildConfiguration) /v:m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/pack.binlog"
displayName: dotnet pack
workingDirectory: src
condition: ne(variables['Agent.OS'], 'Windows_NT')

- task: DotNetCoreCLI@2
displayName: dotnet test -f net472
Expand Down
15 changes: 14 additions & 1 deletion azure-pipelines/expand-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ steps:
displayName: Expanding template
failOnStderr: true
# TODO: Verify that all changes are staged to the git index

- powershell: .\init.ps1
displayName: Install prereqs and restore packages

- task: VSBuild@1
displayName: Build Visual Studio solution (expanded template)
inputs:
msbuildArgs: /t:build,pack /m
platform: Any CPU
configuration: $(BuildConfiguration)
condition: eq(variables['Agent.OS'], 'Windows_NT')

- script: dotnet build
workingDirectory: src
displayName: dotnet build (expanded template)
workingDirectory: src
condition: ne(variables['Agent.OS'], 'Windows_NT')
56 changes: 56 additions & 0 deletions init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ Per-repo can lead to file locking issues when dotnet.exe is left running as a bu
Skips the installation of prerequisite software (e.g. SDKs, tools).
.PARAMETER NoRestore
Skips the package restore step.
.PARAMETER Signing
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.
.PARAMETER Setup
Install the MicroBuild setup plugin for building VSIXv3 packages.
.PARAMETER OptProf
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.
#>
Expand All @@ -25,6 +36,14 @@ Param (
[Parameter()]
[switch]$NoRestore,
[Parameter()]
[switch]$Signing,
[Parameter()]
[switch]$Localization,
[Parameter()]
[switch]$Setup,
[Parameter()]
[switch]$OptProf,
[Parameter()]
[string]$AccessToken
)

Expand All @@ -44,6 +63,43 @@ try {
throw "Failure while restoring packages."
}
}

$EnvVars = @{}
$InstallNuGetPkgScriptPath = ".\azure-pipelines\Install-NuGetPackage.ps1"
$nugetVerbosity = 'quiet'
if ($Verbose) { $nugetVerbosity = 'normal' }
$MicroBuildPackageSource = 'https://devdiv.pkgs.visualstudio.com/DefaultCollection/_packaging/MicroBuildToolset/nuget/v3/index.json'
if ($Signing) {
Write-Host "Installing MicroBuild signing plugin" -ForegroundColor $HeaderColor
& $InstallNuGetPkgScriptPath MicroBuild.Plugins.Signing -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
$EnvVars['SignType'] = "Test"
}

if ($Setup) {
Write-Host "Installing MicroBuild SwixBuild plugin..." -ForegroundColor $HeaderColor
& $InstallNuGetPkgScriptPath MicroBuild.Plugins.SwixBuild -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
}

if ($OptProf) {
Write-Host "Installing MicroBuild OptProf plugin" -ForegroundColor $HeaderColor
& $InstallNuGetPkgScriptPath MicroBuild.Plugins.OptProf -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
$EnvVars['OptProfEnabled'] = '1'
}

if ($Localization) {
Write-Host "Installing MicroBuild localization plugin" -ForegroundColor $HeaderColor
& $InstallNuGetPkgScriptPath MicroBuild.Plugins.Localization -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
$EnvVars['LocType'] = "Pseudo"
$EnvVars['LocLanguages'] = "JPN"
}

if ($FxCop) {
Write-Host "Installing MicroBuild FxCop plugin" -ForegroundColor $HeaderColor
& $InstallNuGetPkgScriptPath MicroBuild.Plugins.FxCop -source $MicroBuildPackageSource -Verbosity $nugetVerbosity
$EnvVars['MicroBuild_FXCop'] = "true"
}

& ".\azure-pipelines\Set-EnvVars.ps1" -Variables $EnvVars
}
catch {
Write-Error $error[0]
Expand Down
5 changes: 5 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="vs-impl" value="https://pkgs.dev.azure.com/devdiv/_packaging/vs-impl/nuget/v3/index.json" protocolVersion="3" />

<!-- These next two should eventually be upstreams of the private vs-impl above, but until then... -->
<add key="vs-impl-public" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json" protocolVersion="3" />
<add key="vssdk-public" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MicroBuild.VisualStudio" Version="2.0.55" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0-preview.2" PrivateAssets="All" />
<!-- <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19351-01" PrivateAssets="All" /> -->
Expand Down
1 change: 1 addition & 0 deletions src/Library.Tests/Library.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MicroBuild.NonShipping" Version="2.0.55" />
<PackageReference Include="coverlet.msbuild" Version="2.6.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down

0 comments on commit 4ec792f

Please sign in to comment.