Add a msbuild task that runs after building a .NET Core project in Visual Studio 2017 RC

亡梦爱人 提交于 2019-12-18 14:02:57

问题


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

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>

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.


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


回答1:


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>

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)" />
  <!--


来源:https://stackoverflow.com/questions/41473503/add-a-msbuild-task-that-runs-after-building-a-net-core-project-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!