【问题标题】:how to create an exe file from my created file(.cs file)? [closed]如何从我创建的文件(.cs 文件)创建一个 exe 文件? [关闭]
【发布时间】:2011-10-05 17:18:29
【问题描述】:

此 C# 代码用于运行我合并在一起的 Winform 应用程序。我想从那个 C# 代码创建一个 exe 文件。

如何做到这一点?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public static class Program
    {
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

public class Form1 : Form
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
    public Form1()
    {
        InitializeComponent();
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Text = "Form1";
    }

    #endregion
}

}

【问题讨论】:

  • 您是否尝试过使用 C# 编译器 (csc.exe)?
  • 我假设你没有视觉工作室?从 Microsoft 获取 Visual C# Express 2010。它是免费的!
  • 对不起......但我知道你在对我说什么......所以我知道像VS或任何东西这样的IDE以及如何使用它!我希望我的 C# winform 生成一个 exe 文件!好的?! ...实际上...我想从我的项目(Windows 窗体应用程序)中生成 exe 文件!!! ...我正在创建一个像visual studio这样的程序可以创建exe文件...但是比VS简单!!!我想要一些代码从我在第一篇文章中写的文件中生成 exe 文件!!!!
  • 我认为您想从您的应用程序构建 C# 代码。看这里:stackoverflow.com/questions/7264682/…

标签: c# winforms


【解决方案1】:

您可以使用 csc 编译器并在控制台中编写此代码(csc.exe 的路径可能会有所不同),我假设您的代码文件名为 program.cs:

C:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe /t:winexe program.cs

可执行文件将命名为program.exe

如果您想从 C# 代码中执行此操作(如果我理解正确您想要执行的操作),您可以通过以下方式执行此操作:

使用以下代码构建并执行 C# 控制台应用程序:

using System.Diagnostics;

static void Main(string[] args)
{
    Process.Start(@"C:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe", "/t:winexe program.cs");
}

【讨论】:

  • thanx ... 如何使用 C# 代码来使用它?!
  • 我不知道你想在哪里使用这个 C# 代码,我已经写了一些代码并更新了我的帖子,也许这会对你有所帮助。
  • 对不起,我没有得到任何可执行文件。生成的.exe路径是什么?
  • @SGG 对我来说它是在 csc.exe 被调用的路径中生成的......所以如果你使用完整的 C:\Windows\Microsoft.NET\Framework\v...` path, the generated .exe` 调用 csc.exe 可能会在那里。跨度>
【解决方案2】:

您需要一个编译器或带有内置编译器的 IDE

尝试使用 Microsoft Visual C# Express,它是免费的

【讨论】:

  • 他已经有了编译器,他必须手动调用它。既然他在问如何做到这一点,可以肯定地说那不是一个选择:-)
  • 你的回复根本不是我的问题!!! ...因为我想从我的项目中的那个文件生成 exe 文件!!!
猜你喜欢
  • 2016-03-19
  • 1970-01-01
  • 1970-01-01
  • 2020-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-09
相关资源
最近更新 更多