I'm trying to read a version number from a file in MSBuild:
<ItemGroup>
<VersionFile Include="Properties\VERSION" />
</ItemGroup>
<Target Name="BeforeBuild">
<ReadLinesFromFile File="@(VersionFile)">
<Output TaskParameter="Lines" ItemName="VersionNumber" />
</ReadLinesFromFile>
</Target>
I only need the first line of this file. How can I concatenate that value with another string in WriteLinesToFile
? This does not work:
<WriteLinesToFile
File="$(AssemblyVersionFile)"
Lines="[assembly: AssemblyVersion("@(VersionNumber)")]" />
I get an error:
error MSB4012: The expression "[assembly: AssemblyVersion("@(VersionNumber)")]" cannot be used in this context. Item lists cannot be concatenated with other strings where an item list is expected. Use a semicolon to separate multiple item lists.`
I'm not too familiar with MSBuild but changing the Output
of ReadLinesFromFile to be a Property and using $
to access it in the WriteLinesToFile seems to work:
<Target Name="BeforeBuild">
<ReadLinesFromFile File="@(VersionFile)">
<Output TaskParameter="Lines" PropertyName="VersionNumber" />
</ReadLinesFromFile>
<WriteLinesToFile
File="output.txt"
Lines="[assembly: AssemblyVersion("$(VersionNumber)")]" />
</Target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With