Question

How do I set an incoming value to a new value in msbuild?

Lets say I have this

  msbuild /t:package /p:revision=2.2

in my msbuild file I want to change the revision to another value in another variable. Let say I have:

 $(Version)

I know want my Version value to set Revision value.

revision = Version

How?

Example You get revision 1.0.0.0 in but want to set revision to what you have in your version?

Was it helpful?

Solution

You can do this by using PropertyGroups and Conditions. Save this MsBuild markup as "test.proj".

<Project DefaultTargets="VersionTest" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Version Condition="'$(Revision)' != ''">$(Revision)</Version>
    <Version Condition="'$(Version)' == ''">0.0.0.0</Version>
  </PropertyGroup>
  <Target Name="VersionTest">
    <Message Importance="high" Text="Revision is: $(Revision)" />
    <Message Importance="high" Text="Version is: $(Version)" />
  </Target>
</Project>

From a command prompt run msbuild.exe test.proj

VersionTest:
  Revision is:
  Version is: 0.0.0.0

Then run: msbuild test.proj /p:Revision=1.0.0.0

VersionTest:
  Revision is: 1.0.0.0
  Version is: 1.0.0.0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top