I want to implement automatic semantic versioning of NuGet packages as VSTS build step (actually inside cakebuild step). The problem is, while getting which branch build is executing is easy (buildSystem.TFBuild.Environment.Repository.Branch), I don't have any idea how to get information about which branch was merged to master (hotfix branch for patch version, or develop branch with new feature for minor). Is this possible or should I accept that each version update will require manual Nuspec editing? It looks like gitflow has inbuilt mechanism to recognize these e.g. based on branch names, but we simply don't use it.
You could utilize GitVersion tool and aliases to assert version from git history / branch, example usage:
#tool "nuget:https://api.nuget.org/v3/index.json?package=GitVersion.CommandLine&version=3.6.2"
if (!BuildSystem.IsLocalBuild)
{
GitVersion(new GitVersionSettings{
OutputType = GitVersionOutput.BuildServer
});
}
GitVersion assertedVersions = GitVersion(new GitVersionSettings
{
UpdateAssemblyInfoFilePath = "./src/Project/AssemblyInfo.cs",
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.Json,
});
version = assertedVersions.MajorMinorPatch;
semVersion = assertedVersions.LegacySemVerPadded;
milestone = string.Concat("v", version);