3

I'm building a C++ application on a CruiseControl.Net buildserver.

The build itself is done by msbuild and through cruisecontrol.net I have the desired version available - but I can't get it to be stamped into the c++ output.

Below is my msbuild project file.

Any comments are appreciated,

Anders, Denmark

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="FullBuild" ToolsVersion="3.5">
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
  <UsingTask TaskName="NCover.MSBuildTasks.NCover" AssemblyFile="C:\Program Files\NCover\Build Task Plugins\NCover.MSBuildTasks.dll"/>
  <UsingTask TaskName="NCover.MSBuildTasks.NCoverReporting" AssemblyFile="C:\Program Files\NCover\Build Task Plugins\NCover.MSBuildTasks.dll"/>

  <ItemGroup>
    <MyBinaries Include="Build\*.*"/>
  </ItemGroup>

  <PropertyGroup>
    <CCNetLabel Condition="$(CCNetLabel)==''">2.0.0.0</CCNetLabel>
  </PropertyGroup>

  <ItemGroup>
    <Projects Include="$(vsproject)" />
  </ItemGroup>

  <Target Name="Rebuild">
    <MSBuild Projects="@(Projects)" StopOnFirstFailure="true" ContinueOnError="false" Targets="Rebuild" Properties="version=$(CCNetLabel)" />
  </Target>

</Project>
Filburt
  • 17,626
  • 12
  • 64
  • 115
Anders Juul
  • 2,407
  • 3
  • 34
  • 56

3 Answers3

6

In your buildscript, create a file (version.info) which will look like this:

#define BINVERSION 1,2,3,4
#define STRVERSION "1.2.3.4"

You might need to create a small utility to do that.

In your resourcefile, you will have a versioninfo rescource, the start will look like this:

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,2,3,4
 PRODUCTVERSION 1,2,3,4
(...)
    VALUE "FileVersion", "1.2.3.4"
    VALUE "ProductVersion", "1.2.3.4"

Replace that with something like this:

VS_VERSION_INFO VERSIONINFO
 FILEVERSION BINVERSION
 PRODUCTVERSION BINVERSION
(...)
    VALUE "FileVersion", STRVERSION
    VALUE "ProductVersion", STRVERSION

Don't forget to add #include "version.info" at the top of the resource file

When you now compile your application, it will have the correct versionnumber. (if you correctly created the version.info).

Also take a look at Automatic Build Versioning in Visual Studio (codeproject)

wimh
  • 15,072
  • 6
  • 47
  • 98
2

I ended up just doing a search & replace on the .rc file.

Wimmels suggestion was good, but if I need to write a custom tool I might as well keep the rest simple. I tried out a single freeware search and replace tool, but it messes up the format of the rc file and it's really simple to do the replace yourself. For completeness, I include the code for search-replace below.

Thanks all!

Anders, Denmark

Target in msbuild project file:

<Target Name="UpdateVersion">
    <Exec Command="..\CCNetConfig\tools\SearchReplace\SearchReplace.exe project\project.rc $(CCNetLabel)"/>
  </Target>

Search & Replace:

  class Program
    {
        static void Main(string[] args)
        {
            if (args.Length!=2)
            {
                Console.WriteLine("Must call with two args:");
                Console.WriteLine("1 - File");
                Console.WriteLine("2 - Version");
                Environment.Exit(1);
            }

            var fileName = args[0];
            var version = args[1];
            var commaVersion = version.Replace(',', '.');

            var allLines = File.ReadAllLines(fileName).ToList();

            for (int i = 0; i < allLines.Count(); i++)
            {

                allLines[i] = allLines[i].Replace("1.0.0.1", version);
                allLines[i] = allLines[i].Replace("1,0,0,1", commaVersion);
            }

            File.WriteAllLines(fileName, allLines);
        }
    }
Anders Juul
  • 2,407
  • 3
  • 34
  • 56
1

From the CruiseControl.Net standpoint everything looks fine. The CCNetLabel property should have the correct value. You could print it out with the Message task just to be sure.

I don't have any experience with C++ projects, but if you're not using Visual Studio 2010, MSBuild is only delegating the build to VCBuild which could be the reason why the version you pass in is not being used (the same should happen if you manually call MSBuild with e.g. /p:version=1.2.3.4).

You might want to take a look at this question. Maybe you could solve your problem as well by overriding the vsprops file.

Community
  • 1
  • 1
Damir Arh
  • 17,637
  • 2
  • 45
  • 83