I need to create a program that creates another program but not a compiler though.
For example,
I write a program that accepts a string input from the user. Let's say user enter "Pluto". This program should then create a separate .exe that says "Hello Pluto" when executed.
How can I do this? If you could give example in C# and Windows Forms, it's better.
Thanks.
Basically that is a compiler - just for a particularly simple language.
If you can express the final program in C#, the easiest solution is probably to use CSharpCodeProvider. That's what I do for Snippy, a little tool to help run code snippets easily for C# in Depth. The source code to Snippy is on the C# in Depth web site and can give you an idea of what you might do - basically you'd just want it to write the executable to a file instead of building it in memory.
Alternatively, look at the MSDN docs which have an example generating an executable.
The classes you are looking for are in the Microsoft.CSharp
namespace
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;
CompilerResults results = icc.CompileAssemblyFromSource(parameters,SourceString);
(from microsoft support found by using google - taking less than 20 sec)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With