添加在 Visual Studio 2017 RC 中构建 .NET Core 项目后运行的 msbuild 任务 [英] Add a msbuild task that runs after building a .NET Core project in Visual Studio 2017 RC

查看:7
本文介绍了添加在 Visual Studio 2017 RC 中构建 .NET Core 项目后运行的 msbuild 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 2017 RC 中是否有类似于带有 .NET Core 的 msbuild 中的 AfterBuild 目标?

Is there something like the AfterBuild Target in msbuild with .NET Core in Visual Studio 2017 RC?

我尝试将以下片段添加到 .csproj 文件中,但它在构建过程中没有被执行(与 VS2015 的工作相反).

I tried to add the following snipped to the .csproj file, but it is not excuted during a build (Contrary to VS2015 where it does work).

<Target Name="AfterBuild">
  <Message Importance="High" Text="This is a test" />
</Target>

另一个有趣的发现:我认为 AfterBuild 目标可能已被删除 - 运行 msbuild <project.csproj>/t:AfterBuild 似乎没有调用添加的目标.如果我将目标重命名为测试",则使用 msbuild <project.csproj> 调用它/t:Test 它工作得很好.

Another interesting discovery: As I thought that the AfterBuild target might have been removed - running msbuild <project.csproj> /t:AfterBuild doesn't seem to call the added target. If I rename the target to "Test" an call it with msbuild <project.csproj> /t:Test it works just fine.

此外,Visual Studio 2017 RC 附带的 msbuild 版本(可能还有 .NET Core 构建脚本)是否有任何文档?

Additionally, is there any documentation on the msbuild version (and possibly the .NET Core build scripts) shipping with Visual Studio 2017 RC?

推荐答案

另一种方法是在 Target 上使用 AfterTargets 属性.比如:

An alternative is to use the AfterTargets attribute on the Target. Something like:

<Target Name="TestTarget" AfterTargets="Build">
  <Message Importance="High" Text="This is a test" />
</Target>

我不确定为什么AfterBuild"不再起作用,但 这似乎由 MSBuild 的维护者做出有意识的决定(向 Livven 指出这个 github 问题).AfterBuild"是 Build 目标使用的特殊名称.Microsoft.Common 的当前版本.CurrentVersion.targets 还是有的:

I'm not sure why "AfterBuild" wouldn't work any more, but this appears to be a conscious decision by the maintainers of MSBuild (h/t to Livven on pointing me to this github issue). "AfterBuild" was a special name that was used by the Build target. The current version of Microsoft.Common.CurrentVersion.targets still has it:

  <PropertyGroup>
    <BuildDependsOn>
      BeforeBuild;
      CoreBuild;
      AfterBuild
    </BuildDependsOn>
  </PropertyGroup>
  <Target
      Name="Build"
      Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
      DependsOnTargets="$(BuildDependsOn)"
      Returns="$(TargetPath)" />
  <!--

这篇关于添加在 Visual Studio 2017 RC 中构建 .NET Core 项目后运行的 msbuild 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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