I am trying to deploy a Click Once application (build and publish) using CruiseControl.NET. I cannot find out where I can开发者_运维问答 use the CCNetLabel to set my AssemblyVersion and/or PublishVersion. I would accept other solutions that would allow a unique version number per CruiseControl.NET deployment (Live and Development deployments).
You need to write a script for setting your AssemblyVersion. I would recommend using NAnt or MSBuild for that purpose, but PowerShell or a simple bat file will also do.
In your CCNET configuration you use Assembly Version Labeller. CCNetLabel is available then inside the script via ${CCNetLabel}
(NAnt) resp. environment variable %CCNetLabel%
(batch - try different casings, since I know they have an issue with that).
The script's task is to either edit the project's AssemblyInfo.cs file or create a CommonAssemblyInfo.cs file and reference it from the project for the build.
SO search for
[cruisecontrol.net] assemblyinfo
yields more valuable advice.
You need to set it before the compile in your AssemblyInfo.cs as the other answerer points out. The Assembly Version Labeller is great, but it doesn't work with svn. If you use svn, you might want to have a look at the svn revision labeller.
Once you get the label generating properly, you can use that in your CC or Nant script when creating/editing the AssemblyInfo.cs file. If you're using Nant, then the asminfo task will be of great help for you. An SO search would be good, but you might also want to have a look at this article, which should be very helpful.
You can achieve this with a Nant C# snipped describe here
Create a property called ${assemblyinfo.file} which points to the AssemblyInfo.cs file in your project.
<!-- Updating assembly version with the CI build http://lazyloading.blogspot.com/2007/05/updating-assembly-version-with-ci.html -->
<target name="update.assembly" description="Replaces the version in the assemblyinfo.cs file">
<echo message="AssemblyInfo: ${assemblyinfo.file}" />
<echo message="Version: ${CCNetLabel}" />
<script language="C#">
<references>
<include name="System.dll" />
</references>
<imports>
<import namespace="System.Text.RegularExpressions" />
</imports>
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
string fileContent="";
using (StreamReader reader = new StreamReader(project.Properties["assemblyinfo.file"]))
{
fileContent = reader.ReadToEnd();
reader.Close();
}
string newVersion = string.Format("[assembly: AssemblyVersion(\"{0}\")]", project.Properties["CCNetLabel"]);
string newText = Regex.Replace(fileContent, @"\[assembly: AssemblyVersion\("".*""\)\]", newVersion);
using (StreamWriter writer = new StreamWriter(project.Properties["assemblyinfo.file"], false))
{
writer.Write(newText);
writer.Close();
}
}
]]>
</code>
</script>
</target>
Example:
[assembly: AssemblyVersion("1.0.*")]
becomes
[assembly: AssemblyVersion("2013.03.11.001")]
精彩评论