日期:2014-05-18 浏览次数:21077 次
//源代码字符串(最好从文件中读取)
string source = "using System;" +
                "using System.Windows.Forms;" +
                "namespace App2" +
                "{" +
                "    public class MainForm : Form" +
                "    {" +
                "          static void Main(string[] args)" +
                "          {" +
                "               " +
                "          }" +
                "    }" +
                "}";
//初始化C#编译器
Microsoft.CSharp.CSharpCodeProvider CScodeProvider = new Microsoft.CSharp.CSharpCodeProvider();
System.CodeDom.Compiler.ICodeCompiler icodeCompiler = CScodeProvider.CreateCompiler();
//设置C#编译器编译参数
System.CodeDom.Compiler.CompilerParameters compilerParameters = new System.CodeDom.Compiler.CompilerParameters();
compilerParameters.GenerateInMemory = false;  //生成文件
compilerParameters.GenerateExecutable = true;  //生成可执行文件
compilerParameters.ReferencedAssemblies.Add("System.dll");  //添加程序集引用
compilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
compilerParameters.ReferencedAssemblies.Add("System.Drawing.dll");
compilerParameters.OutputAssembly = Application.StartupPath + "\\2.exe";  //指定输出文件
//开始使用这个参数,对脚本代码进行编译
System.CodeDom.Compiler.CompilerResults compilerResults = icodeCompiler.CompileAssemblyFromSource(compilerParameters, source);
//如果编译出错,那么出错信息就在compilerResults变量内
------解决方案--------------------
1.exe的功能输出"Hello 1_exe"  
2.exe的功能是输出:"ello 2_exe"
在调用1.exe时要调用2.exe,楼主是不是这个意思、
我的源代码如下:
  1.exe的  
using System;