要执行解决方案范围的 Before 和 After 目标,您将在与你的解决方案。
要对所有解决方案执行此操作,您需要将目标文件之后的自定义解决方案级别放到路径 $(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\SolutionFile\ImportBefore\ 或 $(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\SolutionFile \导入后。构建这些解决方案后,它将导入这些文件夹中的所有项目文件(如果存在)。
要验证上述内容,请打开命令提示符并导航到包含您的解决方案文件的文件夹。键入“SET MSBuildEmitSolution=1”。然后运行 msbuild.exe 。您将看到 msbuild 已将元数据项目文件 .sln.metaproj 和 .sln.metaproj.tmp 保存在与您的解决方案相同的路径中。
查看文件顶部和底部的 声明,您会注意到条件导入,允许您在目标之前和之后声明特定于解决方案,或在目标之前和之后声明特定于全局解决方案。
编辑:
这似乎只适用于命令行或团队构建,但不适用于 Visual Studio。
我将此添加到我的 After.Solution.sln.targets 文件中:
<Target Name="Banana" AfterTargets="Build">
<Message Text="*** BEGIN BANANA ***" Importance="high" />
<Message Text=" _ " Importance="high" />
<Message Text="//\ " Importance="high" />
<Message Text="V \ " Importance="high" />
<Message Text=" \ \_ " Importance="high" />
<Message Text=" \,'.`-. " Importance="high" />
<Message Text=" |\ `. `. " Importance="high" />
<Message Text=" ( \ `. `-. _,.-:\" Importance="high" />
<Message Text=" \ \ `. `-._ __..--' ,-';/" Importance="high" />
<Message Text=" \ `. `-. `-..___..---' _.--' ,'/ " Importance="high" />
<Message Text=" `. `. `-._ __..--' ,' / " Importance="high" />
<Message Text=" `. `-_ ``--..'' _.-' ,' " Importance="high" />
<Message Text=" `-_ `-.___ __,--' ,' " Importance="high" />
<Message Text=" `-.__ `----''' __.-' " Importance="high" />
<Message Text=" `--..____..--' " Importance="high" />
<Message Text="*** END BANANA ***" Importance="high" />
</Target>
从命令行:香蕉!
在 TFS 构建中:香蕉!
Visual Studio:没有香蕉 :(