3

Is there a way to create and build an .exe from C#? (Editor's Note: Basically a .NET app that can create and compile other .NET apps - see accepted answer)

I am NOT talking about getting the .exe of my project (which is the only exe building I could find on google), I am talking about generating .exe files from within my program.

How would I create a runnable .exe file from C#? I have no idea how and on google I only find questions on where to find the .exe of the Project, while I want the project to build .exe's itself.

12
  • That is how a .exe is made, by programming, the compiler is a VS build-in, so it created the file for you. Commented Dec 6, 2013 at 15:41
  • compiling an exe is a very difficult process to do on your own. That's why we have Visual Studio to do it for us. Commented Dec 6, 2013 at 15:41
  • 1
    You want to write a compiler ? Commented Dec 6, 2013 at 15:41
  • 2
    "Programmatically" is the word you want. You're asking how to generate an .exe programmatically. And poo on whoever downvoted you, it's a reasonable question. Commented Dec 6, 2013 at 15:43
  • 1
    @CodeCaster It appears to me that he made a reasonable effort, but didn't know how to express what he was looking for. He just sounded like somebody who'd been wading through an awful lot of irrelevant google hits. You can ding people for not making an effort (and boy, do I ever), but not for making the wrong effort because they missed the obvious. We all miss the obvious sometimes. Commented Dec 6, 2013 at 16:00

1 Answer 1

7

The simplest way to do it without using external compilers is called CodeDOM, the relevant class you would use is called CSharpCodeProvider. There there are many tutorials on the internet (including one in the first link I gave) that will show you how to use it, the topic is too broad to explain in depth here.

Sign up to request clarification or add additional context in comments.

2 Comments

OP says "I am talking about generating .exe files within my program". Using CodeDOM is a way to to that, not the way. :)
@CodeCaster changed the wording a bit. I agree with you there are other options, for example you could just call out to csc.exe and do it with that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.