How to compile C# without Visual Studio

Yesterday I found myself in a bind, I needed to fix a bug for a client and Visual Studio was having a moment (and still is actually). I’ve been using the Visual Studio Community Edition for a bit now and it’s been working great. However, yesterday it decided to expire my “trial period” and would fail when attempting to renew my license. Awesome.

After hours of uninstalling / reinstalling / hoping / praying, I still hadn’t gotten anywhere and needed to push this hotfix out. Have you ever been in this situation? Just then, I had the brightest of ideas, why not fix the code in notepad, compile it via the command line, and push it out while hoping for the best? Brilliant!

Here’s how you can compile a solution without opening Visual Studio. The first thing you’ll want to do is navigate to the .NET Framework folder that your solution is using. For example,

C:\Windows\Microsoft.NET\Framework\v4.0.30319

Then, run this command to build it!

msbuild "C:\path\to\your\awesome\solution.sln" /t:Rebuild /p:Configuration=Release /p:Platform="Any CPU"

p.s. I don’t recommend “shooting from the hip” in this fashion and throwing untested code out to production.. buuttt, when you’re in a jam.. :)