如何转储从 MSBuild 导入的属性表列表
我正在构建属性表的层次结构(许多属性表是根据平台和配置有条件包含的),并且我正在尝试编写一组目标来帮助诊断可能潜入的任何错误。
我想要的是属性列表已包含的表。
示例:
<ImportGroup Condition="$(Configuration.Contains('Debug'))">
<Import Project="ps.cpp.config.debug.props"/>
</ImportGroup>
<ImportGroup Condition="$(Configuration.Contains('Release'))">
<Import Project="ps.cpp.config.release.props"/>
</ImportGroup>
<ImportGroup Condition="'$(Platform)' == 'x64'">
<Import Project="ps.cpp.plat.x64.props"/>
</ImportGroup>
<ImportGroup Condition="'$(Platform)' == 'Win32'">
<Import Project="ps.cpp.plat.win32.props"/>
</ImportGroup>
像这样的目标:
<Target Name="DumpPropertySheets">
<!-- This doesn't work! -->
<!-- <Message Text="%(Import.Project)"/> -->
</Target>
使用 msbuild test.vcxproj /t:DumpPropertySheets /p:Platform=x64 /p:Configuration:Debug
构建时,应该会产生这样的控制台输出
DumpPropertySheets:
ps.cpp.config.debug.props
ps.cpp.plat.x64.props
I am constructing a hierarchy of property sheets (many that are conditionally included according to Platform and Configuration) and I am attempting to write a set of targets that can help diagnose any errors that may sneak in.
What I would like is a list of property sheets that have been included.
Example:
<ImportGroup Condition="$(Configuration.Contains('Debug'))">
<Import Project="ps.cpp.config.debug.props"/>
</ImportGroup>
<ImportGroup Condition="$(Configuration.Contains('Release'))">
<Import Project="ps.cpp.config.release.props"/>
</ImportGroup>
<ImportGroup Condition="'$(Platform)' == 'x64'">
<Import Project="ps.cpp.plat.x64.props"/>
</ImportGroup>
<ImportGroup Condition="'$(Platform)' == 'Win32'">
<Import Project="ps.cpp.plat.win32.props"/>
</ImportGroup>
And a target like this:
<Target Name="DumpPropertySheets">
<!-- This doesn't work! -->
<!-- <Message Text="%(Import.Project)"/> -->
</Target>
Which should result in console output like this when built with msbuild test.vcxproj /t:DumpPropertySheets /p:Platform=x64 /p:Configuration:Debug
DumpPropertySheets:
ps.cpp.config.debug.props
ps.cpp.plat.x64.props
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有一种明显的方法可以完成您想要做的事情。导入经过预处理,将所有内容聚合到一个文件中,它们不是像项目数组或属性这样可以稍后引用的数据类型。
语法 %(Import.Project) 不起作用,因为该语法仅对项目数组有效,并且您尝试在 Import 关键字上使用它,该关键字不是填充的项目数组。
另请注意,您对导入周围的 ImportGroup 元素的使用是可选的(并且可能有点冗长)。 MSBuild 文件中的以下两个构造是等效的...
...并且(为了清楚起见,换行)...
如果您尝试诊断属性表导入错误,请不要忘记 /pp 命令行开关,这将转储完整的预处理文件。您还可以(至少对于您自己的文件)为每个导入提供一个唯一的条目到项目数组中,例如
然后在
ps.cpp.config.debug.props
内,然后在您的构建中稍后您可以得到在某种程度上,你似乎正在寻找什么,
There is not an obvious way to do what you are trying to do. Imports are pre-processed to aggregate all of the content into a single file, they are not a datatype like item arrays or properties that can be referenced later on.
The syntax %(Import.Project) doesn't work because that syntax is valid only for item arrays, and you are trying to use it on the Import keyword, which is not a populated item array.
Also note that your use of the ImportGroup elements surrounding the imports is optional (and probably a bit verbose). The following two constructs in an MSBuild file are equivalent...
...and (line-wrapped for clarity)...
If you are trying to diagnose property sheet import errors, don't forget about the /pp command-line switch, which will dump the complete preprocessed file. You also could (for your own files at least) give each import a unique entry into an item array, e.g.
then inside
ps.cpp.config.debug.props
,then later in your build you could get what you appear to be looking for, to some degree, with,