Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code run individual .cs files

Is there a way we can run individual .cs files in Visual Studio Code.

I have followed this link and runs fine but then I added Program2.cs and try to run using "dotnet run Program2.cs" but it failed for obvious reasons saying

link

Program2.cs(7,21): error CS0111: Type 'Program' already defines a member called 'Main' with the same parameter types [csharp.csproj]"

Is there a way to run individual .cs files. Or any way I can run individual .cs files that outputs to terminal/command prompt or console.

like image 841
raghzz Avatar asked Mar 27 '18 02:03

raghzz


Video Answer


2 Answers

dotnet command is just for .NET Core and you must do dotnet new console command to generate a project to run it

if you are using .NET Framework and having the environment variables correctly set on your system, you can use csc Program.cs command to individually compile a class file to an executable. But this way is highly deprecated for any further learning or development

like image 151
Alsein Avatar answered Oct 03 '22 12:10

Alsein


For this i've always used this c# scripting engine : http://csscript.net,

very easy to implement and works very well and you can reference local dlls, Nuget packages or GAC assemblies.

It also has a Visual studio code plugin, so you can run with F5, debug ...

like image 22
Chtiwi Malek Avatar answered Oct 03 '22 14:10

Chtiwi Malek