Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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# 动态编译windows应用程序时,如何隐藏控制台窗口?_C#_Visual Studio 2010 - Fatal编程技术网

C# 动态编译windows应用程序时,如何隐藏控制台窗口?

C# 动态编译windows应用程序时,如何隐藏控制台窗口?,c#,visual-studio-2010,C#,Visual Studio 2010,事实上,我的问题是一年前在这个话题上提出的- 现在我也遇到了同样的问题,只是我没有使用命令行编译器,所以这个解决方案不适合我 请帮忙。 非常感谢 编辑 这是代码。它主要是从微软的支持人员那里获得的 由于它是动态编译的,我不知道在哪里传递我不需要控制台显示的概念 抱歉,它太大了,因为字符串源是我的整个其他类 using System.Windows.Forms; using System.Diagnostics; using System.CodeDom.Compiler; using Syste

事实上,我的问题是一年前在这个话题上提出的-

现在我也遇到了同样的问题,只是我没有使用命令行编译器,所以这个解决方案不适合我

请帮忙。 非常感谢

编辑

这是代码。它主要是从微软的支持人员那里获得的

由于它是动态编译的,我不知道在哪里传递我不需要控制台显示的概念

抱歉,它太大了,因为字符串源是我的整个其他类

using System.Windows.Forms;
using System.Diagnostics;
using System.CodeDom.Compiler;
using System;
using System.Drawing;
using System.IO;

namespace compile
{
public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
        button1.Click += new EventHandler(button1_Click);
    }

    void button1_Click(object sender, EventArgs e)
    {
        CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
        string Output = "Out.exe";
        Button ButtonObject = (Button)sender;

        System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
        //Make sure we generate an EXE, not a DLL
        parameters.GenerateExecutable = true;
        parameters.OutputAssembly = Output;
        parameters.ReferencedAssemblies.Add("System.dll");
        parameters.ReferencedAssemblies.Add("System.Drawing.Dll");
        parameters.ReferencedAssemblies.Add("System.Windows.Forms.Dll");


        ////////////////////////////////////////////////////////////////////////////////////
        string text = @"using System;
                    using System.Windows.Forms;
                    using System.Drawing;


static class Program
{

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new TestForm());
    }
}




partial class TestForm
{

    private System.ComponentModel.IContainer components = null;

    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code


    private void InitializeComponent()
    {
        //System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestForm));
        this.MainLabel = new System.Windows.Forms.Label();
        this.MainLabel2 = new System.Windows.Forms.Label();
        this.BackBtn = new System.Windows.Forms.Button();
        this.NextBtn = new System.Windows.Forms.Button();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.elementPanel = new System.Windows.Forms.Panel();
        this.label1 = new System.Windows.Forms.Label();
        this.groupBox1.SuspendLayout();
        this.elementPanel.SuspendLayout();
        this.SuspendLayout();
        // 
        // MainLabel
        // 
        this.MainLabel.AutoSize = true;
        this.MainLabel.Font = new System.Drawing.Font(""Microsoft Sans Serif"", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
        this.MainLabel.Location = new System.Drawing.Point(10, 9);
        this.MainLabel.Name = ""MainLabel"";
        this.MainLabel.Size = new System.Drawing.Size(126, 18);
        this.MainLabel.TabIndex = 0;
        this.MainLabel.Text = ""Вопросы теста"";
        // 
        // MainLabel2
        // 
        this.MainLabel2.AutoSize = true;
        this.MainLabel2.Font = new System.Drawing.Font(""Microsoft Sans Serif"", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
        this.MainLabel2.Location = new System.Drawing.Point(10, 38);
        this.MainLabel2.Name = ""MainLabel2"";
        this.MainLabel2.Size = new System.Drawing.Size(479, 16);
        this.MainLabel2.TabIndex = 1;
        this.MainLabel2.Text = ""Выберите правильные ответы на вопросы из предложенных вариантов."";
        // 
        // BackBtn
        // 
        this.BackBtn.Anchor = 

                ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | 

        System.Windows.Forms.AnchorStyles.Right)));
        this.BackBtn.Font = new System.Drawing.Font(""Microsoft Sans Serif"", 

       9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
        this.BackBtn.Location = new System.Drawing.Point(447, 401);
        this.BackBtn.Name = ""BackBtn"";
        this.BackBtn.Size = new System.Drawing.Size(88, 26);
        this.BackBtn.TabIndex = 3;
        this.BackBtn.Text = ""Назад"";
        this.BackBtn.UseVisualStyleBackColor = true;
        // 
        // NextBtn
        // 
        this.NextBtn.Anchor = 

        ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | 

        System.Windows.Forms.AnchorStyles.Right)));
        this.NextBtn.Font = new System.Drawing.Font(""Microsoft Sans Serif"", 

         9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
        this.NextBtn.Location = new System.Drawing.Point(541, 401);
        this.NextBtn.Name = ""NextBtn"";
        this.NextBtn.Size = new System.Drawing.Size(88, 26);
        this.NextBtn.TabIndex = 4;
        this.NextBtn.Text = ""Вперед"";
        this.NextBtn.UseVisualStyleBackColor = true;
        // 
        // groupBox1
        // 
        this.groupBox1.Anchor = 

          ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | 

          System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | 

         System.Windows.Forms.AnchorStyles.Right)));
        this.groupBox1.Controls.Add(this.elementPanel);
        this.groupBox1.Controls.Add(this.MainLabel2);
        this.groupBox1.Controls.Add(this.NextBtn);
        this.groupBox1.Controls.Add(this.MainLabel);
        this.groupBox1.Controls.Add(this.BackBtn);
        this.groupBox1.Location = new System.Drawing.Point(2, 0);
        this.groupBox1.Name = ""groupBox1"";
        this.groupBox1.Size = new System.Drawing.Size(635, 433);
        this.groupBox1.TabIndex = 5;
        this.groupBox1.TabStop = false;
        // 
        // elementPanel
        // 
        this.elementPanel.Anchor = 

                 ((System.Windows.Forms.AnchorStyles)               ((((System.Windows.Forms.AnchorStyles.Top | 

                 System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | 

                    System.Windows.Forms.AnchorStyles.Right)));
        this.elementPanel.AutoScroll = true;
        this.elementPanel.Controls.Add(this.label1);
        this.elementPanel.Location = new System.Drawing.Point(6, 57);
        this.elementPanel.Name = ""elementPanel"";
        this.elementPanel.Size = new System.Drawing.Size(624, 338);
        this.elementPanel.TabIndex = 5;
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Font = new System.Drawing.Font(""Microsoft Sans Serif"", 

             9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
        this.label1.Location = new System.Drawing.Point(4, 11);
        this.label1.MaximumSize = new System.Drawing.Size(610, 0);
        this.label1.Name = ""label1"";
        this.label1.Size = new System.Drawing.Size(601, 30);
        this.label1.TabIndex = 0;
        this.label1.Text = 

                  ""mmmmmmmmmmmm\r\n"";
        // 
        // TestForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(638, 433);
        this.Controls.Add(this.groupBox1);
        //this.Icon = ((System.Drawing.Icon)(resources.GetObject(""$this.Icon"")));
        this.Name = ""TestForm"";
        this.StartPosition = 

                  System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = ""Тест на знание английского языка"";
        this.Load += new System.EventHandler(this.TestForm_Load);
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.elementPanel.ResumeLayout(false);
        this.elementPanel.PerformLayout();
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.Label MainLabel;
    private System.Windows.Forms.Label MainLabel2;
    private System.Windows.Forms.Button BackBtn;
    private System.Windows.Forms.Button NextBtn;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.Panel elementPanel;
    private System.Windows.Forms.Label label1;
}



public partial class TestForm : Form
{
    public TestForm()
    {
        InitializeComponent();
    }

    private void TestForm_Load(object sender, EventArgs e)
    {
        BackBtn.Enabled = false;
        this.MouseWheel += new MouseEventHandler(TestForm_MouseWheel);
        int loc = 24 + label1.Height;
        for (int i = 0; i < 20; i++)
        {
            RadioButton newR = new RadioButton();
            newR.Text = ""test"";
            newR.AutoSize = true;
            newR.Location = new Point(4, loc);
            loc += 24;
            elementPanel.Controls.Add(newR);
        }
    }

    void TestForm_MouseWheel(object sender, MouseEventArgs e)
    {
        elementPanel.Focus();
    }

}
";
                         ////////////////////////////////////////////////////////////////////////////////////



        CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, text);

        if (results.Errors.Count > 0)
        {
            foreach (CompilerError CompErr in results.Errors)
            {
                textBox2.Text = textBox2.Text +
                            "Line number " + CompErr.Line +
                            ", Error Number: " + CompErr.ErrorNumber +
                            ", '" + CompErr.ErrorText + ";" +
                            Environment.NewLine + Environment.NewLine;
            }
        }
        else
        {
            //Successful Compile
            textBox2.ForeColor = Color.Blue;
            textBox2.Text = "Success!";
            Process.Start(Output);

        }
    }
}
    }

添加>parameters.CompilerOptions/t:winexe似乎适合我:

        CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
        string output = "Out.exe";
        var parameters = new CompilerParameters();
        parameters.GenerateExecutable = true;
        parameters.OutputAssembly = output;
        parameters.ReferencedAssemblies.Add("System.dll");
        parameters.ReferencedAssemblies.Add("System.Drawing.Dll");
        parameters.ReferencedAssemblies.Add("System.Windows.Forms.Dll");
        parameters.CompilerOptions = "/t:winexe";
        var results = codeProvider.CompileAssemblyFromSource(parameters, "namespace Bah { static class Program { static void Main() { System.Threading.Thread.Sleep(100000); } } }");
但我也添加了这一点:

        var psi = new ProcessStartInfo(output) {CreateNoWindow = true};
        Process.Start(output);
没有/t:winexe,我得到了一个命令窗口,如果按照您的方式执行,它会显示出来,如果添加了ProcessStartInfo,它会闪烁。使用/t:winexe选项时,窗口为我关闭,但我将ProcessStartInfo也设置为NoWindow


我想强调的是,编写这样一个表单是非常严格和脆弱的,似乎没有任何理由这样做。在处理CodeDom时,我们编译了动态用户输入,表示用户创建的计算和公式。管理起来很困难,而且对于大型软件包来说速度很慢。嵌入式脚本引擎本来是一个更好的选择,但没有一种经济高效的方法将其拆掉并替换,因此我们在技术上致力于采用这种方法添加参数。编译器选项/t:winexe似乎适合我:

        CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
        string output = "Out.exe";
        var parameters = new CompilerParameters();
        parameters.GenerateExecutable = true;
        parameters.OutputAssembly = output;
        parameters.ReferencedAssemblies.Add("System.dll");
        parameters.ReferencedAssemblies.Add("System.Drawing.Dll");
        parameters.ReferencedAssemblies.Add("System.Windows.Forms.Dll");
        parameters.CompilerOptions = "/t:winexe";
        var results = codeProvider.CompileAssemblyFromSource(parameters, "namespace Bah { static class Program { static void Main() { System.Threading.Thread.Sleep(100000); } } }");
但我也添加了这一点:

        var psi = new ProcessStartInfo(output) {CreateNoWindow = true};
        Process.Start(output);
没有/t:winexe,我得到了一个命令窗口,如果按照您的方式执行,它会显示出来,如果添加了ProcessStartInfo,它会闪烁。使用/t:winexe选项时,窗口为我关闭,但我将ProcessStartInfo也设置为NoWindow


我想强调的是,编写这样一个表单是非常严格和脆弱的,似乎没有任何理由这样做。在处理CodeDom时,我们编译了动态用户输入,表示用户创建的计算和公式。管理起来很困难,而且对于大型软件包来说速度很慢。嵌入式脚本引擎本来是一个更好的选择,但没有经济高效的方法将其删除并替换,因此我们在技术上致力于这种方法

如果您不使用命令行编译器,那么您使用的是什么?您使用的是框架提供的一些编译器类吗?是的,Visual Studio 2010的标准功能您不能为目标提供编译调用吗?您是否有正在使用的代码或库函数的引用?我很好奇你是怎么做到的。听起来和以前一样,您只需要一个winexe目标。如果您没有使用命令行编译器,那么您使用的是什么?您使用的是框架提供的一些编译器类吗?是的,Visual Studio 2010的标准功能您不能为目标提供编译调用吗?您是否有正在使用的代码或库函数的引用?我很好奇你是怎么做到的。这听起来像是和以前一样的问题,你只需要一个winexe的目标。非常感谢,这正是我需要的!回答得很好,6年后这帮了我的忙!非常感谢,这正是我需要的!回答得很好,6年后这帮了我的忙!