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

查看:89
本文介绍了添加在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天全站免登陆