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

前端 未结 3 1207
故里飘歌
故里飘歌 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 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)
    

提交回复
热议问题