1

I am new to dotnet core and I have tried to view the help of dotnet cli but does not seem to find an answer. How do we add a new class file to a dotnet core console app from dotnet CLI ?

2
  • I believe there's no such command, you should create file Program.cs manually in your file explorer, or in cli: touch Program.cs or vim Program.cs. Read more here: learn.microsoft.com/en-us/dotnet/core/tutorials/… Commented Jan 18, 2020 at 21:39
  • Thanks. I did create the file manually but since we have lots of commands to perform operations in cli hence wanted to know the possible way of adding a class with cli. Commented Jan 19, 2020 at 9:39

3 Answers 3

2

You can create your own custom templates for dotnet new (tutorial):

https://learn.microsoft.com/en-us/dotnet/core/tutorials/cli-templates-create-item-template

A list of samples of varying complexity can be found here....

https://github.com/dotnet/dotnet-template-samples

End of answer.


Non-answer

You didn't ask this but since vscode is a popular C# editor for people using dotnet new, if you happen to be using vscode you can create a new class file by typing e.g.

var myEye = new MyEye { color = "blue" };

Hit 'ctrl+.' over MyEye and select the option to create a new class in a file. You should see it created complete with properties and namespace.

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

Comments

2

You can add class using this extension: https://marketplace.visualstudio.com/items?itemName=jchannon.csharpextensions

Comments

0

One way that we can create a class from VSCode using a extension that is C# Extensions. this will help to create a new class into our solution.

enter image description here

Comments

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.