0

I am new to C#.

I have a program that I want to work on any computer.

How do I compile the application to work on any computer without dependencies?

A simple hello world let's say:

class MainApp {

public static void Main() {
    // Write text to the console.
    Console.WriteLine("Hello");
}
}
Bridge
  • 27,772
  • 8
  • 56
  • 78
susparsy
  • 936
  • 4
  • 18
  • 37
  • 5
    The computer will need the .NET framework. – Darren Aug 29 '13 at 11:45
  • 1
    You can compile it into native machine instructions using [ngen](http://msdn.microsoft.com/en-us/library/6t9t5wcf.aspx) but _note_ that generated instructions will be optimized for cpu on a machine, you're compiling. Also, do you _really_ need that? I mean Windows is the most used OS and it comes with .NET framework. If you target for other platforms take a look at mono. – Leri Aug 29 '13 at 11:48
  • possible duplicate of [Make an Installation program for C# applications and include .NET Framework installer into the setup](http://stackoverflow.com/questions/6090913/make-an-installation-program-for-c-sharp-applications-and-include-net-framework) – Shadow The Vaccinated Wizard Aug 29 '13 at 11:49
  • @ShadowWizard Not duplicate, OP wants executable that runs on every machine. – Leri Aug 29 '13 at 11:50
  • You can't have single .exe compiled to "work on any computer", you need to create installation package, see the linked post. – Shadow The Vaccinated Wizard Aug 29 '13 at 11:50
  • @susparsy you can do .. refer my answer and let me know – backtrack Aug 29 '13 at 11:54

3 Answers3

0

In order to run a .Net application, you need the .Net Framework installed on that computer.

If this is a problem for you, pick another language.

Rik
  • 26,673
  • 13
  • 47
  • 65
0

To compile the application, you can either use Visual Studio and choose the Build Solution from the Build menu.

You can also use the command line and csc.exe

To compile your application via csc you will need to execute the following statement in the command prompt.

csc YourFile.cs 

Any computer attempting to execute the assembly will need the .NET framework installed.

Darren
  • 63,390
  • 21
  • 126
  • 134
0

The other computer will need the ability to run .NET programs.

There are two ways that I know of that you can run your software on someone elses computer assuming they meet the above requirement.

  1. The first way is to go into the bin folder and get the executable (or the .exe file) this can just be distributed and ran. This is ussually in a path simular to this C:\Users\username\Documents\Visual Studio 2012\Projects\YourProjName\YourProjName\bin
  2. The second way is to create a click once application. How to create a click once

On a side note, if you want your program to run on almost any machine I would choose a different language. Java is pretty popular and it is VERY close to C#. Many colleges focus on Java as well so it gives you a leg up if you ever go to school for it. That said, I did my whole degree in Java and ended up in a .NET shop so I had to relearn a ton of stuff.... On second thought, just learn everything...

Anthony Russell
  • 9,093
  • 8
  • 52
  • 98
  • On an unrelated note, why did you approve [this edit](http://stackoverflow.com/review/suggested-edits/2952113)? It's basically an ok edit, but [the post itself](http://stackoverflow.com/a/18871198/321973) is copy-pasta which you should flag instead, rendering the edit obsolete **edit** never mind, it has been dealt with – Tobias Kienzler Sep 18 '13 at 12:08