从MSBuild中的文件读取单个值 [英] Reading a single value from a file in MSBuild

查看:56
本文介绍了从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(&quot;@(VersionNumber)&quot;)]" />

我得到一个错误:

错误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不太熟悉,但是更改了

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(&quot;$(VersionNumber)&quot;)]" />
</Target>

这篇关于从MSBuild中的文件读取单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆