Set an incoming value to a new value

98 views Asked by At

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?

1

There are 1 answers

4
Nicodemeus On BEST ANSWER

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