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

Commit 18a920c

Browse files
committed
Added build scripts and strong name keys
1 parent 8a31de5 commit 18a920c

File tree

9 files changed

+176
-0
lines changed

9 files changed

+176
-0
lines changed

AsyncUsageAnalyzers.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1616
README.md = README.md
1717
EndProjectSection
1818
EndProject
19+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{11D3EB88-A10D-4E48-A9F0-D98E6BF9B65C}"
20+
ProjectSection(SolutionItems) = preProject
21+
build\build.ps1 = build\build.ps1
22+
build\check-key.ps1 = build\check-key.ps1
23+
build\keys.ps1 = build\keys.ps1
24+
build\push.ps1 = build\push.ps1
25+
build\version.ps1 = build\version.ps1
26+
EndProjectSection
27+
EndProject
1928
Global
2029
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2130
Debug|Any CPU = Debug|Any CPU

AsyncUsageAnalyzers/AsyncUsageAnalyzers/AsyncUsageAnalyzers.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
<ErrorReport>prompt</ErrorReport>
3333
<WarningLevel>4</WarningLevel>
3434
</PropertyGroup>
35+
<PropertyGroup>
36+
<SignAssembly>true</SignAssembly>
37+
</PropertyGroup>
38+
<PropertyGroup>
39+
<AssemblyOriginatorKeyFile Condition="'$(KeyConfiguration)' == 'Final'">..\..\build\keys\AsyncUsageAnalyzers.snk</AssemblyOriginatorKeyFile>
40+
<AssemblyOriginatorKeyFile Condition="'$(KeyConfiguration)' != 'Final'">..\..\build\keys\AsyncUsageAnalyzers.dev.snk</AssemblyOriginatorKeyFile>
41+
</PropertyGroup>
3542
<ItemGroup>
3643
<Compile Include="CodeFixProvider.cs" />
3744
<Compile Include="DiagnosticAnalyzer.cs" />
@@ -49,6 +56,12 @@
4956
</EmbeddedResource>
5057
</ItemGroup>
5158
<ItemGroup>
59+
<None Include="..\..\build\keys\AsyncUsageAnalyzers.dev.snk">
60+
<Link>AsyncUsageAnalyzers.dev.snk</Link>
61+
</None>
62+
<None Include="..\..\build\keys\AsyncUsageAnalyzers.snk">
63+
<Link>AsyncUsageAnalyzers.snk</Link>
64+
</None>
5265
<NuGetManifest Include="AsyncUsageAnalyzers.nuspec">
5366
<SubType>Designer</SubType>
5467
<Symbols>True</Symbols>

build/build.ps1

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
param (
2+
[switch]$Debug,
3+
[string]$VisualStudioVersion = '14.0',
4+
[switch]$SkipKeyCheck,
5+
[string]$Verbosity = 'normal',
6+
[string]$Logger
7+
)
8+
9+
# build the solution
10+
$SolutionPath = "..\AsyncUsageAnalyzers.sln"
11+
12+
# make sure the script was run from the expected path
13+
if (!(Test-Path $SolutionPath)) {
14+
$host.ui.WriteErrorLine('The script was run from an invalid working directory.')
15+
exit 1
16+
}
17+
18+
. .\version.ps1
19+
20+
If ($Debug) {
21+
$BuildConfig = 'Debug'
22+
} Else {
23+
$BuildConfig = 'Release'
24+
}
25+
26+
If ($Version.Contains('-')) {
27+
$KeyConfiguration = 'Dev'
28+
} Else {
29+
$KeyConfiguration = 'Final'
30+
}
31+
32+
# download NuGet.exe if necessary
33+
$nuget = '..\.nuget\NuGet.exe'
34+
If (-not (Test-Path $nuget)) {
35+
If (-not (Test-Path '..\.nuget')) {
36+
mkdir '..\.nuget'
37+
}
38+
39+
$nugetSource = 'http://nuget.org/nuget.exe'
40+
Invoke-WebRequest $nugetSource -OutFile $nuget
41+
If (-not $?) {
42+
$host.ui.WriteErrorLine('Unable to download NuGet executable, aborting!')
43+
exit $LASTEXITCODE
44+
}
45+
}
46+
47+
# build the main project
48+
$msbuild = "${env:ProgramFiles(x86)}\MSBuild\$VisualStudioVersion\Bin\MSBuild.exe"
49+
50+
# Attempt to restore packages up to 3 times, to improve resiliency to connection timeouts and access denied errors.
51+
$maxAttempts = 3
52+
For ($attempt = 0; $attempt -lt $maxAttempts; $attempt++) {
53+
&$nuget 'restore' $SolutionPath
54+
If ($?) {
55+
Break
56+
} ElseIf (($attempt + 1) -eq $maxAttempts) {
57+
$host.ui.WriteErrorLine('Failed to restore required NuGet packages, aborting!')
58+
exit $LASTEXITCODE
59+
}
60+
}
61+
62+
If ($Logger) {
63+
$LoggerArgument = "/logger:$Logger"
64+
}
65+
66+
&$msbuild '/nologo' '/m' '/nr:false' '/t:rebuild' $LoggerArgument "/verbosity:$Verbosity" "/p:Configuration=$BuildConfig" "/p:VisualStudioVersion=$VisualStudioVersion" "/p:KeyConfiguration=$KeyConfiguration" $SolutionPath
67+
If (-not $?) {
68+
$host.ui.WriteErrorLine('Build failed, aborting!')
69+
exit $LASTEXITCODE
70+
}
71+
72+
# By default, do not create a NuGet package unless the expected strong name key files were used
73+
if (-not $SkipKeyCheck) {
74+
. .\keys.ps1
75+
76+
foreach ($pair in $Keys.GetEnumerator()) {
77+
$assembly = Resolve-FullPath -Path "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.dll"
78+
# Run the actual check in a separate process or the current process will keep the assembly file locked
79+
powershell -Command ".\check-key.ps1 -Assembly '$assembly' -ExpectedKey '$($pair.Value)' -Build '$($pair.Key)'"
80+
If (-not $?) {
81+
$host.ui.WriteErrorLine('Failed to verify strong name key for build, aborting!')
82+
exit $LASTEXITCODE
83+
}
84+
}
85+
}
86+
87+
if (-not (Test-Path 'nuget')) {
88+
mkdir "nuget"
89+
}
90+
91+
Copy-Item "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.$Version.nupkg" 'nuget'
92+
Copy-Item "..\AsyncUsageAnalyzers\AsyncUsageAnalyzers\bin\$BuildConfig\AsyncUsageAnalyzers.$Version.symbols.nupkg" 'nuget'

build/check-key.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
param(
2+
[string]$Assembly,
3+
[string]$ExpectedKey,
4+
[string]$Build = $null
5+
)
6+
7+
function Get-PublicKeyToken() {
8+
param([string]$assembly = $null)
9+
if ($assembly) {
10+
$bytes = $null
11+
$bytes = [System.Reflection.Assembly]::ReflectionOnlyLoadFrom($assembly).GetName().GetPublicKeyToken()
12+
if ($bytes) {
13+
$key = ""
14+
for ($i=0; $i -lt $bytes.Length; $i++) {
15+
$key += "{0:x2}" -f $bytes[$i]
16+
}
17+
18+
$key
19+
}
20+
}
21+
}
22+
23+
if (-not $Build) {
24+
$Build = $Assembly
25+
}
26+
27+
$actual = Get-PublicKeyToken -assembly $Assembly
28+
if ($actual -ne $ExpectedKey) {
29+
$host.ui.WriteErrorLine("Invalid publicKeyToken for '$Build'; expected '$ExpectedKey' but found '$actual'")
30+
exit 1
31+
}

build/keys.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Note: these values may only change during major release
2+
3+
If ($Version.Contains('-')) {
4+
5+
# Use the development keys
6+
$Keys = @{
7+
'portable-net45' = '71b21a4aa82ae3b3'
8+
}
9+
10+
} Else {
11+
12+
# Use the final release keys
13+
$Keys = @{
14+
'portable-net45' = '2d9feb668c6a0e40'
15+
}
16+
17+
}
18+
19+
function Resolve-FullPath() {
20+
param([string]$Path)
21+
[System.IO.Path]::GetFullPath((Join-Path (pwd) $Path))
22+
}
596 Bytes
Binary file not shown.

build/keys/AsyncUsageAnalyzers.snk

596 Bytes
Binary file not shown.

build/push.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
. .\version.ps1
2+
3+
If ($Version.EndsWith('-dev')) {
4+
$host.ui.WriteErrorLine("Cannot push development version '$Version' to NuGet.")
5+
Exit 1
6+
}
7+
8+
..\.nuget\NuGet.exe 'push' ".\nuget\AsyncUsageAnalyzers.$Version.nupkg"

build/version.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$Version = "1.0.0-dev"

0 commit comments

Comments
 (0)