0

This answer shows how to use CSharpCodeProvider class to compile a C# code snippet during runtime. Since that's a rather specific task I'm not sure that every system with .NET Framework installed will have this capability - perhaps something extra has to be installed.

Is CSharpCodeProvider with its C# code compilation capability available on any system with .NET Framework installed?

Community
  • 1
  • 1
sharptooth
  • 167,383
  • 100
  • 513
  • 979

6 Answers6

2

According to the MSDN Documentation for the CSharpeCodeProvider Class it is available in all of the frameworks

Provides access to instances of the C# code generator and code compiler.

.NET Framework
Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile
Supported in: 4, 3.5 SP1

Peter
  • 27,590
  • 8
  • 64
  • 84
Mark Hall
  • 53,938
  • 9
  • 94
  • 111
2

All previous answers are correct, but I've made a test on a VM without .NET SDK/Visual Studio Installed. It is a plain 2003 server with .NET 4 Client Profile + .NET 4 Extended Framework.

And result is that in this setup CSharpCodeProvider works just fine!

If you want to protect yourself even more, you can check for specific code provider availability with this call:

   CodeDomProvider.IsDefinedLanguage("CSharp")

And documentation for this method says:

The Element in the machine configuration file (Machine.config) contains the language provider and compiler configuration settings for each CodeDomProvider implementation on the computer. The IsDefinedLanguage method searches the provider configuration elements for the specified language name.

Therefore it is possible to run your program on computer where CodeProvider WILL NOT work (may be some paranoid system administrator wanted to disable dynamic code compilation (although it is meaningless because using CodeDomProvider requires full trust anyway)).

vlad2135
  • 1,556
  • 12
  • 14
1

From CSharpCodeProvider documentation:

Version Information .NET Framework Supported in:

4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile Supported in:

4, 3.5 SP1

Community
  • 1
  • 1
nothrow
  • 15,882
  • 9
  • 57
  • 104
1

AFAIK, CSharpCodeProvider is just a wrapper for csc.exe, and csc.exe, in turn, is available on every desktop version of .NET (e.g., it isn't available on Silverlight).

Dennis
  • 37,026
  • 10
  • 82
  • 150
0

http://msdn.microsoft.com/en-us/library/microsoft.csharp.csharpcodeprovider%28v=vs.71%29.aspx

first hit on Google. Click "Other versions"

It gives a list of versions where this class (and therefore this feature) was available.

It seems this class has been available from version 1.1, I'd say that's probably every version as even the Object class goes back to that version.

MrFox
  • 4,852
  • 7
  • 45
  • 81
0

In addition to the other answers, it would appear that the language specification is actually tied in to this assembly, so I believe the answer would be "yes".

See: dynamic (C# Reference) (answer based on https://stackoverflow.com/a/2460934/211627)

Community
  • 1
  • 1
JDB
  • 25,172
  • 5
  • 72
  • 123