-1

I have a windows form application and i search to create an .exe of another WinForm application with the first application. Because i would like in my Application1 select files or folders with parameter of deployment (folder of destination) and with a button create an another form application with the attached files.

Application2 will deploy the files into the destination folder set.

I looked "Csharpcode provider" to compile the other form. I could write the source code into a file and compile with this one but how to do for attached file ?

Do you have an another solution or ideas ?

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80
Neyoh
  • 623
  • 1
  • 11
  • 33
  • 2
    Do you really need to compile on the fly? Or just deploy a previously compiled exe? – Alejandro May 07 '15 at 09:02
  • Compile on the fly because i need to create an exe which will deploy files. – Neyoh May 07 '15 at 09:10
  • Why not just run the instructions in an interpreter? – Luaan May 07 '15 at 09:16
  • I don't totally understand your question, what's an interpreter for you ? The exe created must be a WinForm to display informations, progressbar. – Neyoh May 07 '15 at 09:23
  • But you can have the exe precompiled and only extract it during execution, not compile it from scratch. Dynamic compilation is useful only when you know its source will also dynamically change. "Deploy" to me seems pretty much like copying an already compiled file. – Alejandro May 07 '15 at 09:30
  • But if i have exe precompiled, can i have an winform during execution and copy the files ? The creation and execution of the exe are not in the same computer. – Neyoh May 07 '15 at 09:43

3 Answers3

1

Look here: Compile assembly in runtime and save dll in a folder

In CompilerParameters you cant set GenerateExecutable to true.

Community
  • 1
  • 1
Thomas
  • 113
  • 1
  • 11
1

I will reply not to your exact question but instead to how to solve the underlying problem. To me it seems you're building some sort of "installer" that should simply unpack some other program, right?

On the fly compilation in this case is a bad idea for a number of reasons. It can be much slower and needs to carry the whole code around up to the user machine and would rely on the user to have a compatible environment. PDBs would also be useless since they would be generated at the user site. Instead you should always compiled in your computers and then just deliver those binaries, which is also much simpler to code.

One possible approach would be to include the target exe within the installer as an embedded resource. Add the .exe to be deployed from its build folder into the installer project and switch it to be embedded resource which will include the whole file inside the other. Then at runtime you just read from it and save somewhere else.

For that you can use the GetManifestResourceStream method (Look at its documentation for the details), together with normal file writing routines to extract it at the user site. This question also deals with this particular topic. With this technique the installer will just read the file within itself and save it to a location of your choice, much like extracting a compressed file like most installers do, but using the precompiled code instead.

Community
  • 1
  • 1
Alejandro
  • 7,290
  • 4
  • 34
  • 59
  • Yes i would like to build an installer that unpack files. To copy files into folder defined, or sql files to execute into DB. – Neyoh May 07 '15 at 10:20
0

You might call msbuild.exe from your application with related parameters.

MSBuild Usage