简体   繁体   English

如何在TFS 2017 Build之后通过TFS Build Job中的Shell脚本自动递增asp.net核心应用程序版本并将其显示在index.html页脚中

[英]How to auto increment asp.net core application version via shell script in TFS Build Job after TFS 2017 Build and show it in the footer of index.html

i'm using TFS 2017 for CI, Version defined in csproj file as below should be auto-incremented after every TFS build, 我使用TFS 2017 for CI,每次TFS生成后,在csproj文件中定义的版本(如下所示)应自动递增,

<PropertyGroup>
    <Major Condition=" '$(Major)' == '' ">1</Major>
    <Minor Condition=" '$(Minor)' == '' ">0</Minor>
    <Patch Condition=" '$(Patch)' == '' ">0</Patch>
    <VersionPrefix>$(Major).$(Minor).$(Patch)</VersionPrefix>
</PropertyGroup>

I added Major, Minor and Patch varibles on TFS Job, my question is how to increment these variables in TFS BUILD. 我在TFS作业上添加了Major,Minor和Patch变量,我的问题是如何在TFS BUILD中增加这些变量。

I solve the problem by using Bump to increment version in package.json file, 我通过使用凹凸来增加package.json文件中的版本来解决该问题,

var gulp = require('gulp');
var bump = require('gulp-bump');

// Basic usage:
// Will patch the version
gulp.task('bump', function(){
  gulp.src('./component.json')
  .pipe(bump())
  .pipe(gulp.dest('./'));
});

// Defined method of updating:
// Semantic
gulp.task('bump', function(){
  gulp.src('./*.json')
  .pipe(bump({type:'minor'}))
  .pipe(gulp.dest('./'));
});

// Defined method of updating:
// Semantic major
gulp.task('bump', function(){
  gulp.src('./package.yml')
  .pipe(bump({type:'major'}))
  .pipe(gulp.dest('./'));
});

// Defined method of updating:
// Set a specific version
gulp.task('bump', function(){
  gulp.src('./*.json')
  .pipe(bump({version: '1.2.3'}))
  .pipe(gulp.dest('./'));
});

// Update bower, component, npm at once:
gulp.task('bump', function(){
  gulp.src(['./bower.json', './component.json', './package.json'])
  .pipe(bump({type:'major'}))
  .pipe(gulp.dest('./'));
});

// Define the key for versioning off
gulp.task('bump', function(){
  gulp.src('./package.json')
  .pipe(bump({key: "appversion"}))
  .pipe(gulp.dest('./'));
}); 

icreated 3 Jobs in TSF, evry job is responsable for incrementing one of Major, Minor and Patch, so while commiting developer will choose to excute one of these jobs, wich will excute the concrete gulp Task. 在TSF中创建了3个工作,每个工作负责增加Major,Minor和Patch之一,因此在提交开发人员将选择执行其中一项工作的同时,还将执行具体的任务。

If your code is stored in TFS server there is one way to update your project. 如果您的代码存储在TFS服务器中,则有一种方法可以更新您的项目。 I recommend update your project to .net core 2 downloading dependencies of version. 我建议将您的项目更新为.net core 2下载版本的依赖项。 Then update your project file. 然后更新您的项目文件。 here is good article of updating your version. 这是更新您的版本的好文章。

https://www.stevejgordon.co.uk/upgrading-to-asp-net-core-2-0 https://www.stevejgordon.co.uk/upgrading-to-asp-net-core-2-0

You can try to set the build number format as $(Major).$(Minor)-rev$(Rev:.rr) , then update the application version with the variable $(Build.BuildNumber) 您可以尝试将内部版本号格式设置为$(Major).$(Minor)-rev$(Rev:.rr) ,然后使用变量$(Build.BuildNumber)更新应用程序版本。

What is $(Rev:.rr)? 什么是$(Rev:.rr)?

To ensure that every completed build has a unique name. 确保每个完成的构建都有唯一的名称。 When a build is completed, if nothing else in the build number has changed, the Rev integer value is incremented by one. 构建完成后,如果内部版本号没有其他更改,则Rev整数值将增加1。

Source: MSDN 资料来源: MSDN

You can use the .NET Core CLI tool to update the version information in .NET Core *.csproj files. 您可以使用.NET Core CLI工具来更新.NET Core * .csproj文件中的版本信息。


Other threads may helps: 其他线程可能会有所帮助:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM