Reputation: 3143
I have designed my very own language that I, in the end, translate to C# code. Now I want to compile this C# code using the C# compiler through my Windows Forms Application.
Where is the actual compiler file located and how do I compile my code (currently placed in a string)??
Upvotes: 3
Views: 4054
Reputation: 46728
c:\windows\Microsoft.NET\Framework\v3.5\
contains the C# compiler csc.exe
.
So, you could do something like the following:
const string outputfile = "abc.exe";
const string inputFile = "xyz.cs"
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "c:\\windows\\Microsoft.NET\\Framework\v3.5\\csc.exe";
startInfo.Arguments = "/out:" + outputFile + " " + inputFile;
Process.Start(startInfo);
Upvotes: 0
Reputation: 1062780
It sounds like you are looking for the CSharpCodeProvider
. http://support.microsoft.com/kb/304655, or MSDN have examples.
Upvotes: 5
Reputation: 13303
You need to have a look at the following 2 sites:
1 - Command-line Building With csc.exe
http://msdn.microsoft.com/en-us/library/78f4aasd.aspx
and
2 - Determining Which Version of the .NET Framework Is Installed
http://msdn.microsoft.com/en-us/library/y549e41e.aspx
You will need to identify which version of the .NET Framework compiler you will use, from the second link you can see:
"You can install and run multiple versions of the .NET Framework on a computer. You can install the versions in any order. To see which versions are installed, view the %WINDIR%\Microsoft.NET\Framework directory. (You should also view the Framework64 directory on a 64-bit computer, which can have 32 or 64-bit versions installed.) Each version of the .NET Framework has a directory, and the first two digits of the directory name identify the .NET Framework version; for example: v1.1.4322 for the .NET Framework 1.1, v2.0.50727 for the .NET Framework 2.0, v3.5 for the .NET Framework 3.5, and so on."
Upvotes: 0
Reputation: 294287
Have you considered using Emit instead?
The csc.exe compiler is part of the .Net:
The csc.exe executable is usually located in the Microsoft.NET\Framework\ folder under the system directory. Its location may vary depending on the exact configuration on any individual computer. Multiple versions of this executable will be present on the computer if more than one version of the .NET Framework is installed on the computer. For more information about such installations, see Determining Which Version of the .NET Framework Is Installed.
Upvotes: -1
Reputation: 19598
You can use C# CodeDom for this purpose. This link may help you
http://www.codeproject.com/Articles/3445/Runtime-Compilation-A-NET-eval-statement
Upvotes: 3