visual-studio - 使用困难模块化 Visual Studio 项目文件
问题描述
我正在尝试模块化 Visual Studio 项目文件,但它不起作用。这适用于带有 .Net 3.5 的 Visual Studio 2008。
如下所示,第一个示例有效,但第二个示例无效。我怎样才能让它工作..?
我是这个话题的新手,可能遗漏了一些东西。我在阅读 3rd-party博客时首先意识到它,然后在文档中也发现了它。我已经用谷歌搜索了更多帮助,但信息太多,我无法找到相关答案。
主项目文件:
...
<!-- main project file -->
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Target Name="AfterBuild">
<Message Text="This is a message from the *.vbproj file."/> ... this works
</Target>
</Project>
...但是如果<Import>
使用相同的<Target>
和<Message>
在导入的文件中,它不起作用。MSBuild 似乎可以正确处理所有内容,但没有任何反应......
主项目文件:
...
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Import Project="$(MSBuildProjectDirectory)\CustomBuildEvents.targets" /> ... new tag
<Target Name="AfterBuild">
<Message Text="This is a message from the *.vbproj file."/> ... this still works
</Target>
</Project>
导入的目标文件:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
<Message Text="Hello from the imported file." Importance ="high"/> ... doesn't work
</Target>
</Project>
以及构建输出,Verbosity
设置为Diagnostic
:
### Halfway through the output, this is the only mention of the imported file. ###
None
CustomBuildEvents.targets ... custom file
My Project\Application.myapp
My Project\Settings.settings
### And then at the end, no mention of the imported file or its message. ###
Done building target "CoreBuild" in project "MsBuildCustomTargetTester.vbproj".
Target "AfterBuild" in file "C:\Visual Studio 2008\Solutions\MsBuildCustomTargetTester\MsBuildCustomTargetTester\MsBuildCustomTargetTester.vbproj":
Task "Message"
Hello from the *.vbproj file. ... message from main file
Done executing task "Message".
Done building target "AfterBuild" in project "MsBuildCustomTargetTester.vbproj".
Target "Build" in file "c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets":
Building target "Build" completely.
No input files were specified.
Done building target "Build" in project "MsBuildCustomTargetTester.vbproj".
Done building project "MsBuildCustomTargetTester.vbproj".
Project Performance Summary:
109 ms C:\Visual Studio 2008\Solutions\MsBuildCustomTargetTester\MsBuildCustomTargetTester\MsBuildCustomTargetTester.vbproj 1 calls
解决方案
问题AfterBuild
在于它只能定义一次。因此,如果您导入它,然后在项目文件中再次定义它,则最后一个定义将获胜并成为唯一的定义。
要解决这个问题,您需要使用更高级的方式来注册事件。鉴于您使用的是 Visual Studio 2008(为什么?!),您需要对自定义目标文件使用更高级的语法:
<Project>
<!--
Redefines the original build order, includes the standard targets and
adds your new custom target to the end of the list.
-->
<PropertyGroup>
<BuildDependsOn>
$(BuildDependsOn);
CustomTarget
</BuildDependsOn>
</PropertyGroup>
<CustomTarget>
<!-- Imported after Build -->
<Message Text="Hello from the imported file." Importance ="high"/>
</CustomTarget>
</Project>
还有其他方法可以做到这一点,在 MsBuild 4 中引入了任何目标上的 BeforeTargets
andAfterTargets
属性,但如果我没记错的话,上面的语法也应该适用于 Visual Studio 2008 附带的 MsBuild 版本。
也可以看看:
推荐阅读
- python - 贝塞尔曲线曲面
- sql - 如何从批处理文件执行 Sql 查询
- odoo - odoo - 解释 @api.multi - 记录集
- javascript - 括号中的构造函数调用时未定义Javascript原型函数
- wordpress - WordPress中的文件路径不是默认值
- c# - 如何在 WPF 中激活 UserControl 的所有父级(即一个选项卡)
- sql - 使用 sql 查询从数据库中计算百分比(SQL Management Studio 2012)?
- ruby-on-rails - 使用 Turbolinks 5 和 Rails 5 在页面之间重新加载资产
- keras - 如何在 LSTM 自动编码器中计算带有零填充的输入的 softmax
- sql - 如何查询属性的未配对值