Skip to content

Commit b3e7d83

Browse files
committed
Merge origin/master into fixLinuxMono
2 parents eaa0c2f + 7250cec commit b3e7d83

26 files changed

+366
-51
lines changed

CONTRIBUTING.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
Contributing to this project
2+
============================
3+
4+
## Prerequisites
5+
6+
This project is actively developed using the following software.
7+
It is highly recommended that anyone contributing to this library use the same
8+
software.
9+
10+
1. [Visual Studio 2015][VS]
11+
2. [Node.js][NodeJs]
12+
13+
### Optional additional software
14+
15+
Some projects in the Visual Studio solution require optional or 3rd party components to open.
16+
They are not required to build the full solution from the command line using MSBuild,
17+
but installing this software will facilitate an enhanced developer experience in Visual Studio.
18+
19+
1. [Node.js Tools for Visual Studio][NodeJsTools]
20+
2. [NuProj for VS2015][NuProj]
21+
22+
All other dependencies are acquired via NuGet or NPM.
23+
24+
## Building
25+
26+
To build this repository from the command line, you must first execute our init.ps1 script,
27+
which downloads NuGet.exe and uses it to restore packages.
28+
Assuming your working directory is the root directory of this git repo,
29+
and you are running Windows PowerShell, the command is:
30+
31+
.\init.ps1
32+
33+
Everything in the repo may be built via building the solution file
34+
either from Visual Studio 2015 or the VS2015 Developer Command Prompt:
35+
36+
.\build.ps1
37+
38+
This repo is structured such that it builds the NuGet package first, using MSBuild.
39+
It then builds an NPM package that includes some of the outputs of MSBuild, along with
40+
some javascript, for our NPM consumers who want a reasonable versioning story for their
41+
NPM packages too.
42+
43+
### Important notice when developing with Visual Studio
44+
45+
The NuGet package restore functionality in Visual Studio does not work for this project, which relies
46+
on newer functionality than comes with Visual Studio 2015 Update 3. You should disable automatic
47+
package restore on build in Visual Studio in order to build successfully and have a useful Error List
48+
while developing.
49+
50+
Follow these steps to disable automatic package restore in Visual Studio:
51+
52+
1. Tools -> Options -> NuGet Package Manager -> General
53+
2. *Clear* the checkbox for "Automatically check for missing packages during build in Visual Studio
54+
55+
With this setting, you can still execute a package restore within Visual Studio by right-clicking
56+
on the _solution_ node in Solution Explorer and clicking "Restore NuGet Packages". But do not ever
57+
execute that on this project as that will corrupt the result of `init.ps1`.
58+
59+
Before developing this project in Visual Studio, or after making project or project.json changes,
60+
or to recover after Visual Studio executes a package restore, run the `init` script again.
61+
62+
## Testing
63+
64+
The Visual Studio 2015 Test Explorer will list and execute all tests.
65+
66+
## Pull requests
67+
68+
Pull requests are welcome! They may contain additional test cases (e.g. to demonstrate a failure),
69+
and/or product changes (with bug fixes or features). All product changes should be accompanied by
70+
additional tests to cover and justify the product change unless the product change is strictly an
71+
efficiency improvement and no outwardly observable change is expected.
72+
73+
In the master branch, all tests should always pass. Added tests that fail should be marked as Skip
74+
via `[Fact(Skip = "Test does not pass yet")]` or similar message to keep our test pass rate at 100%.
75+
76+
## Self-service releases for contributors
77+
78+
As soon as you send a pull request, a build is executed and updated NuGet packages
79+
are published to this Package Feed:
80+
81+
https://ci.appveyor.com/nuget/nerdbank-gitversioning
82+
83+
By adding this URL to your package sources you can immediately install your version
84+
of the NuGet packages to your project. This can be done by adding a nuget.config file
85+
with the following content to the root of your project's repo:
86+
87+
```xml
88+
<?xml version="1.0" encoding="utf-8"?>
89+
<configuration>
90+
<packageSources>
91+
<add key="Nerdbank.GitVersioning CI" value="https://ci.appveyor.com/nuget/nerdbank-gitversioning" />
92+
</packageSources>
93+
</configuration>
94+
```
95+
96+
You can then install the package(s) while you have your new "Nerdbank.GitVersioning CI" package source selected:
97+
98+
```powershell
99+
Install-Package Nerdbank.GitVersioning -Pre -Version 0.1.41-g02f355c05d
100+
```
101+
102+
Take care to set the package version such that it exactly matches the AppVeyor build
103+
for your pull request. You can get the version number by reviewing the result of the
104+
validation build for your pull request, clicking ARTIFACTS, and noting the version
105+
of the produced packages.
106+
107+
[VS]: https://www.visualstudio.com/en-us/downloads/visual-studio-2015-downloads-vs.aspx
108+
[NodeJs]: https://nodejs.org
109+
[NuProj]: https://onedrive.live.com/redir?resid=63D0C265F96E43D!2477835&authkey=!AHh2k9FoNR-nFHo&ithint=file%2cmsi
110+
[NodeJsTools]: https://www.visualstudio.com/vs/node-js/
111+
[NuGetClient]: https://dist.nuget.org/win-x86-commandline/v3.3.0/nuget.exe

LICENSE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) Microsoft Corporation
3+
Copyright (c) Andrew Arnott
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
SOFTWARE.

appveyor.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ environment:
1515
secure: Ql19CstT9GvFNeSIAjXvgHXZg+/pNaYJ2jVkzde4LT2vwSyjiQgQ+M332wVYtu+r
1616
install:
1717
- ps: >-
18-
iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/install-nuget-3-3-0.ps1'))
19-
2018
npm install npm -g
2119
before_build:
2220
- ps: >-

build.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'" %*

build.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ The project configuration to build.
88
Param(
99
[Parameter()]
1010
[ValidateSet('Debug', 'Release')]
11-
[string]$Configuration
11+
[string]$Configuration,
12+
13+
[Parameter()]
14+
[ValidateSet('minimal', 'normal', 'detailed', 'diagnostic')]
15+
[string]$MsBuildVerbosity = 'minimal'
1216
)
1317

14-
$msbuildCommandLine = "msbuild `"$PSScriptRoot\src\Nerdbank.GitVersioning.sln`" /m /verbosity:minimal /nologo"
18+
$msbuildCommandLine = "msbuild `"$PSScriptRoot\src\Nerdbank.GitVersioning.sln`" /m /verbosity:$MsBuildVerbosity /nologo /p:Platform=`"Any CPU`""
1519

1620
if (Test-Path "C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll") {
1721
$msbuildCommandLine += " /logger:`"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll`""

doc/node.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See [NPM acquisition](npm-acquisition.md).
88

99
```js
1010
var nbgv = require('nerdbank-gitversioning')
11-
nbgv.getGitVersion()
11+
nbgv.getVersion()
1212
.then(r => console.log(r))
1313
.catch(e => console.error(e));
1414
```

init.cmd

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

init.ps1

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,41 @@ Restores all NuGet, NPM and Typings packages necessary to build this repository.
66
Param(
77
)
88

9-
Write-Host "Restoring NuGet packages..." -ForegroundColor Yellow
9+
$oldPlatform=$env:Platform
10+
$env:Platform='AnyCPU' # Some people wander in here from a platform-specific build window.
1011

11-
# First restore NuProj packages since the solution restore depends on NuProj evaluation succeeding.
12-
gci "$PSScriptRoot\src\project.json" -rec |? { $_.FullName -imatch 'nuget' } |% {
13-
if ($PSCmdlet.ShouldProcess($_, "nuget restore")) {
14-
nuget restore $_ -Verbosity quiet
12+
Push-Location $PSScriptRoot
13+
try {
14+
$toolsPath = "$PSScriptRoot\tools"
15+
16+
# First restore NuProj packages since the solution restore depends on NuProj evaluation succeeding.
17+
gci "$PSScriptRoot\src\project.json" -rec |? { $_.FullName -imatch 'nuget' } |% {
18+
& "$toolsPath\Restore-NuGetPackages.ps1" -Path $_ -Verbosity Quiet
1519
}
16-
}
1720

18-
if ($PSCmdlet.ShouldProcess("$PSScriptRoot\src", "nuget restore")) {
19-
nuget restore "$PSScriptRoot\src" -Verbosity quiet
20-
}
21+
# Restore VS solution dependencies
22+
gci "$PSScriptRoot\src" -rec |? { $_.FullName.EndsWith('.sln') } |% {
23+
& "$toolsPath\Restore-NuGetPackages.ps1" -Path $_.FullName -Verbosity Quiet
24+
}
2125

22-
Write-Host "Restoring NPM packages..." -ForegroundColor Yellow
23-
Push-Location "$PSScriptRoot\src\nerdbank-gitversioning.npm"
24-
if ($PSCmdlet.ShouldProcess("$PSScriptRoot\src\nerdbank-gitversioning.npm", "npm install")) {
25-
npm install --loglevel error
26-
}
26+
Write-Host "Restoring NPM packages..." -ForegroundColor Yellow
27+
Push-Location "$PSScriptRoot\src\nerdbank-gitversioning.npm"
28+
if ($PSCmdlet.ShouldProcess("$PSScriptRoot\src\nerdbank-gitversioning.npm", "npm install")) {
29+
npm install --loglevel error
30+
}
2731

28-
Write-Host "Restoring Typings..." -ForegroundColor Yellow
29-
if ($PSCmdlet.ShouldProcess("$PSScriptRoot\src\nerdbank-gitversioning.npm", "typings install")) {
30-
.\node_modules\.bin\typings install
31-
}
32+
Write-Host "Restoring Typings..." -ForegroundColor Yellow
33+
if ($PSCmdlet.ShouldProcess("$PSScriptRoot\src\nerdbank-gitversioning.npm", "typings install")) {
34+
.\node_modules\.bin\typings install
35+
}
3236

33-
Pop-Location
37+
Write-Host "Successfully restored all dependencies" -ForegroundColor Yellow
38+
}
39+
catch {
40+
Write-Error "Aborting script due to error"
41+
exit $lastexitcode
42+
}
43+
finally {
44+
$env:Platform=$oldPlatform
45+
Pop-Location
46+
}

readme.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ When built as a public release, the git commit ID is dropped:
7070

7171
### What is 'git height'?
7272

73-
Git 'height' is the count of commits in the longest path between HEAD (the code you're building)
74-
and some origin point. In this case the origin is the commit that set the major.minor version number
75-
to the values found in HEAD.
73+
Git 'height' is the number of commits in the longest path from HEAD (the code you're building)
74+
to some origin point, inclusive. In this case the origin is the commit that set the major.minor
75+
version number to the values found in HEAD.
7676

7777
For example, if the version specified at HEAD is 3.4 and the longest path in git history from HEAD
78-
to where the version file was changed to 3.4 is 15 steps, then the git height is "15".
78+
to where the version file was changed to 3.4 includes 15 commits, then the git height is "15".
79+
Another example is when HEAD points directly at the commit that changed the major.minor version,
80+
which has a git height of 1. [Learn more about 1 being the minimum revision number][GitHeightMinimum].
7981

8082
### Why is the git height used for the PATCH version component for public releases?
8183

@@ -110,4 +112,10 @@ that can help you to translate between the two representations.
110112
`Get-CommitId.ps1` takes a version and print out the matching commit (or possible commits, in the exceptionally rare event of a collision).
111113
`Get-Version.ps1` prints out the version information for the git commit current at HEAD.
112114

115+
### How do I build Nerdbank.GitVersioning from source?
116+
117+
Prerequisites and build instructions are found in our
118+
[contributing guidelines](CONTRIBUTING.md).
119+
113120
[semver]: http://semver.org
121+
[GitHeightMinimum]: https://github.com/AArnott/Nerdbank.GitVersioning/issues/102#issuecomment-269591960

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ public async Task GetBuildVersion_Without_Git()
9898
Assert.Equal("3.4.0", buildResult.AssemblyInformationalVersion);
9999
}
100100

101+
[Fact]
102+
public async Task GetBuildVersion_Without_Git_HighPrecisionAssemblyVersion()
103+
{
104+
this.WriteVersionFile(new VersionOptions
105+
{
106+
Version = SemanticVersion.Parse("3.4"),
107+
AssemblyVersion = new VersionOptions.AssemblyVersionOptions
108+
{
109+
Precision = VersionOptions.VersionPrecision.Revision,
110+
},
111+
});
112+
var buildResult = await this.BuildAsync();
113+
Assert.Equal("3.4", buildResult.BuildVersion);
114+
Assert.Equal("3.4.0", buildResult.AssemblyInformationalVersion);
115+
}
116+
101117
[Fact]
102118
public async Task GetBuildVersion_OutsideGit_PointingToGit()
103119
{
@@ -295,6 +311,7 @@ public async Task GetBuildVersion_CustomAssemblyVersion()
295311
}
296312

297313
[Theory]
314+
[InlineData(VersionOptions.VersionPrecision.Major)]
298315
[InlineData(VersionOptions.VersionPrecision.Build)]
299316
[InlineData(VersionOptions.VersionPrecision.Revision)]
300317
public async Task GetBuildVersion_CustomAssemblyVersionWithPrecision(VersionOptions.VersionPrecision precision)
@@ -315,6 +332,7 @@ public async Task GetBuildVersion_CustomAssemblyVersionWithPrecision(VersionOpti
315332
}
316333

317334
[Theory]
335+
[InlineData(VersionOptions.VersionPrecision.Major)]
318336
[InlineData(VersionOptions.VersionPrecision.Build)]
319337
[InlineData(VersionOptions.VersionPrecision.Revision)]
320338
public async Task GetBuildVersion_CustomAssemblyVersionPrecision(VersionOptions.VersionPrecision precision)
@@ -348,6 +366,21 @@ public async Task GetBuildVersion_CustomBuildNumberOffset()
348366
this.AssertStandardProperties(versionOptions, buildResult);
349367
}
350368

369+
[Fact]
370+
public async Task GetBuildVersion_Minus1BuildOffset_NotYetCommitted()
371+
{
372+
this.WriteVersionFile("14.0");
373+
this.InitializeSourceControl();
374+
var versionOptions = new VersionOptions
375+
{
376+
Version = new SemanticVersion(new Version(14, 1)),
377+
BuildNumberOffset = -1,
378+
};
379+
VersionFile.SetVersion(this.RepoPath, versionOptions);
380+
var buildResult = await this.BuildAsync();
381+
this.AssertStandardProperties(versionOptions, buildResult);
382+
}
383+
351384
[Fact]
352385
public async Task PublicRelease_RegEx_Unsatisfied()
353386
{
@@ -370,7 +403,8 @@ public static IEnumerable<object[]> CloudBuildOfBranch(string branchName)
370403
return new object[][]
371404
{
372405
new object[] { CloudBuild.AppVeyor.SetItem("APPVEYOR_REPO_BRANCH", branchName) },
373-
new object[] { CloudBuild.VSTS.SetItem( "BUILD_SOURCEBRANCH", $"refs/heads/{branchName}") },
406+
new object[] { CloudBuild.VSTS.SetItem("BUILD_SOURCEBRANCH", $"refs/heads/{branchName}") },
407+
new object[] { CloudBuild.VSTS.SetItem("BUILD_SOURCEBRANCH", branchName) }, // VSTS building a github repo
374408
};
375409
}
376410

@@ -718,11 +752,15 @@ public async Task AssemblyInfo_SuppressedImplicitlyByTargetExt()
718752

719753
private static Version GetExpectedAssemblyVersion(VersionOptions versionOptions, Version version)
720754
{
721-
var assemblyVersionPrecision = versionOptions.AssemblyVersion?.Precision ?? VersionOptions.VersionPrecision.Minor;
722-
int assemblyVersionBuild = assemblyVersionPrecision >= VersionOptions.VersionPrecision.Build ? version.Build : 0;
723-
int assemblyVersionRevision = assemblyVersionPrecision >= VersionOptions.VersionPrecision.Revision ? version.Revision : 0;
724-
Version assemblyVersion = (versionOptions.AssemblyVersion?.Version ?? versionOptions.Version.Version).EnsureNonNegativeComponents();
725-
assemblyVersion = new Version(assemblyVersion.Major, assemblyVersion.Minor, assemblyVersionBuild, assemblyVersionRevision);
755+
// Function should be very similar to VersionOracle.GetAssemblyVersion()
756+
var assemblyVersion = (versionOptions?.AssemblyVersion?.Version ?? versionOptions.Version.Version).EnsureNonNegativeComponents();
757+
var precision = versionOptions?.AssemblyVersion?.Precision ?? VersionOptions.DefaultVersionPrecision;
758+
759+
assemblyVersion = new System.Version(
760+
assemblyVersion.Major,
761+
precision >= VersionOptions.VersionPrecision.Minor ? assemblyVersion.Minor : 0,
762+
precision >= VersionOptions.VersionPrecision.Build ? version.Build : 0,
763+
precision >= VersionOptions.VersionPrecision.Revision ? version.Revision : 0);
726764
return assemblyVersion;
727765
}
728766

0 commit comments

Comments
 (0)