yper yper - 5 months ago 44
C# Question

How to get csc.exe path?

Is there a way to get path for the latest .NET Framework's csc.exe?

The file usually in: c:\Windows\Microsoft.NET\Framework\vX.X.XXX but the problem is there can be multiple versions installed + there are both 32 and 64 bit versions.

Any solution to this?


One clue to a reasonable answer is to be found here. You can enumerate installed versions of the .NET Framework from the registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP (for versions 1.1 and onwards, I think). Under each key (or profile subkey, in the case of 4.0), you'll find InstallPath which will point to the installation location of the framework. You'll need to enumerate all subkeys under NDP and translate each one into a version number and then find the latest. To detect 32-bit versions running in a 64-bit process on a 64-bit OS, you'll need to look under the equivalent locations under Wow6432Node in the registry.

It's all a bit ugly, but is possibly the only reliable way to do it.