从MSBuild中的文件读取单个值 [英] Reading a single value from a file in MSBuild
问题描述
我正在尝试从MSBuild中的文件中读取版本号:
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>
我只需要此文件的第一行.如何将该值与WriteLinesToFile
中的另一个字符串连接?这不起作用:
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)")]" />
我得到一个错误:
错误MSB4012:在此上下文中不能使用表达式"[assembly:AssemblyVersion("@(VersionNumber)")]).不能将项目列表与需要项目列表的其他字符串连接在一起.使用分号分隔多个项目列表.
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.`
推荐答案
我对MSBuild不太熟悉,但是更改了 WriteLinesToFile 似乎可以正常工作:
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>
这篇关于从MSBuild中的文件读取单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!