Back in 2013 I wrote about Programming .NET 4.5 without VS2012. The reason was that Microsoft had yanked its free compilers from the free Windows SDK, yet Visual Studio at the time did not offer a reasonable free option.
The first point still holds, the second does not. You can now simply download the free Visual Studio Community Edition, so technically there’s no reason anymore to use the workaround described below. However, perhaps you don’t want to the massive Visual Studio installation on your system just for some .NET command line compilation.
Before we go on, another thing that’s changed is the availability of .NET Core which is also free and cross-platform to boot. However, .NET Core lacks support for WPF, Windows Forms, and other Windows-specific APIs built into the traditional .NET Framework for Windows. This post specifically covers the latter.
This part largely mirrors the content of my earlier post, with updates for current Microsoft products and distribution policy. To recapitulate, the standard .NET Framework runtime installed on every Windows system already contains MSBuild and compilers for C#, Visual Basic, JScript, and MSIL. Only the .NET reference assemblies and some other tools are missing, such as ILDASM and the assembly linker. Those items come with Visual Studio but they also used to be included in the free Windows SDK, and now in a dedicated .NET Framework Developer Pack.
- Add the .NET 4.x directory for your Windows bitness to your
PATH. On my 64-bit system, that’s
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319". On a 32-bit system, simply remove the
64. The path always uses the old .NET 4.0 version number because all later versions, including 4.7.1 at the time of this writing, deploy as in-place upgrades to 4.0. Try running
csc.exeto verify the actual version.
- Download and run the Microsoft .NET Framework 4.7.1 Developer Pack for Windows 7 and later. Unless you want languages other than English that’s all you need to do. Installation is fully automatic and registers the .NET reference assemblies for use by compilers. I expect equivalent Developer Packs will become available for future .NET updates, too.
- Optionally, add the directory with the Developer Pack’s .NET utilities to your
PATH. Currently that’s
"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools", with folder names reflecting Windows 10 and .NET 4.7.1. On a 64-bit system, you should first add the same path followed by
\x64, for those tools that have 64-bit versions. (You might not need the 32-bit directory at all in this case, but I’m not sure about that.)
The last step is only required if you wish to run any of the newly installed utilities, it’s not needed for building .NET applications. And that’s it, now you have a perfectly fine minimal .NET programming environment.
2018-05-05: The .NET Framework 4.7.2 has been released along with the Windows 10 April 2018 Update. I haven’t checked but I assume the above steps still apply, changing “4.7.1” to “4.7.2” as needed. The new download location for the Developer Pack is on this page where you can also find .NET Core and Visual Studio.