Previous versions of ASP.NET allowed you to auto-increment the version number via Project Properties. How can I do this in MVC 6?
MVC 6 now uses project.json
to track version and you can bump this number using gulp-bump.
Add gulp-bump to package.json > devDependencies
gulp-bump": "1.0.0"
Edit gulpfile.js
bump = require("gulp-bump")
to the dependencies at the topAdd a task to bump the version number
gulp.task("bump", function() {
gulp.src("./project.json")
.pipe(bump())
.pipe(gulp.dest("./"));
});
Update project.json
1.0.0-*
, change this to 1.0.0
."gulp bump"
to the bottom of "scripts"
> "prepublish"
Now whenever you Publish, or dnu publish
or run the gulp Task Runner the version number will bump.
To display this version number in View add the following in the view;
@inject Microsoft.Extensions.PlatformAbstractions.IApplicationEnvironment appEnv
My version number is @(appEnv.ApplicationVersion)
This is what the ASP.NET 5 team actually uses themselves. If you are using a continuous integration build server you can get your build server to set the DNX_BUILD_VERSION
environment variable like so using PowerShell:
$env:DNX_BUILD_VERSION=$version
Your build machine then sets $version to 'build123' or something similar (It can't start with a number, has to be a character from the alphabet) Then, as long as your version number is set like so:
{
"version": "1.0.0-*"
}
The star will be replaced with the value in the DNX_BUILD_VERSION environment variable. See the ASP.NET 5 GitHub page here for more info.
For .NET Core (RTM) projects, you can use dotnet-bump. You can add it as a tool to your project, and call it from a postcompile script. http://github.com/BalassaMarton/dotnet-bump
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With