我使用CCNET上的一个样本项目SVN为我源的控制。CCNET构成为创建一个建立在每一个检查中。CCNET使用MSBuild建立的源码。

我想用最新修订编号,以产生 AssemblyInfo.cs 同时,编译。我怎么可以检索的最新修订,从颠复和使用的价值在CCNET?

编辑:我不用NAnt只MSBuild。

有帮助吗?

解决方案

CruiseControl.Net 1.4.4现在有一个 大会版贴标签机, ,其产生的版本号兼容。净组件的性质。

在我的项目,我有它配置为:

<labeller type="assemblyVersionLabeller" incrementOnFailure="true" major="1" minor="2"/>

(注意: assemblyVersionLabeller 会不会开始产生svn修订的基于的标签,直至实际犯下触发的建立发生。)

然后消费的这个从我的MSBuild项目 MSBuildCommunityTasks.程序集信息 :

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

为了completness,它只是作为容易的项目使用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>

其他提示

你基本上有两种选择。要么你写一个简单的脚本,这将启动和分析输出

svn.exe 信息--修订版头

获得修订号(然后生成程序集信息.cs几乎是直接的),或只是使用的插件对CCNET.这里是:

SVN修订贴标签机 是一个插件 CruiseControl.净,允许你 产生CruiseControl的标签 建造,根据的修订数量 你的颠复工作副本。此 可以用一种前缀和/或 大/最小版本的数字。

http://code.google.com/p/svnrevisionlabeller/

我喜欢第一个选项,因为它是仅有约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();
        }
    }
}

我已经写了一个NAnt建立文件处理析SVN信息和创造性。然后我用这些财产值用于各种建设任务,包括设置标签上的建立。我用这个目标结合SVN修订贴标签机提到lubos hasko与重大成果。

<target name="svninfo" description="get the svn checkout information">
    <property name="svn.infotempfile" value="${build.directory}\svninfo.txt" />
    <exec program="${svn.executable}" output="${svn.infotempfile}">
        <arg value="info" />
    </exec>
    <loadfile file="${svn.infotempfile}" property="svn.info" />
    <delete file="${svn.infotempfile}" />

    <property name="match" value="" />

    <regex pattern="URL: (?'match'.*)" input="${svn.info}" />
    <property name="svn.info.url" value="${match}"/>

    <regex pattern="Repository Root: (?'match'.*)" input="${svn.info}" />
    <property name="svn.info.repositoryroot" value="${match}"/>

    <regex pattern="Revision: (?'match'\d+)" input="${svn.info}" />
    <property name="svn.info.revision" value="${match}"/>

    <regex pattern="Last Changed Author: (?'match'\w+)" input="${svn.info}" />
    <property name="svn.info.lastchangedauthor" value="${match}"/>

    <echo message="URL: ${svn.info.url}" />
    <echo message="Repository Root: ${svn.info.repositoryroot}" />
    <echo message="Revision: ${svn.info.revision}" />
    <echo message="Last Changed Author: ${svn.info.lastchangedauthor}" />
</target>

我找到了 项目在谷歌的代码。这个是 CCNET 插件产生的标签 CCNET.

DLL 是测试 CCNET 1.3 但它的工作原理 CCNET 1.4 对我来说。我成功地利用这个插件签了我的建立。

现在到过它 MSBuild...

如果你喜欢做的 MSBuild 侧过 CCNet config,看起来像 MSBuild 社会的任务扩展的 SvnVersion 任务可能做到。

我目前正"的手动"做的,它通过一个预生成-exec的任务,使用我的 cmdnetsvnrev 工具,但如果有人知道一个更好的ccnet综合的方式这样做,我很高兴听到这个消息:-)

定制csproj的文件自动生成程序集信息.cs
http://www.codeproject.com/KB/dotnet/Customizing_csproj_files.aspx

每次我们创建了一个新C#项目, Visual Studio放在那里 程序集信息.cs文件对于我们。该文件 定义大会的元数据等 它的版本,配置,或 生产者。

找到上述技术来自动艮程序集信息.cs使用MSBuild。会后的样品。

我不知道,如果这项工作与CCNET或者没有,但我已经创建了一个 SVN版的插件建立版本的增加 项目上更.这一工具非常灵活,可能设置自动创建一个版本的编号为你使用svn修订。它不需要编写任何代码或编辑xml,所以耶!

我希望这是帮助!

我的方法是使用前述的插件对ccnet和nant echo任务产生一个 VersionInfo.cs 文件含有什么,但版本属性。我只需要包括的 VersionInfo.cs 文件成的建立

回声任务只是输出的串我把它给一个文件。

如果有一个类似的MSBuild任务,可以使用相同的方法。这里的小nant任务我的使用:

<target name="version" description="outputs version number to VersionInfo.cs">
  <echo file="${projectdir}/Properties/VersionInfo.cs">
    [assembly: System.Reflection.AssemblyVersion("$(CCNetLabel)")]
    [assembly: System.Reflection.AssemblyFileVersion("$(CCNetLabel)")]
  </echo>
</target>

试试这个:

<ItemGroup>
    <VersionInfoFile Include="VersionInfo.cs"/>
    <VersionAttributes>
        [assembly: System.Reflection.AssemblyVersion("${CCNetLabel}")]
        [assembly: System.Reflection.AssemblyFileVersion("${CCNetLabel}")]
    </VersionAttributes>
</ItemGroup>
<Target Name="WriteToFile">
    <WriteLinesToFile
        File="@(VersionInfoFile)"
        Lines="@(VersionAttributes)"
        Overwrite="true"/>
</Target>

请注意,我不是很亲密的MSBuild,所以我的脚可能不会作出的箱和需要的更正...

根据skolimas解决方案我更新的NAnt脚本来还更新AssemblyFileVersion.由于skolima的代码!

<target name="setversion" description="Sets the version number to current 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();                     
                       // replace assembly version
                       string replacement = "[assembly: AssemblyVersion(\"" + Project.Properties["label"] + "\")]";
                       contents = Regex.Replace(contents, @"\[assembly: AssemblyVersion\("".*""\)\]", replacement);                                        
                       // replace assembly file version
                       replacement = "[assembly: AssemblyFileVersion(\"" + Project.Properties["label"] + "\")]";
                       contents = Regex.Replace(contents, @"\[assembly: AssemblyFileVersion\("".*""\)\]", replacement);                                        
                       StreamWriter writer = new StreamWriter(Project.Properties["filename"], false);
                       writer.Write(contents);
                       writer.Close();
                      }
                     }
                     ]]>
            </code>
        </script>
        <foreach item="File" property="filename">
            <in>
                    <items basedir="${srcDir}">
                            <include name="**\AssemblyInfo.cs"></include>
                    </items>
            </in>
            <do>
                    <setversion-task />
            </do>
        </foreach>
    </target>

不知道我在哪里发现了这个。但是我发现这个在互联网上的"地方".

这将更新所有程序集信息.cs文件之前建立。

就像一个特色。我所有的可执行软件和dll显示为1.2.3.333(如果"333"是SVN修订的时间。) (以及原始版本的程序集信息.cs文件被列为"1.2.3.0")


$(ProjectDir)(其中我。sln文件所)

$(SVNToolPath)(点svn.exe)

是我定制的变量,它们的声明/定义不下定义。


http://msbuildtasks.tigris.org/ 和/或 https://github.com/loresoft/msbuildtasks 有的(FileUpdate和SvnVersion)的任务。


  <Target Name="SubVersionBeforeBuildVersionTagItUp">

    <ItemGroup>
      <AssemblyInfoFiles Include="$(ProjectDir)\**\*AssemblyInfo.cs" />
    </ItemGroup>

    <SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(SVNToolPath)">
      <Output TaskParameter="Revision" PropertyName="MySubVersionRevision" />
    </SvnVersion>

    <FileUpdate Files="@(AssemblyInfoFiles)"
            Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
            ReplacementText="$1.$2.$3.$(MySubVersionRevision)" />
  </Target>

编辑--------------------------------------------------

上述可能启动失败后你SVN修订的数量达到65534或更高。

参见:

关闭警告CS1607

这里是解决方法。

<FileUpdate Files="@(AssemblyInfoFiles)"
Regex="AssemblyFileVersion\(&quot;(\d+)\.(\d+)\.(\d+)\.(\d+)"
ReplacementText="AssemblyFileVersion(&quot;$1.$2.$3.$(SubVersionRevision)" />

这样的结果应该是:

在Windows/Explorer//文件/性。......

大会版本将于1.0.0.0.

文件的版本将1.0.0.333如果333SVN修订。

要小心。使用的结构为建立数字只是一个短暂的让你有一个天花板上有多高你的修订可以走了。

在我们的情况下,我们已经超过极限。

如果你试图把在建立数99.99.99.599999,该文件版本的财产实际上将出来作为99.99.99.10175.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top