Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在运行时创建exe maker_C#_Vb.net - Fatal编程技术网

C# 如何在运行时创建exe maker

C# 如何在运行时创建exe maker,c#,vb.net,C#,Vb.net,我有这段代码,但它创建了一个dll文件: private void btnCompile_Click(object sender, System.EventArgs e) { CSharpCodeProvider csp = new CSharpCodeProvider(); ICodeCompiler cc = csp.CreateCompiler(); CompilerParameters cp = new CompilerParame

我有这段代码,但它创建了一个dll文件:

private void btnCompile_Click(object sender, System.EventArgs e)
    {
        CSharpCodeProvider csp = new CSharpCodeProvider();
        ICodeCompiler cc = csp.CreateCompiler();
        CompilerParameters cp = new CompilerParameters();

        cp.OutputAssembly = Application.StartupPath + "\\TestClass.dll";
        cp.ReferencedAssemblies.Add("System.dll");
        cp.ReferencedAssemblies.Add("System.dll");
        cp.ReferencedAssemblies.Add("System.Data.dll");
        cp.ReferencedAssemblies.Add("System.Xml.dll");
        cp.ReferencedAssemblies.Add("mscorlib.dll");
        cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");
        cp.ReferencedAssemblies.Add("CSharpScripter.exe");

        cp.WarningLevel = 3;

        cp.CompilerOptions = "/target:library /optimize";
        cp.GenerateExecutable = false;
        cp.GenerateInMemory = false;

        System.CodeDom.Compiler.TempFileCollection tfc = new TempFileCollection(Application.StartupPath, false);
        CompilerResults cr  = new CompilerResults(tfc);

        cr = cc.CompileAssemblyFromSource(cp, this.rtfCode.Text);

        if (cr.Errors.Count > 0) 
        {
            foreach (CompilerError ce in cr.Errors) 
            {
                Console.WriteLine(ce.ErrorNumber + ": " + ce.ErrorText);
            }
            MessageBox.Show(this, "Errors occoured", "Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
            this.btnExecute.Enabled = false;
        } 
        else 
        {
            this.btnExecute.Enabled = true;
        }

        System.Collections.Specialized.StringCollection sc = cr.Output;
        foreach (string s in sc) 
        {
            Console.WriteLine(s);
        }
    }  
如何转换为exe文件

cp.GenerateExecutable = false;
你可能需要改变这句话


您可能需要更改该行…

您需要
exe
dll
?如果是exe,为什么命名为dll?如果是dll,为什么你的问题标题是exe?你需要
exe
dll
?如果是exe,为什么命名为dll?如果dll为什么你的问题标题是exe?可能还想将
/target:library
更改为
/target:winexe
。看@icemanind:或者完全摆脱它;我相信该属性设置的就是该选项。可能还希望将
/target:library
更改为
/target:winexe
。看@icemanind:或者完全摆脱它;我相信这个选择就是这个属性所设定的。