MSBuild:使用ReadLinesFromFile评估保留的属性 [英] MSBuild: Evaluating reserved properties with ReadLinesFromFile

查看:112
本文介绍了MSBuild:使用ReadLinesFromFile评估保留的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MSBuild定制Visual Studio,WiX,SandCastle等项目的构建过程. 为了使它尽可能通用,我想使用定义一些特定于项目"设置的文本文件,例如应从何处加载文件,要运行哪些自定义可执行文件等等.

I'm using MSBuild to customize the build process of Visual Studio, WiX, SandCastle, ... projects. To keep it as generic as possible I'd like to use text files defining some 'project specific' settings, like where the files should be loaded from, which custom executables to run and so on.

文本文件可能如下所示: $(MSBuildProjectDirectory).... \ Projects \ Project1 \ bin \ Release obj \ $(Configuration)\ Project1.Files.wxi -in * .dll -id TEST

A text file could look like this: $(MSBuildProjectDirectory)....\Projects\Project1\bin\Release obj\$(Configuration)\Project1.Files.wxi -in *.dll -id TEST

每一行代表一个命令或文件.

Each line represents one command or file.

在目标内部,我正在使用ReadLinesFromFile来获取这些文件的内容. 到目前为止一切顺利!

Inside my targets I'm using ReadLinesFromFile to get the contents of these files. So far so good!

问题在于,诸如"$(Configuration),$(MSBuildProjectDirectory)"之类的保留属性在执行此操作时不会进行评估,它们只是作为常规文本处理.

The problem is that the reserved properties like '$(Configuration), $(MSBuildProjectDirectory)' are not evaluated when doing so, they are just processed as regular text.

关于如何在不创建自定义任务的情况下评估这些$占位符的想法?

Any ideas on how I could evaluate these $-placeholders without creating a custom task?

提前谢谢!

关于, robert.oh.

Regards, robert.oh.

推荐答案

为什么不创建一行包含以下内容的单独文件(例如,命名为"local.build.config"),而不是自己读取行并解析所有内容?

Rather than reading the lines and parsing everything yourself, why not create a separate file (named, for example, "local.build.config") that has the

<PropertyGroup>
    <someproperty>$(MSBuildProjectDirectory)..\Projects\Project1\bin\Release</someproperty>
</PropertyGroup>

文件中的信息,然后在您的实际项目中,在构建顶部使用如下行导入文件:

information in the file, and then in your actual project do an import of the file with a line such as this at the top of your build:

<Import Project="local.build.config" Condition="Exists('local.build.config')"/>

通过让MSBuild引擎尽其所能来防止重塑车轮.

Prevents reinventing the wheel by letting the MSBuild engine do what it does best.

这篇关于MSBuild:使用ReadLinesFromFile评估保留的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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