How To Develop a Standalone (EXE) C# Application

Most Microsoft .Net applications require a setup program (msi) to allow a user to install the application on a host computer. However there are times when you might need to package a C# application as a standalone exe. Meaning, you simply copy the executable to the host computer and it contains it needs to run.

How-To
To create an standalone C# application is very simple. The magic is in the compilation of the application, otherwise the rest of the application is like any other. Write your application as you would any other C# application. Standalone applications are best suited for command line (shell) applications, or desktop applications.

Here are the steps to create a standalone executable application that doesn’t require any installation or setup programs.

When you install Visual Studio, a set of utilities are installed along with the Microsoft SDK. One of these tools is the Visual Studio Command-Line Shell. You will find it in the Visual Studio folder from the Start menu under Tools.

1- Launch the Visual Studio Command Prompt (2010). You will find it under the Visual Studio Tools subfolder.

2-At the prompt enter the following commands:
a) csc (this is the C# compiler)

b) /out applicationname.exe (this flag specifies the name of the executable)

c) /reference “path and name of reference” (list the dlls that your application will needand these dlls will be packaged with the exe. Make sure to enclose the path andfilenames in double quotes if there are spaces in the path)

d) List the full path and filename of each C# file in the application

e) List full path and filename of any other file that is required for the application


Here is a sample script:


csc /out:MyCSharpApplication.exe /reference:"C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.Excel.dll" C:\Users\klanguedoc\Documents\Visual Studio 2010\Projects\ProjectStandalone\ProjectStandalone\Program.cs C:\Users\klanguedoc\Documents\Visual Studio 2010\Projects\ProjectStandalone\ProjectStandalone\UpdateExcel.cs

This will compile a standalone executable. Of course you can create a batch and just run the batch file from the command prompt. Of you still to have the .Net framework installed on the host computer.

In Summary
Creating standalone applications is very easy and come in handy for different types of host devices or computers. These are also good for distributed applications which reduces complicated setup scripts.

More by this Author


Comments 2 comments

Vinix 2 years ago

Will this work on machines without any version of .NET Framework?


klanguedoc profile image

klanguedoc 2 years ago from Canada Author

yes it should but you have to include the framework in the EXE. Get the re-distributable from the msdn site and add the dll reference to the inputs.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working