Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 572
Fionn Avatar asked Jan 04 '17 21:01

Fionn


People also ask

How do I run MSBuild in Visual Studio?

With Visual Studio 2019 and later, it's installed under the Visual Studio installation folder. For a typical default installation on Windows 10, MSBuild.exe is under the installation folder in MSBuild\Current\Bin. In the installer, make sure MSBuild tools for the workloads you use are selected, and choose Install.

Which of the following interface is used to implement a custom task in MSBuild?

An MSBuild custom task is a class that implements the ITask interface.

What is MSBuild EXE used for?

The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software. Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio.

How do I get MSBuild?

You can also get the MSBuild executable as a Nuget package https://www.nuget.org/packages/Microsoft.Build.Runtime/.


1 Answers

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)" />   <!-- 
like image 185
Mike Zboray Avatar answered Oct 08 '22 02:10

Mike Zboray