MSBuild:使用 ReadLinesFromFile 评估保留属性

发布于 2024-08-08 05:39:28 字数 508 浏览 2 评论 0原文

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

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

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

在我的目标中,我使用 ReadLinesFromFile 来获取这些文件的内容。 到目前为止,一切都很好!

问题是,这样做时不会评估“$(Configuration)、$(MSBuildProjectDirectory)”等保留属性,它们只是作为常规文本进行处理。

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

提前致谢!

问候, 罗伯特哦。

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.

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.

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

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?

Thanks in advance!

Regards,
robert.oh.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三月梨花 2024-08-15 05:39:28

与其自己阅读这些行并解析所有内容,不如创建一个包含

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

文件中信息的单独文件(例如,命名为“local.build.config”),然后在实际项目中导入该文件在构建的顶部添加这样一行:

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

通过让 MSBuild 引擎做它最擅长的事情来防止重新发明轮子。

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')"/>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文