.net 项目生成时自动更新版本号
https://www.codeproject.com/articles/31236/how-to-update-assembly-version-number-automaticall
Examples
AssemblyInfoUtil.exe -set:3.1.7.53 "C:\Program Files\MyProject1\AssemblyInfo.cs"
Set the version string to "3.1.7.53
".
AssemblyInfoUtil.exe -inc:4 AssemblyInfo.cs
Increase the last (revision) number. So in our case it will become 54
.
using System;
using System.IO;
using System.Text; namespace AssemblyInfoUtil
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class AssemblyInfoUtil
{
private static int incParamNum = ; private static string fileName = ""; private static string versionStr = null; private static bool isVB = false; /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
for (int i = ; i < args.Length; i++) {
if (args[i].StartsWith("-inc:")) {
string s = args[i].Substring("-inc:".Length);
incParamNum = int.Parse(s);
}
else if (args[i].StartsWith("-set:")) {
versionStr = args[i].Substring("-set:".Length);
}
else
fileName = args[i];
} if (Path.GetExtension(fileName).ToLower() == ".vb")
isVB = true; if (fileName == "") {
System.Console.WriteLine(@"Usage: AssemblyInfoUtil
<path to AssemblyInfo.cs or AssemblyInfo.vb file> [options]");
System.Console.WriteLine("Options: ");
System.Console.WriteLine(@" -set:<new version number> -
set new version number (in NN.NN.NN.NN format)");
System.Console.WriteLine(@" -inc:<parameter index> -
increases the parameter with specified index (can be from 1 to 4)");
return;
} if (!File.Exists(fileName)) {
System.Console.WriteLine
("Error: Can not find file \"" + fileName + "\"");
return;
} System.Console.Write("Processing \"" + fileName + "\"...");
StreamReader reader = new StreamReader(fileName);
StreamWriter writer = new StreamWriter(fileName + ".out");
String line; while ((line = reader.ReadLine()) != null) {
line = ProcessLine(line);
writer.WriteLine(line);
}
reader.Close();
writer.Close(); File.Delete(fileName);
File.Move(fileName + ".out", fileName);
System.Console.WriteLine("Done!");
} private static string ProcessLine(string line) {
if (isVB) {
line = ProcessLinePart(line, "<Assembly: AssemblyVersion(\"");
line = ProcessLinePart(line, "<Assembly: AssemblyFileVersion(\"");
}
else {
line = ProcessLinePart(line, "[assembly: AssemblyVersion(\"");
line = ProcessLinePart(line, "[assembly: AssemblyFileVersion(\"");
}
return line;
} private static string ProcessLinePart(string line, string part) {
int spos = line.IndexOf(part);
if (spos >= ) {
spos += part.Length;
int epos = line.IndexOf('"', spos);
string oldVersion = line.Substring(spos, epos - spos);
string newVersion = "";
bool performChange = false; if (incParamNum > ) {
string[] nums = oldVersion.Split('.');
if (nums.Length >= incParamNum && nums[incParamNum - ] != "*") {
Int64 val = Int64.Parse(nums[incParamNum - ]);
val++;
nums[incParamNum - ] = val.ToString();
newVersion = nums[];
for (int i = ; i < nums.Length; i++) {
newVersion += "." + nums[i];
}
performChange = true;
}
} else if (versionStr != null) {
newVersion = versionStr;
performChange = true;
} if (performChange) {
StringBuilder str = new StringBuilder(line);
str.Remove(spos, epos - spos);
str.Insert(spos, newVersion);
line = str.ToString();
}
}
return line;
}
}
}
预先生成事件命令行:(对 AssemblyVersion 和 AssemblyFileVersion 属性的最后一位执行+1处理)
if $(ConfigurationName) == Release (
call $(SolutionDir)AssemblyInfoUtil.exe -inc:4 $(ProjectDir)Properties\AssemblyInfo.cs
)
或者使用VS插件也是一个不错的选择:
Automatic Versions
.net 项目生成时自动更新版本号的更多相关文章
- 扩展BindingList,防止增加、删除项时自动更新界面而不出现“跨线程操作界面控件 corss thread operation”异常
在做界面程序时,常常需要一些数据类,界面元素通过绑定等方式显示出数据,然而由于UI线程不是线程安全的,一般都需要通过Invoke等方式来调用界面控件.但对于数据绑定bindingList而言,没法响应 ...
- winform datagridview 不显示默认第一列 不显示未绑定列 数据源发生改变时自动更新 (转)
不显示带星号的第一列: datagridview属性框中将 RowHeadersVisiber 设置为 false 不显示未绑定列: datagridview有一个属性是 AutoGenerateC ...
- Android Studio生成APK自动追加版本号、自定义apk名称、指定签名证书文件
你也可以查看我的其他同类文章,也会让你有一定的收货! 生成APK自动追加版本号 可自动区分debug和release,并追加版本号: 打开 build.gradle 在 android 节点中插入下面 ...
- [Azure DevOps] 编译时自动修改版本号
1. 需求 在使用 Pipeline 自动化 CI/CD 流程的过程中,我还还需要自动修改程序集的版本号.这个功能 EdiWang 和LeoLaw 都写文章讲解过做法.不过我的项目基本都是 .Net ...
- 神奇的bug,退出时自动更新时间
遇到一个神奇的bug,用户退出时,上次登录时间会变成退出时的时间. 于是开始跟踪,发现Laravel在退出时,会做一次脏检查,这时会更新rember_token,这时就会有update操作如下. 而粗 ...
- mysql设置updatetime字段每次修改时自动更新
我们在数据库表设计阶段中都会加上CreateTime, UpdateTime字段, 在重要业务字段更新的时候,都会重新赋值UpdateTime字段,这个对后期查找分析业务数据变更时非常有用. 但是现在 ...
- (转载)让XCode运行时自动更新资源
转自http://goldlion.blog.51cto.com/4127613/1351616 用过XCode的人都知道,XCode有一个臭名昭著的bug——除非你修改了源代码造成了重新编译,否则游 ...
- [QuickX]xcode运行Quick-cocos2d-x项目时自动更新lua资源文件
1.项目设置 build settings ->build options ->Scan all source files and Includes = YES 2.加入script (1 ...
- VS2010 win7 64位安装后新建项目生成时错误:LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
解决方案:VS2010在经历一些更新后,建立Win32 Console Project时会出“error LNK1123” 错误,解决方案为将 项目|项目属性|配置属性|清单工具|输入和输出|嵌入清单 ...
随机推荐
- Android 手机卫士7--黑名单拦截
1,黑名单数据库创建 三个字段(_id 自增长字段 phone 黑名单号码 mode 拦截类型) 创建表的sql语句 create table blacknumber (_id integer pri ...
- vue2.0 非父子组件如何通信
1 利用父组件传递 A组件传递到父组件,再由父组件传递到B组件 2 利用新的vue实例 var bus = new Vue() // 触发组件 A 中的事件 bus.$emit('id-selecte ...
- 强大的observejs
写在前面 各大MVVM框架的双向绑定太难以观察,很难直观地从业务代码里知道发生了什么,我不是双向绑定的反对者,只是认为双向绑定不应该糅合进底层框架,而应该出现在业务代码中,或者是业务和框架之间的代码上 ...
- Andriod 自定义控件之创建可以复用的组合控件
前面已学习了一种自定义控件的实现,是Andriod 自定义控件之音频条,还没学习的同学可以学习下,学习了的同学也要去温习下,一定要自己完全的掌握了,再继续学习,贪多嚼不烂可不是好的学习方法,我们争取学 ...
- Android面试题(一)
1. 请描述一下Activity 生命周期. 答: 如下图所示.共有七个周期函数,按顺序分别是: onCreate(), onStart(), onRestart(), onResume(), onP ...
- WKWebView浅析
原文链接:supermokey WKWebView 一个WKWebView对象展示交互的web内容,例如应用于app内的浏览器.你可以在你的App中使用WKWebView. 综述 Important: ...
- java实现敏感词过滤(DFA算法)
小Alan在最近的开发中遇到了敏感词过滤,便去网上查阅了很多敏感词过滤的资料,在这里也和大家分享一下自己的理解. 敏感词过滤应该是不用给大家过多的解释吧?讲白了就是你在项目中输入某些字(比如输入xxo ...
- (视频)Erich Gamma 与 Visual Studio Online 的一点野史
大家对Erich Gamma的熟悉应该都集中在<设计模式>, Eclipse以及最近微软所发布的Visual Studio Code跨平台代码编辑器.其实在Erich加入微软的头几年里,他 ...
- [Erlang 0119] Erlang OTP 源码阅读指引
上周Erlang讨论群里面提到lists的++实现,争论大多基于猜测,其实打开代码看一下就都明了.贴出代码截图后有同学问这代码是哪里找的? "代码去哪里找?",关于Erla ...
- [Erlang 0112] Elixir Protocols
Why Elixir 为什么要学习Elixir?答案很简单,为了更好的学习Erlang.这么无厘头的理由? Erlang语法设计几乎没有考虑过取悦开发者,所以学习之初的门槛略高.对于已经克服了最初 ...