Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is <Target Name="Build"> not found in any .csproj file?

Just curious - whenever I see xml of .csproj , it starts with DefaultTargets="Build" and hence I assume that <Target Name="Build"> should be present; However, I have never found this default target in any .csproj file.

Does VS inject this target before compilation or does msbuild built it by default. What happens internally?

like image 870
Antony Thomas Avatar asked Nov 09 '12 21:11

Antony Thomas


People also ask

How do I open a .csproj file in Visual Studio 2022?

csproj or . sln extension. Double-click the . csproj file to open it in Visual Studio.

What does Csproj file contains?

What is a CSProj file? Files with CSPROJ extension represent a C# project file that contains the list of files included in a project along with the references to system assemblies.

How do I run MSBuild target?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.


3 Answers

Near the bottom of the file you'll see this; <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> which imports the standard targets, "Build" is one of these. The import generates the "Build" target in a dynamic fashion based on the other data available in the your project file.

like image 102
evanmcdonnal Avatar answered Oct 14 '22 00:10

evanmcdonnal


A csproj typically has this:

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

which according to MSDN also imports Microsoft.Common.targets which is where that target is defined.

like image 31
Mike Zboray Avatar answered Oct 13 '22 22:10

Mike Zboray


There is one or more < Import ...> somewhere in the project file that imports other file(s) that should have that target...

like image 41
Z.D. Avatar answered Oct 14 '22 00:10

Z.D.