-3

This C# code is for running a Winform application that I have merged together. I want to create an exe file from that C# code.

How can this be done?

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
}

}

p.campbell
  • 98,673
  • 67
  • 256
  • 322
amir-yeketaz
  • 254
  • 2
  • 5
  • 11
  • 7
    Have you tried using a C# compiler (`csc.exe`)? – Darin Dimitrov Oct 05 '11 at 17:21
  • I am presuming that you don't have visual studio ? Go get Visual C# Express 2010 from Microsoft. Its free! – user957902 Oct 05 '11 at 17:23
  • sorry ... but I know what are you saying to me ... so i know IDE like VS or anything and how to use it !!! I want that my C# winform produce a exe file! OK?! ... actually ... I want to produce exe file from my project(windows form application) !!! ... I'm creating a program like visual studio can create exe file... but so simpler than VS!!! I want some code to produce exe file from my file that i wrote in my first post!!!! – amir-yeketaz Oct 05 '11 at 18:28
  • I think you want to build C# code from your app. Take a look here: http://stackoverflow.com/questions/7264682/running-msbuild-programmatically – Jayanta Dey Oct 06 '11 at 06:32

2 Answers2

7

You can use csc compiler and write this in console (path to csc.exe may vary), I'm assuming that your code file name is program.cs:

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

Executable file will be named program.exe

If you want to do this from C# code (If I understand correctly what you want to do), you can do it in this way:

Build and execute C# console application with this code:

using System.Diagnostics;

static void Main(string[] args)
{
    Process.Start(@"C:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe", "/t:winexe program.cs");
}
Łukasz Wiatrak
  • 2,747
  • 3
  • 22
  • 38
-1

You need a compiler or an IDE with an inbuilt compiler

Try using Microsoft Visual C# Express, it's free

DarkDevine
  • 1,047
  • 1
  • 9
  • 12
  • He already has the compiler he would have to call it by hand. Since he is asking how to do that its safe to say thats not an option :-) – Security Hound Oct 05 '11 at 17:31
  • your reply is not for my problem at all!!! ... because I want produce exe file from that file inside my project!!! – amir-yeketaz Oct 05 '11 at 18:30