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");
}
}
6
  • 5
    The computer will need the .NET framework. Commented Aug 29, 2013 at 11:45
  • 1
    You can compile it into native machine instructions using ngen 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. Commented Aug 29, 2013 at 11:48
  • possible duplicate of Make an Installation program for C# applications and include .NET Framework installer into the setup Commented Aug 29, 2013 at 11:49
  • @ShadowWizard Not duplicate, OP wants executable that runs on every machine. Commented Aug 29, 2013 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. Commented Aug 29, 2013 at 11:50

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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...

1 Comment

On an unrelated note, why did you approve this edit? It's basically an ok edit, but the post itself is copy-pasta which you should flag instead, rendering the edit obsolete edit never mind, it has been dealt with

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.