Skip to content

Created new configuration-option assembly-file-versioning-scheme: #1130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Task("Create-Release-Notes")
.WithCriteria(() => IsMainGitVersionRepo && IsMainGitVersionBranch && !IsPullRequest)
.Does(() =>
{
var githubToken = EnvironmentVariable("GitHubToken");
var githubToken = EnvironmentVariable("GitHubToken");

if(!string.IsNullOrWhiteSpace(githubToken))
{
Expand Down
7 changes: 7 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The global configuration look like this:
```yaml
next-version: 1.0
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatchTag
assembly-informational-format: '{InformationalVersion}'
mode: ContinuousDelivery
increment: Inherit
Expand Down Expand Up @@ -61,6 +62,12 @@ Strong Naming. Note: you can use `None` to skip updating the `AssemblyVersion`
while still updating the `AssemblyFileVersion` and `AssemblyInformationVersion`
attributes.

### assembly-file-versioning-scheme
When updating assembly info, `assembly-file-versioning-scheme` tells GitVersion how
to treat the `AssemblyFileVersion` attribute. Note: you can use `None` to skip updating the `AssemblyFileVersion`
while still updating the `AssemblyVersion` and `AssemblyInformationVersion`
attributes.

### assembly-informational-format
Set this to any of the available [variables](/more-info/variables) to change the
value of the `AssemblyInformationalVersion` attribute. Default set to
Expand Down
2 changes: 1 addition & 1 deletion docs/git-branching-strategies/gitflow-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Feature branches will take the feature branch name and use that as the pre-relea

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`.

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`.
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`.

## Pull Request
Because feature branches are most likely pushed to a fork, we are showing the
Expand Down
1 change: 1 addition & 0 deletions docs/more-info/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ For the `release/3.0.0` branch of GitVersion it shows:
"LegacySemVer":"3.0.0-beta1",
"LegacySemVerPadded":"3.0.0-beta0001",
"AssemblySemVer":"3.0.0.0",
"AssemblySemFileVer":"3.0.0.0",
"FullSemVer":"3.0.0-beta.1+1",
"InformationalVersion":"3.0.0-beta.1+1.Branch.release/3.0.0.Sha.28c853159a46b5a87e6cc9c4f6e940c59d6bc68a",
"BranchName":"release/3.0.0",
Expand Down
24 changes: 23 additions & 1 deletion docs/usage/msbuild-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The MSBuild Task for GitVersion — **GitVersionTask** — is a simple solution
you want to version your assemblies without writing any command line scripts or
modifying your build process.

It currently works with desktop `MSBuild`. Support for CoreCLR with `dotnet build` is coming soon.

## TL;DR

### Install the MSTask targets
Expand All @@ -16,6 +18,14 @@ From the Package Manager Console:
Install-Package GitVersionTask
```

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:

``` xml
<PackageReference Include="GitVersionTask" Version="4.0.0-beta*">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
```

### Remove AssemblyInfo attributes

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

In addition, the following MSBuild properties are set when `UpdateVersionProperties` is true (the default):
`Version`, `VersionPrefix`, `VersionSuffix`, `PackageVersion`, `InformationalVersion`, `AssemblyVersion` and `FileVersion`. These are used by the built-in tasks for generating AssemblyInfo's and NuGet package versions.


### NuGet packages
The new SDK-style projects available for .NET Standard libraries (and multi-targeting), have the ability
to create NuGet packages directly by using the `pack` target: `msbuild /t:pack`. The version is controled by the MSBuild properties described above.

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.


#### Accessing variables in MSBuild

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

## Conditional control tasks

Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo` and `GetVersion`
Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo`, `UseFullSemVerForNuGet`, `UpdateVersionProperties` and `GetVersion`
are checked before running these tasks.

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Major":1,
"Minor":2,
"Patch":0,
Expand All @@ -14,6 +14,7 @@
"LegacySemVer":"1.2.0-unstable4",
"LegacySemVerPadded":"1.2.0-unstable0004",
"AssemblySemVer":"1.2.0.0",
"AssemblySemFileVer":"1.2.0.0",
"FullSemVer":"1.2.0-unstable.4+5",
"InformationalVersion":"1.2.0-unstable.4+5.Branch.feature1.Sha.commitSha",
"BranchName":"feature1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Major":1,
"Minor":2,
"Patch":3,
Expand All @@ -14,6 +14,7 @@
"LegacySemVer":"1.2.3-unstable4",
"LegacySemVerPadded":"1.2.3-unstable0004",
"AssemblySemVer":"1.2.3.0",
"AssemblySemFileVer":"1.2.3.0",
"FullSemVer":"1.2.3-unstable.4+5",
"InformationalVersion":"1.2.3-unstable.4+5.Branch.develop.Sha.commitSha",
"BranchName":"develop",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Major":1,
"Minor":2,
"Patch":3,
Expand All @@ -14,6 +14,7 @@
"LegacySemVer":"1.2.3-unstable4",
"LegacySemVerPadded":"1.2.3-unstable00004",
"AssemblySemVer":"1.2.3.0",
"AssemblySemFileVer":"1.2.3.0",
"FullSemVer":"1.2.3-unstable.4+5",
"InformationalVersion":"1.2.3-unstable.4+5.Branch.develop.Sha.commitSha",
"BranchName":"develop",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Major":1,
"Minor":2,
"Patch":3,
Expand All @@ -14,6 +14,7 @@
"LegacySemVer":"1.2.3",
"LegacySemVerPadded":"1.2.3",
"AssemblySemVer":"1.2.3.0",
"AssemblySemFileVer":"1.2.3.0",
"FullSemVer":"1.2.3+5",
"InformationalVersion":"1.2.3+5.Branch.develop.Sha.commitSha",
"BranchName":"develop",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Major":1,
"Minor":2,
"Patch":3,
Expand All @@ -14,6 +14,7 @@
"LegacySemVer":"1.2.3-unstable5",
"LegacySemVerPadded":"1.2.3-unstable0005",
"AssemblySemVer":"1.2.3.0",
"AssemblySemFileVer":"1.2.3.0",
"FullSemVer":"1.2.3-unstable.5",
"InformationalVersion":"1.2.3-unstable.5+Branch.develop.Sha.commitSha",
"BranchName":"develop",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Major":1,
"Minor":2,
"Patch":3,
Expand All @@ -14,6 +14,7 @@
"LegacySemVer":"1.2.3-ci5",
"LegacySemVerPadded":"1.2.3-ci0005",
"AssemblySemVer":"1.2.3.0",
"AssemblySemFileVer":"1.2.3.0",
"FullSemVer":"1.2.3-ci.5",
"InformationalVersion":"1.2.3-ci.5+Branch.develop.Sha.commitSha",
"BranchName":"develop",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Major":1,
"Minor":2,
"Patch":3,
Expand All @@ -14,6 +14,7 @@
"LegacySemVer":"1.2.3",
"LegacySemVerPadded":"1.2.3",
"AssemblySemVer":"1.2.3.0",
"AssemblySemFileVer":"1.2.3.0",
"FullSemVer":"1.2.3+5",
"InformationalVersion":"1.2.3+5.Sha.commitSha",
"BranchName":"",
Expand Down
29 changes: 29 additions & 0 deletions src/GitVersionCore.Tests/AssemblyFileVersionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using GitVersion;
using NUnit.Framework;

namespace GitVersionCore.Tests
{
using Shouldly;

[TestFixture]
public class AssemblyFileVersionTests
{
[TestCase(AssemblyFileVersioningScheme.None, 1, 2, 3, 4, null)]
[TestCase(AssemblyFileVersioningScheme.Major, 1, 2, 3, 4, "1.0.0.0")]
[TestCase(AssemblyFileVersioningScheme.MajorMinor, 1, 2, 3, 4, "1.2.0.0")]
[TestCase(AssemblyFileVersioningScheme.MajorMinorPatch, 1, 2, 3, 4, "1.2.3.0")]
[TestCase(AssemblyFileVersioningScheme.MajorMinorPatchTag, 1, 2, 3, 4, "1.2.3.4")]
public void ValidateAssemblyFileVersionBuilder(AssemblyFileVersioningScheme assemblyFileVersioningScheme, int major, int minor, int patch,
int tag, string versionString)
{
var semVer = new SemanticVersion(major, minor, patch)
{
PreReleaseTag = new SemanticVersionPreReleaseTag("Test", tag)
};

var assemblyFileVersion = semVer.GetAssemblyFileVersion(assemblyFileVersioningScheme);

assemblyFileVersion.ShouldBe(versionString);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
mode: ContinuousDelivery
tag-prefix: '[vV]'
continuous-delivery-fallback-tag: ci
Expand Down
7 changes: 7 additions & 0 deletions src/GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,14 @@ public void CanUpdateAssemblyInformationalVersioningScheme()
{
const string text = @"
assembly-versioning-scheme: MajorMinor
assembly-file-versioning-scheme: MajorMinorPatch
assembly-informational-format: '{NugetVersion}'";

SetupConfigFileContent(text);

var config = ConfigurationProvider.Provide(repoPath, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
config.AssemblyInformationalFormat.ShouldBe("{NugetVersion}");
}

Expand All @@ -179,12 +181,14 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithMultipleVariables(
{
const string text = @"
assembly-versioning-scheme: MajorMinor
assembly-file-versioning-scheme: MajorMinorPatch
assembly-informational-format: '{Major}.{Minor}.{Patch}'";

SetupConfigFileContent(text);

var config = ConfigurationProvider.Provide(repoPath, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
config.AssemblyInformationalFormat.ShouldBe("{Major}.{Minor}.{Patch}");
}

Expand All @@ -193,6 +197,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithMultipleVariables(
public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer()
{
const string text = @"assembly-versioning-scheme: MajorMinorPatch
assembly-file-versioning-scheme: MajorMinorPatch
assembly-informational-format: '{FullSemVer}'
mode: ContinuousDelivery
next-version: 5.3.0
Expand All @@ -202,6 +207,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer()

var config = ConfigurationProvider.Provide(repoPath, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
config.AssemblyInformationalFormat.ShouldBe("{FullSemVer}");
}

Expand All @@ -212,6 +218,7 @@ public void CanReadDefaultDocument()
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
config.AssemblyInformationalFormat.ShouldBe(null);
config.Branches["develop"].Tag.ShouldBe("alpha");
config.Branches["release"].Tag.ShouldBe("beta");
Expand Down
50 changes: 50 additions & 0 deletions src/GitVersionCore.Tests/DynamicRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.IO;
using GitVersion;
using NUnit.Framework;

[TestFixture]
public class DynamicRepositoryTests
{
string workDirectory;


[SetUp]
public void CreateTemporaryRepository()
{
// Note: we can't use guid because paths will be too long
workDirectory = Path.Combine(Path.GetTempPath(), "DynRepoTests");
}


//[TearDown]
//public void Cleanup()
//{
// Directory.Delete(workDirectory, true);
//}

[Ignore("These tests are slow and fail on the second run in Test Explorer and need to be re-written")]
[TestCase("GV_master_1", "https://github.com/GitTools/GitVersion", "master", "4783d325521463cd6cf1b61074352da84451f25d", "4.0.0+1126")]
[TestCase("GV_master_2", "https://github.com/GitTools/GitVersion", "master", "3bdcd899530b4e9b37d13639f317da04a749e728", "4.0.0+1132")]
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer)
{
var root = Path.Combine(workDirectory, name);
var dynamicDirectory = Path.Combine(root, "dynamic");
var workingDirectory = Path.Combine(root, "working");

// Clear upfront
if (Directory.Exists(root))
{
Directory.Delete(root, true);
}

Directory.CreateDirectory(dynamicDirectory);
Directory.CreateDirectory(workingDirectory);

var executeCore = new ExecuteCore(new TestFileSystem());

var versionVariables = executeCore.ExecuteGitVersion(url, dynamicDirectory, null, targetBranch,
false, workingDirectory, commitId);

Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer);
}
}
4 changes: 4 additions & 0 deletions src/GitVersionCore.Tests/ExecuteCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void CacheFileExistsOnDisk()
LegacySemVer: 4.10.3-test19
LegacySemVerPadded: 4.10.3-test0019
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
Expand Down Expand Up @@ -101,6 +102,7 @@ public void CacheFileExistsOnDiskWhenOverrideConfigIsSpecifiedVersionShouldBeDyn
LegacySemVer: 4.10.3-test19
LegacySemVerPadded: 4.10.3-test0019
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
Expand Down Expand Up @@ -163,6 +165,7 @@ public void ConfigChangeInvalidatesCache()
LegacySemVer: 4.10.3-test19
LegacySemVerPadded: 4.10.3-test0019
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
Expand Down Expand Up @@ -211,6 +214,7 @@ public void NoCacheBypassesCache()
LegacySemVer: 4.10.3-test19
LegacySemVerPadded: 4.10.3-test0019
AssemblySemVer: 4.10.3.0
AssemblySemFileVer: 4.10.3.0
FullSemVer: 4.10.3-test.19
InformationalVersion: 4.10.3-test.19+Branch.feature/test.Sha.dd2a29aff0c948e1bdf3dabbe13e1576e70d5f9f
BranchName: feature/test
Expand Down
Loading