gpt4 book ai didi

c# - 如何在运行时制作exe maker

转载 作者:太空宇宙 更新时间:2023-11-03 20:12:42 25 4
gpt4 key购买 nike

我有这段代码,但它创建了一个 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;

你可能want改变那条线...

关于c# - 如何在运行时制作exe maker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19014138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com