Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MSBuild, how do I set a property to the contents of a file?

Tags:

msbuild

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>
like image 263
Kirk Liemohn Avatar asked Jul 02 '09 16:07

Kirk Liemohn


1 Answers

The ReadLinesFromFile task is what you want

<ReadLinesFromFile File="Version.Txt">
    <Output TaskParameter="Lines" ItemName="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">
 <PropertyGroup>
   <BuildNumber>10</BuildNumber>
   <RevNumber>5</RevNumber>
 </PropertyGroup>
</Project>

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

like image 95
Scott Weinstein Avatar answered Nov 08 '22 11:11

Scott Weinstein