如何在 Visual Studio 2017 中使用 BeforeBuild 和 AfterBuild 目标? [英] How can I use BeforeBuild and AfterBuild targets with Visual Studio 2017?

查看:23
本文介绍了如何在 Visual Studio 2017 中使用 BeforeBuild 和 AfterBuild 目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到 csproj 以使用 Visual Studio 2017 和 Microsoft.NET.Sdk 后,我的BeforeBuild"和AfterBuild"目标不再运行.我的文件看起来像这样:

After upgrading to a csproj to use Visual Studio 2017 and Microsoft.NET.Sdk, my "BeforeBuild" and "AfterBuild" targets are no longer running. My file looks like this:

<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>

推荐答案

相关的 MSBuild git 问题 建议不要使用 BeforeBuild/AfterBuild 作为未来的任务名称,而是适当地命名任务并与目标联系起来

The associated MSBuild git issue recommends not using BeforeBuild/AfterBuild as task names going forward, instead name the task appropriately and wiring up against targets

<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 项目文件,但是您在之前/之后触发的目标目前仍然存在争议

This gets you an idiomatic VS 2017 project file, but which targets you trigger before/after is still a matter of some debate at this time

这篇关于如何在 Visual Studio 2017 中使用 BeforeBuild 和 AfterBuild 目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆