Skip to content

Commit 2a54485

Browse files
authored
Merge branch 'master' into master
2 parents e79613b + f554e4a commit 2a54485

File tree

10 files changed

+242
-21
lines changed

10 files changed

+242
-21
lines changed

docs/git-branching-strategies/gitflow-examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Feature branches will take the feature branch name and use that as the pre-relea
1010

1111
Notice after the feature branch is merged, the version on `develop` is `1.3.0-alpha.3`. This is due to `develop` running in *continuous deployment* mode. If you configured `develop` to use *continuous delivery* the version would still be `1.3.0-alpha.1` and you would have to use release tags to increment the `alpha.1`.
1212

13-
You can see the different on the feature branch itself, notice the version is the same before and after the commit on the feature branch? Only the metadata has changed. If you released the feature branch artifacts then tagged the commit, the following commit would increase to `-beta.2`.
13+
You can see the difference on the feature branch itself, notice the version is the same before and after the commit on the feature branch? Only the metadata has changed. If you released the feature branch artifacts then tagged the commit, the following commit would increase to `-beta.2`.
1414

1515
## Pull Request
1616
Because feature branches are most likely pushed to a fork, we are showing the

docs/usage/msbuild-task.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The MSBuild Task for GitVersion — **GitVersionTask** — is a simple solution
44
you want to version your assemblies without writing any command line scripts or
55
modifying your build process.
66

7+
It currently works with desktop `MSBuild`. Support for CoreCLR with `dotnet build` is coming soon.
8+
79
## TL;DR
810

911
### Install the MSTask targets
@@ -16,6 +18,14 @@ From the Package Manager Console:
1618
Install-Package GitVersionTask
1719
```
1820

21+
If you're using `PackageReference` style NuGet dependencies (VS 2017+), add `<PrivateAssets>all</PrivateAssets>` to prevent the task from becoming a dependency of your package:
22+
23+
``` xml
24+
<PackageReference Include="GitVersionTask" Version="4.0.0-beta*">
25+
<PrivateAssets>All</PrivateAssets>
26+
</PackageReference>
27+
```
28+
1929
### Remove AssemblyInfo attributes
2030

2131
The next thing you need to do is to remove the `Assembly*Version` attributes from
@@ -115,6 +125,17 @@ However at MSBuild time these properties are mapped to MSBuild properties that
115125
are prefixed with `GitVersion_`. This prevents conflicts with other properties
116126
in the pipeline.
117127

128+
In addition, the following MSBuild properties are set when `UpdateVersionProperties` is true (the default):
129+
`Version`, `VersionPrefix`, `VersionSuffix`, `PackageVersion`, `InformationalVersion`, `AssemblyVersion` and `FileVersion`. These are used by the built-in tasks for generating AssemblyInfo's and NuGet package versions.
130+
131+
132+
### NuGet packages
133+
The new SDK-style projects available for .NET Standard libraries (and multi-targeting), have the ability
134+
to create NuGet packages directly by using the `pack` target: `msbuild /t:pack`. The version is controled by the MSBuild properties described above.
135+
136+
GitVersionTask has the option to generate SemVer 2.0 compliant NuGet package versions by setting `UseFullSemVerForNuGet` to true in your project (this is off by default for compatibility). Some hosts, like MyGet, support SemVer 2.0 package versions but older NuGet clients and nuget.org do not.
137+
138+
118139
#### Accessing variables in MSBuild
119140

120141
Once `GitVersionTask.GetVersion` has been executed, the MSBuild properties can be
@@ -136,7 +157,7 @@ Build Server log in a format that the current Build Server can consume. See
136157

137158
## Conditional control tasks
138159

139-
Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo` and `GetVersion`
160+
Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo`, `UseFullSemVerForNuGet`, `UpdateVersionProperties` and `GetVersion`
140161
are checked before running these tasks.
141162

142163
You can disable `GitVersionTask.UpdateAssemblyInfo` by setting
@@ -150,6 +171,7 @@ this:
150171
...
151172
</PropertyGroup>
152173
```
174+
For SDK-style projects, `UpdateVersionProperties` controls setting the default variables: `Version`, `VersionPrefix`, `VersionSuffix`, `PackageVersion`, `InformationalVersion`, `AssemblyVersion` and `FileVersion`.
153175

154176
## My Git repository requires authentication. What should I do?
155177

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.IO;
2+
using GitVersion;
3+
using NUnit.Framework;
4+
5+
[TestFixture]
6+
public class DynamicRepositoryTests
7+
{
8+
string workDirectory;
9+
10+
11+
[SetUp]
12+
public void CreateTemporaryRepository()
13+
{
14+
// Note: we can't use guid because paths will be too long
15+
workDirectory = Path.Combine(Path.GetTempPath(), "DynRepoTests");
16+
}
17+
18+
19+
//[TearDown]
20+
//public void Cleanup()
21+
//{
22+
// Directory.Delete(workDirectory, true);
23+
//}
24+
25+
[TestCase("GV_master_1", "https://github.com/GitTools/GitVersion", "master", "4783d325521463cd6cf1b61074352da84451f25d", "4.0.0+1126")]
26+
[TestCase("GV_master_2", "https://github.com/GitTools/GitVersion", "master", "3bdcd899530b4e9b37d13639f317da04a749e728", "4.0.0+1132")]
27+
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer)
28+
{
29+
var root = Path.Combine(workDirectory, name);
30+
var dynamicDirectory = Path.Combine(root, "dynamic");
31+
var workingDirectory = Path.Combine(root, "working");
32+
33+
// Clear upfront
34+
if (Directory.Exists(root))
35+
{
36+
Directory.Delete(root, true);
37+
}
38+
39+
Directory.CreateDirectory(dynamicDirectory);
40+
Directory.CreateDirectory(workingDirectory);
41+
42+
var executeCore = new ExecuteCore(new TestFileSystem());
43+
44+
var versionVariables = executeCore.ExecuteGitVersion(url, dynamicDirectory, null, targetBranch,
45+
false, workingDirectory, commitId);
46+
47+
Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer);
48+
}
49+
}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<Compile Include="BuildServers\VsoAgentTests.cs" />
121121
<Compile Include="BuildServers\TeamCityTests.cs" />
122122
<Compile Include="Configuration\IgnoreConfigTests.cs" />
123+
<Compile Include="DynamicRepositoryTests.cs" />
123124
<Compile Include="GitToolsTestingExtensions.cs" />
124125
<Compile Include="DocumentationTests.cs" />
125126
<Compile Include="ConfigProviderTests.cs" />

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using GitTools.Testing;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using GitTools;
5+
using GitTools.Testing;
26
using GitVersion;
37
using GitVersionCore.Tests;
48
using LibGit2Sharp;
@@ -417,4 +421,49 @@ public void CommitOnDevelop_AfterReleaseBranchMergeToDevelop_ShouldNotResetCount
417421
fixture.AssertFullSemver(config, "2.0.0-beta.5");
418422
}
419423
}
424+
425+
public void ReleaseBranchShouldUseBranchNameVersionDespiteBumpInPreviousCommit()
426+
{
427+
using (var fixture = new EmptyRepositoryFixture())
428+
{
429+
fixture.Repository.MakeATaggedCommit("1.0");
430+
fixture.Repository.MakeACommit("+semver:major");
431+
fixture.Repository.MakeACommit();
432+
433+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/2.0"));
434+
435+
fixture.AssertFullSemver("2.0.0-beta.1+2");
436+
}
437+
}
438+
439+
[Test]
440+
public void ReleaseBranchWithACommitShouldUseBranchNameVersionDespiteBumpInPreviousCommit()
441+
{
442+
using (var fixture = new EmptyRepositoryFixture())
443+
{
444+
fixture.Repository.MakeATaggedCommit("1.0");
445+
fixture.Repository.MakeACommit("+semver:major");
446+
fixture.Repository.MakeACommit();
447+
448+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/2.0"));
449+
450+
fixture.Repository.MakeACommit();
451+
452+
fixture.AssertFullSemver("2.0.0-beta.1+3");
453+
}
454+
}
455+
456+
[Test]
457+
public void ReleaseBranchedAtCommitWithSemverMessageShouldUseBranchNameVersion()
458+
{
459+
using (var fixture = new EmptyRepositoryFixture())
460+
{
461+
fixture.Repository.MakeATaggedCommit("1.0");
462+
fixture.Repository.MakeACommit("+semver:major");
463+
464+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/2.0"));
465+
466+
fixture.AssertFullSemver("2.0.0-beta.1+1");
467+
}
468+
}
420469
}

src/GitVersionCore/GitPreparer.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,19 @@ static string CreateDynamicRepository(string targetPath, AuthenticationInfo auth
166166
static void CloneRepository(string repositoryUrl, string gitDirectory, AuthenticationInfo authentication)
167167
{
168168
Credentials credentials = null;
169-
if (!string.IsNullOrWhiteSpace(authentication.Username) && !string.IsNullOrWhiteSpace(authentication.Password))
170-
{
171-
Logger.WriteInfo(string.Format("Setting up credentials using name '{0}'", authentication.Username));
172169

173-
credentials = new UsernamePasswordCredentials
170+
if (authentication != null)
171+
{
172+
if (!string.IsNullOrWhiteSpace(authentication.Username) && !string.IsNullOrWhiteSpace(authentication.Password))
174173
{
175-
Username = authentication.Username,
176-
Password = authentication.Password
177-
};
174+
Logger.WriteInfo(string.Format("Setting up credentials using name '{0}'", authentication.Username));
175+
176+
credentials = new UsernamePasswordCredentials
177+
{
178+
Username = authentication.Username,
179+
Password = authentication.Password
180+
};
181+
}
178182
}
179183

180184
Logger.WriteInfo(string.Format("Retrieving git info from url '{0}'", repositoryUrl));

src/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public BaseVersion GetBaseVersion(GitVersionContext context)
5151
BaseVersion baseVersionWithOldestSource;
5252
if (matchingVersionsOnceIncremented.Any())
5353
{
54-
baseVersionWithOldestSource = matchingVersionsOnceIncremented.Aggregate((v1, v2) => v1.Version.BaseVersionSource.Committer.When < v2.Version.BaseVersionSource.Committer.When ? v1 : v2).Version;
54+
var oldest = matchingVersionsOnceIncremented.Aggregate((v1, v2) => v1.Version.BaseVersionSource.Committer.When < v2.Version.BaseVersionSource.Committer.When ? v1 : v2);
55+
baseVersionWithOldestSource = oldest.Version;
56+
maxVersion = oldest;
5557
Logger.WriteInfo(string.Format(
5658
"Found multiple base versions which will produce the same SemVer ({0}), taking oldest source for commit counting ({1})",
5759
maxVersion.IncrementedVersion,

src/GitVersionTask/GitVersionTask.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@
7979
</ItemGroup>
8080
<ItemGroup>
8181
<None Include="app.config" />
82-
<None Include="NugetAssets\GitVersionTask.targets">
83-
<SubType>Designer</SubType>
84-
</None>
82+
<None Include="NugetAssets\buildMultiTargeting\GitVersionTask.targets" />
83+
<None Include="NugetAssets\build\GitVersionTask.targets" />
8584
<None Include="NugetAssets\GitVersionTask.nuspec">
8685
<SubType>Designer</SubType>
8786
</None>
@@ -127,7 +126,8 @@
127126
<Copy SourceFiles="$(TargetDir)ILMergeTemp\GitVersionTask.dll" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" Condition="Exists('$(TargetDir)ILMergeTemp\GitVersionTask.dll')" />
128127
<Copy SourceFiles="$(TargetDir)GitVersionTask.pdb" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" Condition="Exists('$(TargetDir)GitVersionTask.pdb')" />
129128
<Copy SourceFiles="$(TargetDir)GitVersionTask.dll.mdb" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" Condition="Exists('$(TargetDir)GitVersionTask.dll.mdb')" />
130-
<Copy SourceFiles="$(ProjectDir)NugetAssets\GitVersionTask.targets" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" />
129+
<Copy SourceFiles="$(ProjectDir)NugetAssets\build\GitVersionTask.targets" DestinationFolder="$(BuildDir)NuGetTaskBuild\build" />
130+
<Copy SourceFiles="$(ProjectDir)NugetAssets\buildMultiTargeting\GitVersionTask.targets" DestinationFolder="$(BuildDir)NuGetTaskBuild\buildMultiTargeting" />
131131
<Copy SourceFiles="$(ProjectDir)NugetAssets\GitVersionTask.nuspec" DestinationFolder="$(BuildDir)NuGetTaskBuild" />
132132
<PepitaPackage.CreatePackageTask NuGetBuildDirectory="$(BuildDir)NuGetTaskBuild" MetadataAssembly="$(ILMergeTemp)GitVersionTask.dll" Version="$(GitVersion_NuGetVersion)" />
133133
<Delete Files="@(TempFiles)" />

src/GitVersionTask/NugetAssets/GitVersionTask.targets renamed to src/GitVersionTask/NugetAssets/build/GitVersionTask.targets

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88
<!-- Property that enables WriteVersionInfoToBuildLog -->
99
<WriteVersionInfoToBuildLog Condition=" '$(WriteVersionInfoToBuildLog)' == '' ">true</WriteVersionInfoToBuildLog>
1010

11-
<!-- Property that enables UpdateAssemblyInfo -->
11+
<!-- Property that enables UpdateAssemblyInfo. Default to off for SDK builds -->
12+
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' and '$(TargetFramework)' != '' ">false</UpdateAssemblyInfo>
1213
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' ">true</UpdateAssemblyInfo>
14+
15+
<!-- Property that enables setting of Version -->
16+
<UpdateVersionProperties Condition=" '$(UpdateVersionProperties)' == '' ">true</UpdateVersionProperties>
17+
<UseFullSemVerForNuGet Condition=" '$(UseFullSemVerForNuGet)' == '' ">false</UseFullSemVerForNuGet>
1318

1419
<!-- Property that enables GetVersion -->
1520
<GetVersion Condition=" '$(GetVersion)' == '' ">true</GetVersion>
@@ -27,7 +32,7 @@
2732
TaskName="GitVersionTask.WriteVersionInfoToBuildLog"
2833
AssemblyFile="$(GitVersionTaskLibrary)GitVersionTask.dll" />
2934

30-
<Target Name="WriteVersionInfoToBuildLog" BeforeTargets="CoreCompile" Condition="$(WriteVersionInfoToBuildLog) == 'true'">
35+
<Target Name="WriteVersionInfoToBuildLog" BeforeTargets="CoreCompile;GetAssemblyVersion;GenerateNuspec" Condition="$(WriteVersionInfoToBuildLog) == 'true'">
3136
<WriteVersionInfoToBuildLog SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersion_NoFetchEnabled)"/>
3237
</Target>
3338

@@ -49,7 +54,7 @@
4954
</ItemGroup>
5055
</Target>
5156

52-
<Target Name="GetVersion" BeforeTargets="CoreCompile" Condition="$(GetVersion) == 'true'">
57+
<Target Name="GetVersion" BeforeTargets="CoreCompile;GetAssemblyVersion;GenerateNuspec" Condition="$(GetVersion) == 'true'">
5358

5459
<GetVersion SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersion_NoFetchEnabled)">
5560
<Output TaskParameter="Major" PropertyName="GitVersion_Major" />
@@ -77,6 +82,18 @@
7782
<Output TaskParameter="CommitsSinceVersionSource" PropertyName="GitVersion_CommitsSinceVersionSource" />
7883
<Output TaskParameter="CommitsSinceVersionSourcePadded" PropertyName="GitVersion_CommitsSinceVersionSourcePadded" />
7984
</GetVersion>
85+
86+
<PropertyGroup Condition=" '$(UpdateVersionProperties)' == 'true' ">
87+
<Version>$(GitVersion_FullSemVer)</Version>
88+
<VersionPrefix>$(GitVersion_MajorMinorPatch)</VersionPrefix>
89+
<VersionSuffix Condition=" '$(UseFullSemVerForNuGet)' == 'false' ">$(GitVersion_NuGetPreReleaseTag)</VersionSuffix>
90+
<VersionSuffix Condition=" '$(UseFullSemVerForNuGet)' == 'true' ">$(GitVersion_PreReleaseTag)</VersionSuffix>
91+
<PackageVersion Condition=" '$(UseFullSemVerForNuGet)' == 'false' ">$(GitVersion_NuGetVersion)</PackageVersion>
92+
<PackageVersion Condition=" '$(UseFullSemVerForNuGet)' == 'true' ">$(GitVersion_FullSemVer)</PackageVersion>
93+
<InformationalVersion Condition=" '$(InformationalVersion)' == '' ">$(GitVersion_InformationalVersion)</InformationalVersion>
94+
<AssemblyVersion Condition=" '$(AssemblyVersion)' == '' ">$(GitVersion_AssemblySemVer)</AssemblyVersion>
95+
<FileVersion Condition=" '$(FileVersion)' == '' ">$(GitVersion_MajorMinorPatch).$(GitVersion_CommitsSinceVersionSource)</FileVersion>
96+
</PropertyGroup>
8097

8198
</Target>
8299

@@ -93,6 +110,4 @@
93110
</None>
94111
</ItemGroup>
95112

96-
</Project>
97-
98-
113+
</Project>

0 commit comments

Comments
 (0)