Generate executable in c # [closed]

1

I was interested in knowing how an executable could be generated from another executable.

Let me explain, let's imagine that I have a form where in some textboxs they are asked, what do I know, an email, subject, message etc ...

But I'm not interested in giving a button, send the message, but generate an executable, and when that application is sent a message, how the hell is an executable compile from another executable?

    
asked by Georgia Fernández 19.10.2018 в 05:31
source

1 answer

6

In runtime you can generate code using the libraries of CodeDom

Compiling C # Code at Runtime

How to programmatically compile code using C # compiler

something like this

string code = @"
    using System;

    namespace First
    {
        public class Program
        {
            public static void Main()
            {
            " +
                "Console.WriteLine(\"Hello, world!\");"
                + @"
            }
        }
    }
";

CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerParameters parameters = new CompilerParameters();

parameters.GenerateInMemory = true;
parameters.GenerateExecutable = true;

CompilerResults results = provider.CompileAssemblyFromSource(parameters, code);

Of course the code is simplified, then you must validate if there are errors in the compilation and you can execute what you compiled, but I think it gives an idea

    
answered by 19.10.2018 / 12:35
source