.net - 如何在 Visual Studio 2017 中使用 BeforeBuild 和 AfterBuild 目标?

标签 .net msbuild .net-core visual-studio-2017 csproj

升级到 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/

相关文章:

c# - 确定某个 URL 是否位于某个目录中的正确方法是什么?

c# - UnhandledExceptionEventArgs 的全局异常处理程序不起作用

msbuild - 未为项目设置 OutputPath 属性

msbuild - 输出标签 - TaskParameter 和 PropertyName,ItemName - 这两个包括什么?

.net - VS 2017 & Nuget : How to find Analyzer packages with specific rules?

c# - 获得两个日期之间的工作日

msbuild - SonarQube - 无法在对象 'dbo.projects' 中插入重复的键行

node.js - Browsersync 不重新加载浏览器或注入(inject) css

asp.net-core - 如何使用 'AsNoTracking' 方法结合显式加载相关实体在 EF Core 中加载实体

.net - .NET : The specified data could not be decrypted only for a specific URL 中非常奇怪的 SSL 错误