tags:

views:

613

answers:

1

I have a file that I set using PowerShell that contains the version number of my build. I need to get this within MSBuild so I can act on it within my build script. It seems simple enough; I just want to take the contents of the file and set a property to that value.

I thought maybe doing an Exec task, doing a "more" on my file, and capturing standard out would do the trick, but I can't seem to get this to work. It appears that others have had problems with stdout and MSBuild as well. Here is what I have tried:

<Exec Command="more $(BuildDirectory)\version.txt" Outputs="stdout">
    <Output TaskParameter="Outputs" ItemName="BuildNumber" />
</Exec>
+1  A: 

The ReadLinesFromFile task is what you want

<ReadLinesFromFile File="Version.Txt">
    <Output TaskParameter="Lines" Item="BuildNumber"/>
</ReadLinesFromFile>

that said, another way to do what your question implies is to store you build num info in an xml file, with a MSBuild schema

something like

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
 <PropertyGroup>
   <BuildNumber>10</BuildNumber>
   <RevNumber>5</RevNumber>
 </PropertyGroup>
</Project>

and then import the version.properties file into your main msbuild file

Scott Weinstein
Thanks! I just couldn't find that task. FYI, there is a slight bug in your first code snippet. It is ItemName instead of Item: <ReadLinesFromFile File="$(BuildDirectory)\version.txt"> <Output TaskParameter="Lines" ItemName="BuildNumber" /> </ReadLinesFromFile>Then I can access the output using "@(BuildNumber)".
Kirk Liemohn
Ack - now I need to change from a list item (@) to a property ($). Any tips on this?
Kirk Liemohn
I think I figured it out:<CreateProperty Value="@(BuildNumber)"> <Output TaskParameter="Value" PropertyName="BuildNumberValue" /></CreateProperty>
Kirk Liemohn