Msbuild C ++: how can I provide information about the desired version as a command line parameter?

I am creating a C ++ application on a CruiseControl.Net build server.

The assembly itself is done using msbuild, and through cruisecontrol.net I have the version I want, but I cannot seal it in C ++ output.

Below is my msbuild project project.

Any comments 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>
+3
source share
3 answers

In your buildscript, create a file (version.info) that looks like this:

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

You may need to create a small utility for this.

In your resource file you will have a resinfo version resource, the beginning 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 it like this:

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

#include "version.info"

, . ( .info).

Visual Studio (codeproject)

+5

.rc.

Wimmels , , , . , rc, . , - .

!

,

msbuild:

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

:

  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);
        }
    }
+2

CruiseControl.Net . CCNetLabel . Message, .

I have no experience working with C ++ projects, but if you are not using Visual Studio 2010, MSBuild delegates the assembly to VCBuild only , which may be the reason that the version you are passing is not used (the same thing happens if you manually call MSBuild, e.g. /p:version=1.2.3.4).

Perhaps you should take a look at this question . Perhaps you can also solve your problem by overriding the vsprops file.

+1
source

Source: https://habr.com/ru/post/1789744/


All Articles