.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” 错误,解决方案为将 项目|项目属性|配置属性|清单工具|输入和输出|嵌入清单 ...
随机推荐
- Struts2入门(四)——数据输入验证
一.前言 1.1.什么是输入验证?为什么需要输入验证? 在上一篇文章中,我们学习了数据类型转换,我们提到了表示层数据处理的两个方法,也提到了用户输入数据需要进行类型转换才能得到我们想要的数据,那么,我 ...
- 【极品代码】一般人我不告诉他,手机端h5播放时不自动全屏代码
已测适用于ios,某些安卓手机微信下播放视频会出现播放器控件(这个实在是无力吐槽噢,因为之前还遇到过微信播放完视频后竟然无法退出全屏出现广告的情况,只有播放完后刷新页面并且要放到框架页里才能屏蔽微信视 ...
- 基于ARM处理器的反汇编器软件简单设计及实现
写在前面 2012年写的毕业设计,仅供参考 反汇编的目的 缺乏某些必要的说明资料的情况下, 想获得某些软件系统的源代码.设计思想及理念, 以便复制, 改造.移植和发展: 从源码上对软件的可靠性和安全性 ...
- Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"
同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...
- PHP中的数据库三、redis
h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...
- Linux 入门之修改主机名
vi /etc/hosts 修改 local.domain 为自己的主机名比如 compute
- 前端HTML之页面结构
前端工作一年了,期间由于工作需要,也做了一些产品的设计,因为自己的目标就是做编程,所以婉拒了与产品相关的一些任务,打算主要把精力放到编程这方面. PS:2015年1月进军编程行业. 废话不多讲,这一年 ...
- svn web页面管理svnadmin部署
1.yum install subversion 创建svn目录 mdkir -p /data/svndirroot 建立svn库 svnadmin create /data/svndirroo ...
- git 修改最后一次提交的用户名 或者 commit的内容
修改git最后一次提交的命令 $ git commit --amend 修改git最后一次提交用户名的相关命令 git config user.name 'wangz' git config user ...
- Linux-./configure: error: the HTTP rewrite module requires the PCRE library.
这个问题是要解决: yum -y install pcre-devel 然后在yum的时候发现出错.问题是我的linux不能上网. 这个问题搞得烦死了.和主机能ping.但是就是不能上网: ping ...