8

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>
Kirk Liemohn
  • 7,733
  • 9
  • 46
  • 57

1 Answers1

9

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

Kepboy
  • 3,733
  • 2
  • 30
  • 43
Scott Weinstein
  • 18,890
  • 14
  • 78
  • 115