Here’s how to quickly create a console app to run, test, and verify code for syntax and logic.
By using the 3 below commands, you can create a new console app in 3 seconds. You can write your code within the public static void main method and run it to complete your validation.
dotnet new console -n quick-console-app
dotnet build
dotnet run
I like to write code separately in an app because it’s faster to run compared to running a whole Web API project. For example, to test your new code that converts DateTime to Unix style timestamp you will have to wait for the complete project to build and run which takes more than 30 seconds. Instead, create a new console app and paste your code to run and find out.
Bonus: Use Visual Studio Code.
If you want to add a bit more speed to your coding, use Visual Studio Code in place of Visual Studio Enterprise. VS Code is ideal if your apps are written in dotnet core.
dotnet new console -n quick-console-app
code .
dotnet build
dotnet run
I have used Visual Studio Enterprise to write code for very long. Even though I like the bells and whistles it provides, I get frustrated when it makes me wait too long especially when I’m in a rush.
Sometimes I had to wait more than 30 seconds to for Visual Studio Enterprise to create a simple console app. This changed once I started using the Visual Studio Code. It is fast and lightweight. It serves my purpose very fast. Like super fast.
Note:- Try installing shell command if syntax “code .” doesn’t open a VS Code editor for you.
Bonus: Use Web Coder.
Hell yeah, if you think the steps are still slower for you, try web coding. Go to https://dotnetfiddle.net in your browser. The website opens a page with a public static void main; ready for you to cruise forward. Bookmark it and you will save yourself a little bit more time.