使用CodeDomProvider隐藏命令提示符 [英] Hiding Command Prompt with CodeDomProvider

查看:198
本文介绍了使用CodeDomProvider隐藏命令提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



但是,当我使用我的示例创建一个新的Windows窗体应用程序时编译器,MSDOS窗口也出现,如果我关闭DOS窗口,我的WinForms应用程序也关闭。如何告诉编译器?



这里是我的代码:

 使用System; 

命名空间JTS
{
public class CSCompiler
{
protected string ot,
rt,
ss,es;

protected bool rg,cg;

public string Compile(String se,String fe,String [] rdas,String [] fs,Boolean rn)
{
System.CodeDom.Compiler.CodeDomProvider CODEPROV = System .CodeDom.Compiler.CodeDomProvider.CreateProvider(CSharp);
ot =
fe;

System.CodeDom.Compiler.CompilerParameters PARAMS = new System.CodeDom.Compiler.CompilerParameters();
//确保编译器生成一个EXE文件,而不是一个DLL。
PARAMS.GenerateExecutable = true;
PARAMS.OutputAssembly = ot;
PARAMS.CompilerOptions =/ target:winexe; PARAMS.ReferencedAssemblies.Add(typeof(System.Xml.Linq.Extensions).Assembly.Location);
PARAMS.LinkedResources.Add(this.ico);

foreach(rdas中的String ay)
{
if(ay.Contains(。dll))
PARAMS.ReferencedAssemblies.Add(ay);
else
{
string refd = ay;
refd = refd +.dll;
PARAMS.ReferencedAssemblies.Add(refd);
}

}

System.CodeDom.Compiler.CompilerResults rs = CODEPROV.CompileAssemblyFromFile(PARAMS,fs);

if(rs.Errors.Count> 0)
{
foreach(System.CodeDom.Compiler.CompilerError COMERR in rs.Errors)
{
es = es +
行号:+ COMERR.Line +
,错误号:+ COMERR.ErrorNumber +
,'+ COMERR.ErrorText + 。 +
Environment.NewLine + Environment.NewLine;
}
}
else
{
//编译成功。
es =编译成功。

if(rn)System.Diagnostics.Process.Start(ot);
}
return es;
}
}
}


解决方案>

在C#编译器控制台窗口中显示/ target开关是exe。当/ target = winexe时,不显示控制台窗口。
http://msdn.microsoft.com/en-us/ library / 6h25dztx.aspx



尝试:

 
系统.CodeDom.Compiler.CompilerParameters PARAMS = new System.CodeDom.Compiler.CompilerParameters();

PARAMS-> CompilerOptions =/ target:winexe;

请参阅:
http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilerparameters.compileroptions.aspx


I've just got my own little custom c# compiler made, using the article from MSDN.

But, when I create a new Windows Forms application using my sample compiler, the MSDOS window also appears, and if I close the DOS window, my WinForms app closes too. How can I tell the Compiler? not to show the MSDOS window at all?

Thank you :)

Here's my code:

using System;

namespace JTS
{
    public class CSCompiler
    {
        protected string ot,
            rt,
            ss, es;

        protected bool rg, cg;

        public string Compile(String se, String fe, String[] rdas, String[] fs, Boolean rn)
        {
            System.CodeDom.Compiler.CodeDomProvider CODEPROV = System.CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp");
            ot =
                fe;

            System.CodeDom.Compiler.CompilerParameters PARAMS = new System.CodeDom.Compiler.CompilerParameters();
            // Ensure the compiler generates an EXE file, not a DLL.
            PARAMS.GenerateExecutable = true;
            PARAMS.OutputAssembly = ot;
            PARAMS.CompilerOptions = "/target:winexe"; PARAMS.ReferencedAssemblies.Add(typeof(System.Xml.Linq.Extensions).Assembly.Location);
            PARAMS.LinkedResources.Add("this.ico");

            foreach (String ay in rdas)
            {
                if (ay.Contains(".dll"))
                    PARAMS.ReferencedAssemblies.Add(ay);
                else
                {
                    string refd = ay;
                    refd = refd + ".dll";
                    PARAMS.ReferencedAssemblies.Add(refd);
                }

            }

            System.CodeDom.Compiler.CompilerResults rs = CODEPROV.CompileAssemblyFromFile(PARAMS, fs);

            if (rs.Errors.Count > 0)
            {
                foreach (System.CodeDom.Compiler.CompilerError COMERR in rs.Errors)
                {
                    es = es +
                        "Line number: " + COMERR.Line +
                        ", Error number: " + COMERR.ErrorNumber +
                        ", '" + COMERR.ErrorText + ";" +
                        Environment.NewLine + Environment.NewLine;
                }
            }
            else
            {
                // Compilation succeeded.
                es = "Compilation Succeeded.";

                if (rn) System.Diagnostics.Process.Start(ot);
            }
            return es;
        }
    }
}

解决方案

In C# compiler Console window is shown when /target switch is exe. When /target=winexe, Console window is not shown. http://msdn.microsoft.com/en-us/library/6h25dztx.aspx

Try this:

System.CodeDom.Compiler.CompilerParameters PARAMS = new System.CodeDom.Compiler.CompilerParameters(); 

PARAMS->CompilerOptions = "/target:winexe";

See: http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilerparameters.compileroptions.aspx

这篇关于使用CodeDomProvider隐藏命令提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆