Użyj wersji SVN do etykietowania kompilacji w CCNET

Używam CCNET w przykładowym projekcie Z SVN jako moją kontrolą źródłową. CCNET jest skonfigurowany tak, aby tworzyć kompilację przy każdej odprawie. CCNET używa MSBuild do budowania kodu źródłowego.

Chciałbym użyć najnowszego numeru wersji do wygenerowania AssemblyInfo.cs podczas kompilacji. Jak mogę pobrać najnowszą wersję z subversion i użyć wartości w CCNET?

Edit: nie używam nant - tylko MSBuild.

Author: Paul Ratazzi, 2008-08-04

12 answers

CruiseControl.Net 1.4.4 posiada teraz Etykietę Assembly Version Labeller , która generuje numery wersji zgodne z właściwościami.Net assembly.

W moim projekcie mam skonfigurowany jako:

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

(Zastrzeżenie: assemblyVersionLabeller nie zacznie generować etykiet opartych na rewizji svn, dopóki nie dojdzie do kompilacji wywołanej zatwierdzeniem.)

A następnie skonsumować to z moich projektów MSBuild z MSBuildCommunityTasks.AssemblyInfo :

<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>
/ Align = "center" bgcolor = "# e0ffe0 " / cesarz chin / / align = center / jak łatwo dla projektów używających NAnt zamiast 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>
 44
Author: skolima,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-09-21 15:30:00

Masz zasadniczo dwie opcje. Albo napiszesz prosty skrypt, który rozpocznie i przetworzy wyjście z

Svn.exe info --revision HEAD

Aby uzyskać numer wersji (następnie wygenerować AssemblyInfo.cs jest prawie prosto) lub po prostu użyj wtyczki dla CCNET. Tutaj jest:

SVN Revision Labeller {[5] } jest wtyczką do CruiseControl.NET to pozwala na generowanie etykiet CruiseControl dla Twojego buduje, w oparciu o numer wersji z twoja kopia robocza Subversion. To można dostosować za pomocą prefiksu i / lub główne / poboczne numery wersji.

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

Wolę pierwszą opcję, ponieważ jest to tylko około 20 linijek kodu:

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();
        }
    }
}
 14
Author: lubos hasko,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-07 00:39:57

Napisałem plik nant, który obsługuje parsowanie informacji SVN i tworzenie właściwości. Następnie używam tych wartości właściwości do różnych zadań budowania, w tym ustawiania etykiety na kompilacji. Używam tego celu w połączeniu z etykietą SVN revision wspomnianą przez Lubosa hasko z świetnymi wynikami.

<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>
 4
Author: Justin Walgran,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-08-04 13:43:54

ZnalazłemTen projekt w Google code. Jest to wtyczka CCNET do generowania etykiety w CCNET.

DLL jest testowany z CCNET 1.3, ale działa z CCNET 1.4 dla mnie. Z powodzeniem używam tej wtyczki, aby oznaczyć mój build.

A teraz przechodzimy do MSBuild...

 4
Author: hitec,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-25 12:49:09

Jeśli wolisz robić to po stronie MSBuild nad konfiguracją CCNet, wygląda jak rozszerzenie Zadań społeczności MSBuildSvnVersion zadanie może załatwić sprawę.

 4
Author: Rytmis,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-25 13:00:54

Obecnie robię to "ręcznie" za pomocą prebuild-exec, używając mojego narzędzia cmdnetsvnrev , ale jeśli ktoś zna lepszy sposób na zrobienie tego w ccnet, chętnie usłyszę: -)

 3
Author: Michael Stum,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-08-04 11:41:37

Dostosowywanie plików csproj do autogeneracji AssemblyInfo.cs
http://www.codeproject.com/KB/dotnet/Customizing_csproj_files.aspx

Za każdym razem, gdy tworzymy nowy projekt C# , Visual Studio stawia tam AssemblyInfo.plik cs dla nas. Plik definiuje meta-dane asemblera jak jego wersję, konfigurację lub producent.

Znalazłem powyższą technikę do auto-gen AssemblyInfo.cs using MSBuild. Wkrótce opublikuje próbkę.

 3
Author: hitec,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-08-04 13:22:31

Nie jestem pewien, czy to działa z CCNET, czy nie, ale stworzyłem SVN version plug-in dla projektu Build Version Increment Na CodePlex. To narzędzie jest dość elastyczne i można je ustawić tak, aby automatycznie tworzyć numer wersji za pomocą wersji svn. Nie wymaga pisania żadnego kodu ani edycji xml, więc yay!

Mam nadzieję, że to pomoże!

 3
Author: grimus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-04-12 01:04:20

Moje podejście polega na użyciu wspomnianej wtyczki dla ccnet i zadania nant echo do wygenerowania pliku VersionInfo.cs zawierającego tylko atrybuty wersji. Muszę tylko dołączyć plik VersionInfo.cs do build

Zadanie echo po prostu wysyła łańcuch, który podaję do pliku.

Jeśli istnieje podobne zadanie MSBuild, możesz użyć tego samego podejścia. Oto małe zadanie nant, którego używam:

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

Spróbuj tego:

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

Proszę zauważyć, że nie jestem zbyt blisko z MSBuild, więc mój skrypt prawdopodobnie nie będzie działać out-of-the-box i wymaga poprawek...

 2
Author: R. Martinho Fernandes,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-02-03 04:27:12

W oparciu o rozwiązanie skolimas zaktualizowałem skrypt NAnt, aby również zaktualizować AssemblyFileVersion. Podziękowania dla skolima za Kod!

<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>
 2
Author: galaktor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-12 10:03:28

Nie mam pojęcia, gdzie to znalazłem. Ale znalazłem to w Internecie "gdzieś".

To aktualizuje wszystkie AssemblyInfo.pliki cs przed rozpoczęciem kompilacji.

Działa jak urok. Wszystkie moje exe i dll są wyświetlane jako 1.2.3.333 (jeśli "333" były rewizją SVN w tym czasie.) (Oraz oryginalną wersję w AssemblyInfo.plik cs został wymieniony jako "1.2.3.0")

$(ProjectDir) (Where my .plik sln)

$(SVNToolPath) (wskazuje na svn.exe)

Are my zmienne niestandardowe, ich deklaracje/definicje nie są zdefiniowane poniżej.


Http://msbuildtasks.tigris.org / i / lub https://github.com/loresoft/msbuildtasks posiada zadania (FileUpdate i 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>

Edytuj --------------------------------------------------

Powyższe może zacząć zawodzić po tym, jak numer wersji SVN osiągnie 65534 lub wyższy.

Zobacz:

Wyłącz Ostrzeżenie CS1607

Oto obejście.

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

Wynikiem tego powinno być:

W Windows/Explorer//File/Properties......

Wersja Assembly będzie 1.0.0.0.

Wersja pliku będzie 1.0.0.333 jeśli 333 jest wersją SVN.

 2
Author: granadaCoder,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:46:30

Bądź ostrożny. Struktura użyta w numerach kompilacji jest tylko krótka, więc możesz określić pułap wysokości wersji.

W naszym przypadku już przekroczyliśmy limit.

Jeśli spróbujesz umieścić w kompilacji numer 99.99.99.599999, właściwość file version faktycznie wyjdzie jako 99.99.99.10175.

 1
Author: Dan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-02-03 18:34:49