53

I seem to have missed Day 1 of MsBuild 101. I find myself asking "What does it do, what does it replace, and when do I need it?" since I can just hit F5 and compile my application.

What is the bigger picture I'm missing?

makerofthings7
  • 60,103
  • 53
  • 215
  • 448

5 Answers5

69

MSBuild is the build platform that enables all build activity in the Visual Studio world.

A better, more practical example would be to state that

  1. The .csproj files (every C# project) are msbuild files

  2. When you hit F5, you basically (oversimplifying) call msbuild.exe and passing in your .csproj file.

MSBuild empowers all the things that make hitting F5 work. From creating the "debug" or "release" folder, to dropping references into the bin\ directory, to invoking CSC ... and everything in between ... MSBuild "powers" all that.

If all you will ever need from a build is the output that F5 gives you, then you know about all you probably need to know about MSBuild.

In most commercial/practical development scenarios, however, there will come a time where there is a need to customize the build process. The most common approach is automating the build process (using either TeamBuild or some homegrown system). You may also need to

  • create a "packaged" deployment
  • link to another library outside of your project that is also actively being developed
  • publish your build to an FTP and send an email to a customer notifying them of its availability.

The use of a unified and extensible build platform (ie MSBuild) is what makes all these these possible, while still being part of the build process ... keeping the "build" part of the development pipeline simple and contained.

malat
  • 12,152
  • 13
  • 89
  • 158
Taylor Bird
  • 7,767
  • 1
  • 25
  • 31
  • This is also how most CI/CD platforms build .NET Framework projects that are made in Visual Studio. – FilBot3 Sep 09 '20 at 17:39
2

It's useful when you want do automated builds, and have to implement a build process

The F5 Key Is Not a Build Process and links therein (e.g this) is a good read in that regard.

Also, your Visual Studio project files are msbuild files. If you want to do more advanced stuff when you build (e.g. run a javascript minifier, have more control over autogenerated version identifiers, post processing of files etc.) , you'll have to dig into msbuild.

nos
  • 223,662
  • 58
  • 417
  • 506
1

msbuild is used when you want to build your project from the command line. Whenever you see a continuous integration product that will automatically build your project, it will call msbuild to perform the actual build step.

David
  • 34,223
  • 3
  • 62
  • 80
  • 1
    MSbuild does use csc, but it can also do other things. It's Microsoft's NANT. – nportelli Aug 30 '10 at 18:28
  • There's more to it than just compiling it - what if you want to run tests, send out test results, archive build artifacts, etc. – dsolimano Aug 30 '10 at 18:28
  • With "csc" you have to construct the very long list of command line parameters needed to compile all of your files. With "msbuild", you pass it your project file or your solution file. Then it will follow all of the build options that you have already defined through Visual Studio. – David Aug 30 '10 at 18:30
1

I know this is pretty stale, but here's my take on MSBuild.

It's a scriptable build tool really similar to ANT. They both use XML for configuration, so you'll be able to figure it out fairly quickly. Both have the concept of "Targets" for instance, lots more similarities in thinking, if you know ANT the switch shouldn't be tough.

MSBuild files generated from Visual Studio is really like the generated ANT scripts you get from Eclipse that build your projects, remember your includes and define your dependencies. You can modify them directly for fun and profit.

I like MSBuild, it fixes some of the stuff I find annoying about ANT.

Dan Devine
  • 859
  • 1
  • 8
  • 19
  • I have not worked with ANT either. However, I am pretty familiar with make. So can I consider msbuild and ANTs are similar to make utility in Linux?? – Darshan L Aug 02 '20 at 14:01
0

I think that build servers should have the option to press F5 key in a simpler way than via windows API.

Petr Kozelek
  • 1,126
  • 8
  • 14