4

Possible Duplicate:
C# - How to get csc.exe path?

Is there a "proper" way to find the path to the C# compiler on a given system?

E.g. for Java, the "proper" way is to use the HKLM\Software\JavaSoft registry key to go through all the different JDKs and their locations, rather than assuming that everything is in %ProgramFiles%\Java.

Is there a similar method for C#?

Community
  • 1
  • 1
user541686
  • 205,094
  • 128
  • 528
  • 886

2 Answers2

2

You can find a list installed frameworks in: HKLM\Software\Microsoft.NetFramework

And on File system %Windows%\Microsoft.NET\Framework

Remembering only, you can access compiler services through the .net classes themselves.

Adilson de Almeida Jr
  • 2,761
  • 21
  • 37
0

I prefer something less system dependent:

string cscPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(typeof(object).Assembly.Location),"csc.exe");
Interarticle
  • 385
  • 4
  • 9
  • This only works assuming I'm doing this from C#. Which doesn't really work because I'm doing this from JScript. :P – user541686 Sep 01 '11 at 03:32
  • Oh. Then why the C# tag? It's quite confusing. – Interarticle Sep 02 '11 at 02:52
  • Really? Sorry, next time I'll tag questions about the C# compiler with JScript instead. – user541686 Sep 02 '11 at 03:00
  • This gets the path of your running assembly, which isn't necessarily the path where `csc.exe` resides. The compiler is part of the .NET Framework, which is embedded in the Windows directory. If you have installed Roslyn, it may also be in Program Files (x86). – Matt Mar 31 '20 at 09:26