是否可以更改 C# 项目的版本格式?
我想使用日期和时间作为版本号,而不是major.minor.build.revision 格式。 更像日.月.年.时间。 有没有办法更改 AssemblyInfo.cs 中的 AssemblyVersion 属性的格式?
Instead of the major.minor.build.revision format, I'd like to use date and time for version numbers. Something more like day.month.year.time. Is there a way to change the format of the AssemblyVersion attribute in AssemblyInfo.cs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以在其中放入任何您想要的数字(只要它们不会溢出内存中包含它们的数据类型)并根据您的意愿命名它们。 但是,我不确定您为什么要这样做,因为标准格式通常将某种形式的日期存储在 build 字段中。
例如,这是我们在工作中使用的程序集版本格式:
这告诉我这是库 5.1 版本的程序集,构建于 7 月 29 日,并且是当天的第一个构建。 同一天的后续构建只需增加修订字段即可。
You can put whatever numbers you want in there (as long as they don't overflow the data types that contain them in memory) and call them whatever you wish. I am not sure why you would want to do this, however, as the standard format usually has some form of the date stored in the build field.
For example, here is the assembly version format that we use where I work:
This tells me that this is an assembly from version 5.1 of the library, built on July 29th, and was the first build of the day. Subsequent builds on the same day simply increment the revision field.
最简单的方法是编写自己的构建任务来处理此问题,然后让 .csproj 文件调用您的任务以使用默认规则更新它。 有一篇关于使用自定义 MSBuild 任务来增加版本号的文章< /a> 可以作为指导。 我们过去在这里做过类似的事情,发现效果很好。
不过,我不相信 VS2005 中包含任何工具可以执行此操作。
The easiest approach is to write you own build task that handles this and then have the .csproj file call your task to update it with your default rules. There's an article on using a custom MSBuild task to increment version numbers that could serve as a guide. We have done a similar thing here in the past and found it to work well.
I don't believe there are any tools included in VS2005 for doing this, though.
我建议坚持使用
AssemblyVersion
等使用的版本号的现有方案 - 它们具有众所周知的含义,并且可能会迷惑人们来反对它们。但是,您可以轻松创建自己的程序集级属性并将其用于您的日期/时间。 不幸的是,
DateTime
类型无法嵌入元数据中,因此您可能最好使用字符串 - 但您的属性可以在执行时将其转换为DateTime
时间。I would suggest sticking to the existing scheme for the version numbers as used by
AssemblyVersion
etc - they have well-known meanings and it might confuse people to go against them.However, you can easily create your own assembly-level attribute and use that for your date/time. Unfortunately the
DateTime
type can't be embedded in metadata so you'd probably be best off using a string - but your attribute could convert that to aDateTime
for you at execution time.您可以在构建脚本中构建 assemblyinfo 代码的相关片段——使用 IronPython 或 F# 作为脚本工具非常容易。
You could build the relevant fragment of assemblyinfo code in a build script -- it's easy enough using IronPython or F# as a scripting tool.
如果您想使用脚本或类似的东西自动更改这些版本。 我建议使用 http://www.codeproject.com/KB/macros/versioningcontrolbuild。 aspx
它也可以从命令行运行。
If you would like to automatically change these versions with a script or something similar. I would suggest using http://www.codeproject.com/KB/macros/versioningcontrolledbuild.aspx
It can be ran from the command line also.