Skip to content

Commit f707f60

Browse files
committed
Add init script and more contributing guidance
Fixes #85
1 parent 944cc78 commit f707f60

5 files changed

Lines changed: 95 additions & 5 deletions

File tree

CONTRIBUTING.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,36 @@ All other dependencies are acquired via NuGet.
1414

1515
## Building
1616

17-
To build this repository from the command line, you must first execute a complete NuGet package restore.
17+
To build this repository from the command line, you must first execute our init.ps1 script,
18+
which downloads NuGet 3.3.0 and uses it to restore packages.
1819
Assuming your working directory is the root directory of this git repo, the command is:
1920

20-
nuget restore src
21-
22-
You may need to [download NuGet.exe][NuGetClient] first. **Be sure to use nuget.exe 3.3.0** rather than
23-
3.4.4 or any version in between because these newer versions have regressions that break the build.
21+
.\init
2422

2523
Everything in the repo may be built via building the solution file
2624
either from Visual Studio 2015 or the command line:
2725

2826
msbuild src\ImmutableObjectGraph.sln
2927

28+
### Important notice when developing with Visual Studio
29+
30+
The NuGet package restore functionality in Visual Studio does not work for this project, which relies
31+
on newer functionality than comes with Visual Studio 2015 Update 3. You should disable automatic
32+
package restore on build in Visual Studio in order to build successfully and have a useful Error List
33+
while developing.
34+
35+
Follow these steps to disable automatic package restore in Visual Studio:
36+
37+
1. Tools -> Options -> NuGet Package Manager -> General
38+
2. *Clear* the checkbox for "Automatically check for missing packages during build in Visual Studio
39+
40+
With this setting, you can still execute a package restore within Visual Studio by right-clicking
41+
on the _solution_ node in Solution Explorer and clicking "Restore NuGet Packages". But do not ever
42+
execute that on this project as that will corrupt the result of `init.ps1`.
43+
44+
Before developing this project in Visual Studio, or after making project or project.json changes,
45+
or to recover after Visual Studio executes a package restore, run the `init` script again.
46+
3047
## Testing
3148

3249
The Visual Studio 2015 Test Explorer will list and execute all tests.

init.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
powershell.exe -ExecutionPolicy bypass -Command "& '%~dpn0.ps1'" %*

init.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<#
2+
.SYNOPSIS
3+
Prepares a machine to build and test this project.
4+
#>
5+
Param(
6+
)
7+
8+
Push-Location $PSScriptRoot
9+
try {
10+
$toolsPath = "$PSScriptRoot\tools"
11+
12+
# First restore NuProj packages since the solution restore depends on NuProj evaluation succeeding.
13+
gci "$PSScriptRoot\src\project.json" -rec |? { $_.FullName -imatch 'nuget' } |% {
14+
& "$toolsPath\Restore-NuGetPackages.ps1" -Path $_ -Verbosity quiet
15+
}
16+
17+
& "$toolsPath\Restore-NuGetPackages.ps1" -Path "$PSScriptRoot\src" -Verbosity quiet
18+
19+
Write-Host "Successfully restored all dependencies" -ForegroundColor Green
20+
}
21+
catch {
22+
Write-Error "Aborting script due to error"
23+
exit $lastexitcode
24+
}
25+
finally {
26+
Pop-Location
27+
}

tools/Get-NuGetTool.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<#
2+
.SYNOPSIS
3+
Downloads the NuGet.exe tool and returns the path to it.
4+
#>
5+
6+
function Expand-ZIPFile($file, $destination) {
7+
if (!(Test-Path $destination)) { $null = mkdir $destination }
8+
$shell = new-object -com shell.application
9+
$zip = $shell.NameSpace((Resolve-Path $file).Path)
10+
foreach ($item in $zip.items()) {
11+
$shell.Namespace((Resolve-Path $destination).Path).copyhere($item)
12+
}
13+
}
14+
15+
$binaryToolsPath = "$PSScriptRoot\..\obj\tools"
16+
if (!(Test-Path $binaryToolsPath)) { $null = mkdir $binaryToolsPath }
17+
$nugetPath = "$binaryToolsPath\nuget.exe"
18+
if (!(Test-Path $nugetPath)) {
19+
$NuGetVersion = "3.3.0"
20+
Write-Host "Downloading nuget.exe $NuGetVersion..." -ForegroundColor Yellow
21+
Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/v$NuGetVersion/nuget.exe" -OutFile $nugetPath
22+
}
23+
24+
$nugetPath

tools/Restore-NuGetPackages.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<#
2+
.SYNOPSIS
3+
Restores NuGet packages.
4+
.PARAMETER Path
5+
The path of the solution, directory, packages.config or project.json file to restore packages from.
6+
If not specified, the current directory is used.
7+
.PARAMETER Verbosity
8+
#>
9+
Param(
10+
[Parameter(Position=1)]
11+
[string]$Path=(Get-Location),
12+
[Parameter()]
13+
[ValidateSet('Quiet','Normal','Detailed')]
14+
[string]$Verbosity='normal'
15+
)
16+
17+
$nugetPath = & "$PSScriptRoot\Get-NuGetTool.ps1"
18+
19+
Write-Host "Restoring NuGet packages for $Path" -ForegroundColor Yellow
20+
& $nugetPath restore $Path -MSBuildVersion 14.0 -Verbosity $Verbosity
21+
if ($lastexitcode -ne 0) { throw }

0 commit comments

Comments
 (0)