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.
我有一个Windows窗体应用程序,我搜索使用第一个应用程序创建另一个WinForm应用程序的.exe。因为我想在我的Application1中选择具有部署参数(目标文件夹)的文件或文件夹,并使用按钮创建另一个带有附加文件的表单应用程序。
Application2 will deploy the files into the destination folder set.
Application2将文件部署到目标文件夹集中。
I looked "Csharpcode provider" to compile the other form. I could writte the source code into a file and compile with this one but how to do for attached file ?
我看了“Csharpcode provider”来编译另一个表单。我可以将源代码写入文件并使用这个编译,但如何为附加文件做?
Do you have an another solution or ideas ?
你有其他解决方案或想法吗?
3 个解决方案
#1
Look here: Compile assembly in runtime and save dll in a folder
请看这里:在运行时编译程序集并将dll保存在文件夹中
In CompilerParameters you cant set GenerateExecutable to true.
在CompilerParameters中,您无法将GenerateExecutable设置为true。
#2
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.
出于多种原因,在这种情况下的动态编译是一个坏主意。它可能要慢得多,并且需要将整个代码传送到用户机器,并且依赖于用户具有兼容的环境。 PDB也将无用,因为它们将在用户站点生成。相反,您应该始终在您的计算机中编译,然后只提供这些二进制文件,这也更容易编码。
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.
一种可能的方法是将安装程序中的目标exe作为嵌入式资源包括在内。将要从其构建文件夹部署的.exe添加到安装程序项目中,并将其切换为嵌入式资源,其中将整个文件包含在另一个内部。然后在运行时,您只需从中读取并保存到其他位置。
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.
为此,您可以使用GetManifestResourceStream方法(查看其文档以获取详细信息)以及常规文件写入例程以在用户站点提取它。这个问题也涉及这一特定主题。使用这种技术,安装程序将只读取其自身内的文件并将其保存到您选择的位置,就像提取大多数安装程序所做的压缩文件一样,但使用预编译代码。
#3
You might call msbuild.exe from your application with related parameters.
您可以使用相关参数从应用程序中调用msbuild.exe。
#1
Look here: Compile assembly in runtime and save dll in a folder
请看这里:在运行时编译程序集并将dll保存在文件夹中
In CompilerParameters you cant set GenerateExecutable to true.
在CompilerParameters中,您无法将GenerateExecutable设置为true。
#2
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.
出于多种原因,在这种情况下的动态编译是一个坏主意。它可能要慢得多,并且需要将整个代码传送到用户机器,并且依赖于用户具有兼容的环境。 PDB也将无用,因为它们将在用户站点生成。相反,您应该始终在您的计算机中编译,然后只提供这些二进制文件,这也更容易编码。
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.
一种可能的方法是将安装程序中的目标exe作为嵌入式资源包括在内。将要从其构建文件夹部署的.exe添加到安装程序项目中,并将其切换为嵌入式资源,其中将整个文件包含在另一个内部。然后在运行时,您只需从中读取并保存到其他位置。
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.
为此,您可以使用GetManifestResourceStream方法(查看其文档以获取详细信息)以及常规文件写入例程以在用户站点提取它。这个问题也涉及这一特定主题。使用这种技术,安装程序将只读取其自身内的文件并将其保存到您选择的位置,就像提取大多数安装程序所做的压缩文件一样,但使用预编译代码。
#3
You might call msbuild.exe from your application with related parameters.
您可以使用相关参数从应用程序中调用msbuild.exe。