Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new .cs file in an existing project through the command line using .net 5.0

I'm using .net core to create and run some very simple C# code through the command line. I create a new console app using dotnet new console . It creates a .csproj file in the name of the directory I'm in (classes). So I have a classes folder which contains a classes.csproj file, a Program.cs file and some other folders.

In order to create some classes I need some other .cs files here, but I can't find out how to do it. I've tried the File:New command according to https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/introduction-to-classes, but I must be using the wrong syntax since it says:

The filename, directory name, or volume label syntax is incorrect.

Since I'm pretty much new to command line and coding(obviously), I've googled for some cmd syntax but still couldn't find anything to get it work.

I know It can be easily done in Visual Studio but I was wondering if there is a way to do it using cmd.

like image 440
Zahra Ahangari Avatar asked Nov 23 '25 21:11

Zahra Ahangari


1 Answers

Unfortunately, there is no command line to create a C# file in dotnet cli

but if you want to create a C# file with the terminal you can use bellow command

in Linux bash OR git bash in windows

touch YourFileName.cs

in Windows cmd

type NUL > YourFileName.cs
like image 134
Nima Airyana Avatar answered Nov 26 '25 10:11

Nima Airyana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!