How can I auto-increment an MVC 6 version number?

前端 未结 3 1208
故里飘歌
故里飘歌 2020-12-09 20:43

Previous versions of ASP.NET allowed you to auto-increment the version number via Project Properties. How can I do this in MVC 6?

相关标签:
3条回答
  • 2020-12-09 20:54

    ASP.NET 5 (DNX) Answer

    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.

    0 讨论(0)
  • 2020-12-09 21:01

    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

    0 讨论(0)
  • 2020-12-09 21:03

    MVC 6 now uses project.json to track version and you can bump this number using gulp-bump.

    Version Bumping

    1. Add gulp-bump to package.json > devDependencies

      gulp-bump": "1.0.0"

    2. Edit gulpfile.js

      • Add bump = require("gulp-bump") to the dependencies at the top
      • Add a task to bump the version number

        gulp.task("bump", function() {
          gulp.src("./project.json")
          .pipe(bump())
          .pipe(gulp.dest("./"));
        });
        
    3. Update project.json

      • By default the MVC template sets the version number to 1.0.0-*, change this to 1.0.0.
      • Add "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.

    Bonus

    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)
    
    0 讨论(0)
提交回复
热议问题