如何自动增加 MVC 6 版本号? [英] How can I auto-increment an MVC 6 version number?
问题描述
以前的 ASP.NET 版本允许您通过项目属性自动增加版本号.如何在 MVC 6 中做到这一点?
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 现在使用 project.json
来跟踪版本,你可以使用 gulp-bump.
MVC 6 now uses project.json
to track version and you can bump this number using gulp-bump.
将 gulp-bump 添加到 package.json >
devDependencies
gulp-bump": "1.0.0"
编辑 gulpfile.js
Edit gulpfile.js
- 将
bump = require("gulp-bump")
添加到顶部的依赖项中 添加任务来提升版本号
- 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("./"));
});
更新 project.json
Update project.json
- 默认情况下,MVC 模板将版本号设置为
1.0.0-*
,将其更改为1.0.0
. - 在
scripts"
的底部添加gulp bump"
>prepublish"
- By default the MVC template sets the version number to
1.0.0-*
, change this to1.0.0
. - Add
"gulp bump"
to the bottom of"scripts"
>"prepublish"
现在,无论何时发布,或 dnu 发布
或运行 gulp Task Runner,版本号都会发生变化.
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)
这篇关于如何自动增加 MVC 6 版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!