Question how do i use visual studio from a c# source file

conradszyman

New member
Joined
May 29, 2023
Messages
1
Programming Experience
1-3
i have a c# source file, when i open it it doesnt allow me to run it, in place of the run button there is an attach button which i have no idea what function it provides, basically i want to use the c# source file like how i use new visual studio projects which actually let me run them.
 
C# source files cannot be run. They need to be compiled into executable assemblies, and then assemblies can be executed (assuming you have the correct framework installed).

In general, you first create a C# project and then use "Add existing..." no the Solution Explorer menu to add in a pre-existing C# source file. After doing that you would compile, and run the resulting executable.

Visual Studio is not like Dev C++ or Code::Blocks that lets you open a random .c, .cxx, or .cpp file, and compile and run from it.

I'm not quite sure what you can achieve with Visual Studio Code -- e.g. if you have the right toolchains installed you can do something like you would do with Dev C++ or Code::Blocks.
 
i want to use the c# source file like how i use new visual studio projects which actually let me run them.

You can't. You need the project to run anything. Depending on the specifics of the situation, you can either add that file to a project - new or existing - as suggested above, or you can copy the code from that file into a file that is already part of a project. Either way, you need a project in order to run anything.
 

Latest posts

Back
Top Bottom