hit*_*tec 41 svn cruisecontrol.net msbuild
我在一个示例项目中使用CCNET,SVN作为我的源代码控制.CCNET配置为在每次签入时创建构建.CCNET使用MSBuild构建源代码.
我想AssemblyInfo.cs在编译时使用最新的修订版号来生成.如何从subversion中检索最新版本并使用CCNET中的值?
编辑:我没有使用NAnt - 只有MSBuild.
sko*_*ima 45
CruiseControl.Net 1.4.4现在有一个Assembly Version Labeller,它生成与.Net程序集属性兼容的版本号.
在我的项目中,我将其配置为:
<labeller type="assemblyVersionLabeller" incrementOnFailure="true" major="1" minor="2"/>
Run Code Online (Sandbox Code Playgroud)
(警告:assemblyVersionLabeller在发生实际的提交触发构建之前,不会开始生成基于svn修订的标签.)
然后使用MSBuildCommunityTasks.AssemblyInfo从我的MSBuild项目中使用它:
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<Target Name="BeforeBuild">
<AssemblyInfo Condition="'$(CCNetLabel)' != ''" CodeLanguage="CS" OutputFile="Properties\AssemblyInfo.cs"
AssemblyTitle="MyTitle" AssemblyCompany="MyCompany" AssemblyProduct="MyProduct"
AssemblyCopyright="Copyright © 2009" ComVisible="false" Guid="some-random-guid"
AssemblyVersion="$(CCNetLabel)" AssemblyFileVersion="$(CCNetLabel)"/>
</Target>
Run Code Online (Sandbox Code Playgroud)
为了完善,使用NAnt而不是MSBuild的项目同样容易:
<target name="setversion" description="Sets the version number to CruiseControl.Net label.">
<script language="C#">
<references>
<include name="System.dll" />
</references>
<imports>
<import namespace="System.Text.RegularExpressions" />
</imports>
<code><![CDATA[
[TaskName("setversion-task")]
public class SetVersionTask : Task
{
protected override void ExecuteTask()
{
StreamReader reader = new StreamReader(Project.Properties["filename"]);
string contents = reader.ReadToEnd();
reader.Close();
string replacement = "[assembly: AssemblyVersion(\"" + Project.Properties["CCNetLabel"] + "\")]";
string newText = Regex.Replace(contents, @"\[assembly: AssemblyVersion\("".*""\)\]", replacement);
StreamWriter writer = new StreamWriter(Project.Properties["filename"], false);
writer.Write(newText);
writer.Close();
}
}
]]>
</code>
</script>
<foreach item="File" property="filename">
<in>
<items basedir="..">
<include name="**\AssemblyInfo.cs"></include>
</items>
</in>
<do>
<setversion-task />
</do>
</foreach>
</target>
Run Code Online (Sandbox Code Playgroud)
lub*_*sko 14
你基本上有两个选择.您可以编写一个简单的脚本来启动并解析输出
svn.exe信息--revision HEAD
获取修订版号(然后生成AssemblyInfo.cs非常简单)或只是使用CCNET插件.这里是:
SVN Revision Labeller是CruiseControl.NET的一个插件,允许您根据Subversion工作副本的修订版号为您的构建生成CruiseControl标签.这可以使用前缀和/或主要/次要版本号进行自定义.
我更喜欢第一个选项,因为它只有大约20行代码:
using System;
using System.Diagnostics;
namespace SvnRevisionNumberParserSample
{
class Program
{
static void Main()
{
Process p = Process.Start(new ProcessStartInfo()
{
FileName = @"C:\Program Files\SlikSvn\bin\svn.exe", // path to your svn.exe
UseShellExecute = false,
RedirectStandardOutput = true,
Arguments = "info --revision HEAD",
WorkingDirectory = @"C:\MyProject" // path to your svn working copy
});
// command "svn.exe info --revision HEAD" will produce a few lines of output
p.WaitForExit();
// our line starts with "Revision: "
while (!p.StandardOutput.EndOfStream)
{
string line = p.StandardOutput.ReadLine();
if (line.StartsWith("Revision: "))
{
string revision = line.Substring("Revision: ".Length);
Console.WriteLine(revision); // show revision number on screen
break;
}
}
Console.Read();
}
}
}
Run Code Online (Sandbox Code Playgroud)