升级到 csproj 以使用 Visual Studio 2017 和 Microsoft.NET.Sdk 后,我的“BeforeBuild”和“AfterBuild”目标不再运行。我的文件看起来像这样:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
<!-- my targets that don't run -->
<Target Name="BeforeBuild">
<Message Text="Should run before build" Importance="High" />
</Target>
<Target Name="AfterBuild">
<Message Text="Should run after build" Importance="High" />
</Target>
</Project>
最佳答案
associated MSBuild git issue推荐 不是 使用 BeforeBuild/AfterBuild 作为 future 的任务名称,而不是适本地命名任务并连接目标
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
<!-- Instead of BeforeBuild target -->
<Target Name="MyCustomTask" BeforeTargets="CoreBuild" >
<Message Text="Should run before build" Importance="High" />
</Target>
<!-- Replaces AfterBuild target -->
<Target Name="AnotherCustomTarget" AfterTargets="CoreCompile">
<Message Text="Should run after build" Importance="High" />
</Target>
</Project>
这将为您提供一个惯用的 VS 2017 项目文件,但是您在之前/之后触发的目标目前仍然存在一些争议
关于.net - 如何在 Visual Studio 2017 中使用 BeforeBuild 和 AfterBuild 目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43921992/