人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

June 10, 2006

设置AssemblyVersion

Filed under: 开发工具

1. DIY一个EXE.
http://code.mattgriffith.net/UpdateVersion/
http://code.mattgriffith.net/UpdateVersion/UpdateVersion-src-1.2.zip

用在Nant中修改AssemblyVersion
<project name=”ExecTest” default=”test”>
<target name=”test” description=”tests using exec to run UpdateVersion.exe”>
<echo message=”** Running UpdateVersion.exe.”/>
<exec program=”UpdateVersion.exe” commandline=”-b MonthDay -s 2002-01-21 -i Input.txt -o Output.txt” verbose=”true” failonerror=”true” />
<echo message=”** End of Tests”/>
</target>
</project>
Input.txt是一个包含AssemblyVersion的文本文件

也可以用在VS中;
Tools -> External Tools… -> Add :

Title: Update Version Number
Command: UpdateVersion.exe
Arguments: -b MonthDay -s 2002-11-23 -i “AssemblyInfo.cs” -o “AssemblyInfo.cs”
Initial directory: $(ProjectDir)
Use Output window: Checked

2.NAntContrib 中的 <version> task

<Version BuildType=”increment”
RevisionType=”increment”
Path=”$(BuildNumberFile)”
WriteVersionInfo=”true”
VersionInfoPath=”$(VersionInfoFile)”>
<Output TaskParameter=”BuildNumber” PropertyName=”BuildNumber”/>
</Version>

3. 在NAnt中使用脚本
<script language=”C#”>
<imports>
<import name=”System.Globalization” />
<import name=”System.Threading” />
</imports>
<code><![CDATA[
[Function(”test-func”)]
public static void ScriptMain(Project project)
{
Version version = new Version(project.Properties[”build.version”]);
int major = version.Major;
int minor = version.Minor;
int build = version.Build;
int revision = version.Revision;
if (build == -1)
{
DateTime start = Convert.ToDateTime(project.Properties[”startdate”]);
Calendar calendar = Thread.CurrentThread.CurrentCulture.Calendar;

int months = ((calendar.GetYear(DateTime.Today)
- calendar.GetYear(start)) * 12)
+ calendar.GetMonth(DateTime.Today)
- calendar.GetMonth(start);
int day = DateTime.Now.Day;
build = (months * 100) + day;
}
if (revision == -1)
{
TimeSpan difference = DateTime.Now.Subtract(DateTime.Today);
revision = (int)(difference.TotalSeconds / 10);
}
version = new Version(major, minor, build, revision);
project.Properties[”build.version”] = version.ToString();
}
]]></code>
</script>

<echo message=’${test::test-func()}’/>

4. 使用macor, 使用ProjectItem来查找AssemblyInfo,然后进行替换.
Auto Increment Build Numbers for C# Projects in VS.NET 2003
http://www.biasecurities.com/blogs/jim/archive/2003/10/08/166.aspx

Managing AssemblyVersion
http://weblogs.asp.net/sjoseph/archive/2004/02/19/76277.aspx

参考
Using Open Source .NET Tools for Sophisticated Builds

Versioning with NAnt
http://geekswithblogs.net/flanakin/archive/2004/08/16/9763.aspx

http://nant.sourceforge.net/release/latest/help/tasks/script.html

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/06/10/p104/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham