Auto Versioning in Visual Studio 2017 (.Net Core)

Auto Versioning in Visual Studio 2017 (.NET Core)

I have been looking for a version incrementer for a .NET Core app in VS2017 using the csproj configuration format.

I found a project called dotnet bump that worked for the project.json format but struggled to find a solution for the .csproj format. The writer of dotnet bump actually came up with the solution for the .csproj format and it is called MSBump.

There is a project on GitHub for it at:

https://github.com/BalassaMarton/MSBump

where you can see the code and it's available on NuGet too. Just search for MSBump on Nuget.

How to auto increment the version (eg. “1.0.*”) of a .NET Core project?

One simple way I did it previously is reading the current version and increase it by one, so you get current version and increment by one using command line.

I found this article would answers your question: https://sachabarbs.wordpress.com/2020/02/23/net-core-standard-auto-incrementing-versioning/

Can I automatically increment the file build version when using Visual Studio?

In visual Studio 2008, the following works.

Find the AssemblyInfo.cs file and find these 2 lines:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

You could try changing this to:

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]

But this won't give you the desired result, you will end up with a Product Version of 1.0.* and a File Version of 1.0.0.0. Not what you want!

However, if you remove the second of these lines and just have:

[assembly: AssemblyVersion("1.0.*")]

Then the compiler will set the File Version to be equal to the Product Version and you will get your desired result of an automatically increment product and file version which are in sync. E.g. 1.0.3266.92689

How to have an auto incrementing version number (Visual Studio)?

If you add an AssemblyInfo class to your project and amend the AssemblyVersion attribute to end with an asterisk, for example:

[assembly: AssemblyVersion("2.10.*")]

Visual studio will increment the final number for you according to these rules (thanks galets, I had that completely wrong!)

To reference this version in code, so you can display it to the user, you use reflection. For example,

Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
DateTime buildDate = new DateTime(2000, 1, 1)
.AddDays(version.Build).AddSeconds(version.Revision * 2);
string displayableVersion = $"{version} ({buildDate})";

Three important gotchas that you should know

From @ashes999:

It's also worth noting that if both AssemblyVersion and AssemblyFileVersion are specified, you won't see this on your .exe.

From @BrainSlugs83:

Setting only the 4th number to be * can be bad, as the version won't always increment.
The 3rd number is the number of days since the year 2000, and the 4th number is the number of seconds since midnight (divided by 2) [IT IS NOT RANDOM]. So if you built the solution late in a day one day, and early in a day the next day, the later build would have an earlier version number. I recommend always using X.Y.* instead of X.Y.Z.* because your version number will ALWAYS increase this way.

Newer versions of Visual Studio give this error:



(this thread begun in 2009)

The specified version string contains wildcards, which are not compatible with determinism. Either remove wildcards from the version string, or disable determinism for this compilation.

See this SO answer which explains how to remove determinism (https://stackoverflow.com/a/58101474/1555612)

How to auto increment asp.net core application version via shell script in TFS Build Job after TFS 2017 Build and show it in the footer of index.html

I solve the problem by using Bump to increment version in package.json file,

var gulp = require('gulp');
var bump = require('gulp-bump');

// Basic usage:
// Will patch the version
gulp.task('bump', function(){
gulp.src('./component.json')
.pipe(bump())
.pipe(gulp.dest('./'));
});

// Defined method of updating:
// Semantic
gulp.task('bump', function(){
gulp.src('./*.json')
.pipe(bump({type:'minor'}))
.pipe(gulp.dest('./'));
});

// Defined method of updating:
// Semantic major
gulp.task('bump', function(){
gulp.src('./package.yml')
.pipe(bump({type:'major'}))
.pipe(gulp.dest('./'));
});

// Defined method of updating:
// Set a specific version
gulp.task('bump', function(){
gulp.src('./*.json')
.pipe(bump({version: '1.2.3'}))
.pipe(gulp.dest('./'));
});

// Update bower, component, npm at once:
gulp.task('bump', function(){
gulp.src(['./bower.json', './component.json', './package.json'])
.pipe(bump({type:'major'}))
.pipe(gulp.dest('./'));
});

// Define the key for versioning off
gulp.task('bump', function(){
gulp.src('./package.json')
.pipe(bump({key: "appversion"}))
.pipe(gulp.dest('./'));
});

icreated 3 Jobs in TSF, evry job is responsable for incrementing one of Major, Minor and Patch, so while commiting developer will choose to excute one of these jobs, wich will excute the concrete gulp Task.

How do I auto increment the package version number?

Three liner, versioning by date

I ran into that issue until I figured out after a lot of research how to achieve automatic versioning in just three line in the .csproj file. Here it is:

<Target Name="NugetPackAutoVersioning" AfterTargets="Build">
<Exec Command="dotnet pack -p:PackageVersion=$([System.DateTime]::Now.ToString("yyyy.MM.dd.HHmm")) --no-build --configuration $(Configuration) --output "$(SolutionDir)nuget"" />
</Target>

This will output a NuGet package named like {ProjectName}.{Year}.{Month}.{Day}.{Hour}{Minute} in a "nuget" folder at the project root, guaranteeing that packages built later are versioned as posteriors.



Related Topics



Leave a reply



Submit