Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Commit

Permalink
Added build scripts and strong name keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed May 3, 2015
1 parent 8a31de5 commit 18a920c
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 0 deletions.
9 changes: 9 additions & 0 deletions AsyncUsageAnalyzers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{11D3EB88-A10D-4E48-A9F0-D98E6BF9B65C}"
ProjectSection(SolutionItems) = preProject
build\build.ps1 = build\build.ps1
build\check-key.ps1 = build\check-key.ps1
build\keys.ps1 = build\keys.ps1
build\push.ps1 = build\push.ps1
build\version.ps1 = build\version.ps1
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
13 changes: 13 additions & 0 deletions AsyncUsageAnalyzers/AsyncUsageAnalyzers/AsyncUsageAnalyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile Condition="'$(KeyConfiguration)' == 'Final'">..\..\build\keys\AsyncUsageAnalyzers.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile Condition="'$(KeyConfiguration)' != 'Final'">..\..\build\keys\AsyncUsageAnalyzers.dev.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="CodeFixProvider.cs" />
<Compile Include="DiagnosticAnalyzer.cs" />
Expand All @@ -49,6 +56,12 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="..\..\build\keys\AsyncUsageAnalyzers.dev.snk">
<Link>AsyncUsageAnalyzers.dev.snk</Link>
</None>
<None Include="..\..\build\keys\AsyncUsageAnalyzers.snk">
<Link>AsyncUsageAnalyzers.snk</Link>
</None>
<NuGetManifest Include="AsyncUsageAnalyzers.nuspec">
<SubType>Designer</SubType>
<Symbols>True</Symbols>
Expand Down
92 changes: 92 additions & 0 deletions build/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
param (
[switch]$Debug,
[string]$VisualStudioVersion = '14.0',
[switch]$SkipKeyCheck,
[string]$Verbosity = 'normal',
[string]$Logger
)

# build the solution
$SolutionPath = "..\AsyncUsageAnalyzers.sln"

# make sure the script was run from the expected path
if (!(Test-Path $SolutionPath)) {
$host.ui.WriteErrorLine('The script was run from an invalid working directory.')
exit 1
}

. .\version.ps1

If ($Debug) {
$BuildConfig = 'Debug'
} Else {
$BuildConfig = 'Release'
}

If ($Version.Contains('-')) {
$KeyConfiguration = 'Dev'
} Else {
$KeyConfiguration = 'Final'
}

# download NuGet.exe if necessary
$nuget = '..\.nuget\NuGet.exe'
If (-not (Test-Path $nuget)) {
If (-not (Test-Path '..\.nuget')) {
mkdir '..\.nuget'
}

$nugetSource = 'http://nuget.org/nuget.exe'
Invoke-WebRequest $nugetSource -OutFile $nuget
If (-not $?) {
$host.ui.WriteErrorLine('Unable to download NuGet executable, aborting!')
exit $LASTEXITCODE
}
}

# build the main project
$msbuild = "${env:ProgramFiles(x86)}\MSBuild\$VisualStudioVersion\Bin\MSBuild.exe"

# Attempt to restore packages up to 3 times, to improve resiliency to connection timeouts and access denied errors.
$maxAttempts = 3
For ($attempt = 0; $attempt -lt $maxAttempts; $attempt++) {
&$nuget 'restore' $SolutionPath
If ($?) {
Break
} ElseIf (($attempt + 1) -eq $maxAttempts) {
$host.ui.WriteErrorLine('Failed to restore required NuGet packages, aborting!')
exit $LASTEXITCODE
}
}

If ($Logger) {
$LoggerArgument = "/logger:$Logger"
}

&$msbuild '/nologo' '/m' '/nr:false' '/t:rebuild' $LoggerArgument "/verbosity:$Verbosity" "/p:Configuration=$BuildConfig" "/p:VisualStudioVersion=$VisualStudioVersion" "/p:KeyConfiguration=$KeyConfiguration" $SolutionPath
If (-not $?) {
$host.ui.WriteErrorLine('Build failed, aborting!')
exit $LASTEXITCODE
}

# By default, do not create a NuGet package unless the expected strong name key files were used
if (-not $SkipKeyCheck) {
. .\keys.ps1

foreach ($pair in $Keys.GetEnumerator()) {
$assembly = Resolve-FullPath -Path "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.dll"
# Run the actual check in a separate process or the current process will keep the assembly file locked
powershell -Command ".\check-key.ps1 -Assembly '$assembly' -ExpectedKey '$($pair.Value)' -Build '$($pair.Key)'"
If (-not $?) {
$host.ui.WriteErrorLine('Failed to verify strong name key for build, aborting!')
exit $LASTEXITCODE
}
}
}

if (-not (Test-Path 'nuget')) {
mkdir "nuget"
}

Copy-Item "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.$Version.nupkg" 'nuget'
Copy-Item "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.$Version.symbols.nupkg" 'nuget'
31 changes: 31 additions & 0 deletions build/check-key.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
param(
[string]$Assembly,
[string]$ExpectedKey,
[string]$Build = $null
)

function Get-PublicKeyToken() {
param([string]$assembly = $null)
if ($assembly) {
$bytes = $null
$bytes = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($assembly).GetName().GetPublicKeyToken()
if ($bytes) {
$key = ""
for ($i=0; $i -lt $bytes.Length; $i++) {
$key += "{0:x2}" -f $bytes[$i]
}

$key
}
}
}

if (-not $Build) {
$Build = $Assembly
}

$actual = Get-PublicKeyToken -assembly $Assembly
if ($actual -ne $ExpectedKey) {
$host.ui.WriteErrorLine("Invalid publicKeyToken for '$Build'; expected '$ExpectedKey' but found '$actual'")
exit 1
}
22 changes: 22 additions & 0 deletions build/keys.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Note: these values may only change during major release

If ($Version.Contains('-')) {

# Use the development keys
$Keys = @{
'portable-net45' = '71b21a4aa82ae3b3'
}

} Else {

# Use the final release keys
$Keys = @{
'portable-net45' = '2d9feb668c6a0e40'
}

}

function Resolve-FullPath() {
param([string]$Path)
[System.IO.Path]::GetFullPath((Join-Path (pwd) $Path))
}
Binary file added build/keys/AsyncUsageAnalyzers.dev.snk
Binary file not shown.
Binary file added build/keys/AsyncUsageAnalyzers.snk
Binary file not shown.
8 changes: 8 additions & 0 deletions build/push.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
. .\version.ps1

If ($Version.EndsWith('-dev')) {
$host.ui.WriteErrorLine("Cannot push development version '$Version' to NuGet.")
Exit 1
}

..\.nuget\NuGet.exe 'push' ".\nuget\AsyncUsageAnalyzers.$Version.nupkg"
1 change: 1 addition & 0 deletions build/version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Version = "1.0.0-dev"

0 comments on commit 18a920c

Please sign in to comment.