问题描述
以前的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
来跟踪版本,您可以使用.
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"
>"prepublish"
的底部添加
"gulp bump"
- 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 publish
或运行gulp Task Runner,版本号都会增加.
Now whenever you Publish, or dnu publish
or run the gulp Task Runner the version number will bump.
要在View中显示此版本号,请在视图中添加以下内容;
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版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!