Using CCNetLabel to set AssemblyVersion and PublishVersion with CruiseControl.NET

≡放荡痞女 提交于 2021-02-19 08:24:06

问题


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).


回答1:


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.




回答2:


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.




回答3:


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")]



来源:https://stackoverflow.com/questions/1638423/using-ccnetlabel-to-set-assemblyversion-and-publishversion-with-cruisecontrol-ne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!