我希望仅在解决方案中的所有 Visual Studio 项目都已构建后才执行此目标
根据文档MSBuild Extending The Solution Buildafter.<SolutionName>.sln.targets
,您可以在与您的解决方案相同的文件夹中创建一个 MSBuild 项目文件。
作为测试,我将其添加到我的 After.Solution.sln.targets 文件中(使用香蕉而不是 SomeApplication.exe),并将此文件设置在与我的解决方案文件相同的文件夹中.sln
:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PostBuildScript" AfterTargets="Build" Condition="'$(Configuration)' == 'Release'">
<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>
</Project>
然后我用dotnet build
命令构建它:
dotnet build "xxxx\TestSolutionTarget.sln" --configuration Release --verbosity n

此目标在解决方案中的所有Visual Studio 项目都已构建后执行。
或者,您也可以创建单独的空项目,引用所有项目的子集并将此目标添加到空项目中。
希望这可以帮助。