What is the difference between using MSBuild and the C# compiler from a command prompt? I want to manually build my solutions/projects without using Visual Studio and I want to learn how to use the command line tools.
4 Answers
By C# compiler do you mean csc.exe
?
If that is what you mean, then csc
and MSBuild
are completely different applications.
MSBuild
uses a solution and project files to build the files in your project. MSBuild
uses csc.exe
as its actual compiler but knows where to find assemblies, references etc based on your solution and project files (these files are actually xml files).
When using csc.exe
you must manually provide paths to your files, references and so on, thus making your compilation much more difficult.
MSDN MSBuild: http://msdn.microsoft.com/en-us/library/dd393574.aspx
MSDN CSC : http://msdn.microsoft.com/en-us/library/78f4aasd.aspx
-
When you are building without the aid of Visual Studio, I would not say using csc is more difficult than MSBuild. Using it forces you to understand on a deeper level what you are instructing the compiler to do. This can make it easier to resolve dependency issues. It also makes it quite easy to automatically compile all the .cs files recursively in your source code directory, removing the need to edit an MSBuild file every time you want to add another file to the project. That would also force you not to have .cs files that you are not really using, which is bad practice anyway. – still_dreaming_1 Feb 09 '15 at 18:29
-
2Seems like reading an MSBuild log file could develop that same level of understanding. – Christopher Painter Oct 07 '17 at 21:26
-
How do i run my application after running msbuild? cant find an answer. – YTG Nov 02 '22 at 12:34
MSBuild
in fact uses csc.exe
, so you can use both in command line. MSBuild
is a bit easier to use.

- 5,105
- 3
- 23
- 21
In C#
your code first compile to IL
code and then JIT
compiler compile your code to CPU Instructions .So all compiler should compile your code to IL
.
So what is msBuild:
The Microsoft Build Engine (MSBuild) is the new build platform for Microsoft and Visual Studio. MSBuild is completely transparent with regards to how it processes and builds software, enabling developers to orchestrate and build products in build lab environments where Visual Studio is not installed
See:
Visual Studio (sln)
If your solution is small and you are not required to do fancy things you can use Visual Studio (sln) build runner. It does exactly the same thing as when you do Project->Build (from VS menu). This option is very easy to configure, a few clicks and your CI server compiles your solution.
MSBuild
If you need to do more advanced scenarios, apart from simple compilation, like apply different config files, insert transformed values into config file, deploy binaries etc, you would select MSBuild option. You will know when you need to use this, simply because sln builder will not be capable of doing stuff. This option requires some knowledge of build scripting language, which is a task-based and xml-like.

- 1
- 1
If you're from Linux world(like me), you can try to understand it in this way: MSBuild
is like Make
, which a build system (although MSBuild is a more modern one, but the core functionality is the same). And csc.exe
is like gcc
is compiler.
For a hello world tiny project, just use compiler directly is acceptable. But if you're working on a very large project consists of hundreds or thousands of source file, you will need a build system to control the process.

- 2,418
- 8
- 35
- 62