Responsibility of each of them:
CSC.exe is the C# compiler which can compile your C# code and produces executable (.exe) files, dynamic-link libraries (.dll), or code modules (.netmodule).
MSBuild is Microsoft Build Engine which can be used to build projects and solutions from Visual Studio. Besides, even if I wrote some .cs files and a custom project file (.xxproj) to structure them, we can use msbuild.exe to build them using a command like msbuild xxx.xxproj
. See this document.
Visual Studio is a software suite that consolidates the basic tools required to write and test software.
Relationship between each of them:
If I only have several .cs files and I want to compile them to output a .exe and what, then csc.exe is enough. Use it in command-line (by cmd.exe or other things
) to compile the code.
If I create a project file (.xxproj) to better control the resources, the .cs files, and other files, I can use msbuild in command-line to build them to output a .exe or what. And one point we should know is msbuild.exe can not only build C# code but also VB.net, C++, F#
... When I use msbuild to build C# code using a command like msbuild xx.csproj
, it will call csc.exe to compile C# code and pass parameters read from the .csproj file to it
.
And though msbuild is the build system in Visual Studio, it doesn't depend on Visual Studio. So you can install a separate Build Tools package for VS2019.
So I think it's clear that msbuild
calls csc.exe
when building C# projects. And Visual Studio uses MSBuild as its build engine
, so it will always call msbuild
when building projects and solutions in Visual Studio
.
And since MSBuild is a separate package since VS2015(not sure about the time), we can also install a free Build Tools package which contains msbuild.exe
to build projects and solutions outside VS IDE.
(From VS2017 and higher, for earlier VS versions like VS2010, VS2012, Visual Studio calls msbuild API to build projects instead of calling the msbuild.exe process)
In addition: You can get a picture here which describes the relationship for earlier VS versions. But I think the situation has changed since in earlier versions, I'm sure VS build call msbuild API instead of msbuild.exe, but for at least VS2017, when building C# project, it's obvious that it calls msbuild.exe as a separate process when you monitor the build process by task manager
.
Hope it helps and if I misunderstand anything in what I wrote above, feel free to contact me to correct it :)
dotnet CLI
andnuget restore
\dotnet restore
? – Aryan