Setup dotnet development in Visual Studio, dotnet CLI and VS code
Install dotnet
- Download and install dotnet sdk from https://dotnet.microsoft.com/en-us/download
- Verify dotnet version with the command
dotnet --version
Solution and Projects in dotnet
- Project is a C# application. It is defined by a .csproj file
- Solution is a collection of multiple projects. It is defined using a .sln file
- A simple C# solution folder structure can be as follows
ConsoleAppSolution
│ ConsoleAppSolution.sln
│
├───ConsoleApp1
│ ConsoleApp1.csproj
│ Program.cs
│
└───ConsoleApp2
ConsoleApp2.csproj
Program.cs
Development with Visual studio
- Download and install visual studio from https://visualstudio.microsoft.com/downloads/
- Open Visual studio and select “Create New Project”
- Select project type as “Console Application”
- Enter the solution name and project name
- Select the dotnet version
- Now a solution is created in visual studio as shown below
Development with dotnet CLI
- dotnet CLI (command line interface) is a part of dotnet SDK. It can be used to run dotnet commands
- A solution in dotnet (defined by .sln file) is a group of dotnet projects (defined by .csproj file)
- Create a new dotnet solution named “CSharpApps” using
dotnet new sln -n CSharpApps
- Create a new dotnet console project named “HelloWorld” in a sub folder using
dotnet new console -o HelloWorld
- Add the project to solution using
dotnet sln add HelloWorld
- A folder structure like the following should be created
C:.
│ CSharpApps.sln
│
└───HelloWorld
HelloWorld.csproj
Program.cs
- Run the project using
dotnet run --project HelloWorld
Development with VS code
- Download VS code from https://code.visualstudio.com/download
- Install the
C# Dev Kit
extension in VS code
- Open a folder in VS code
- Open command palette (Ctrl+Shift+P) and search “.NET New Project”
- Select the project type as Console App
- Enter the project name and proceed
- A solution and project named
HelloWorld
are created. A Visual studio like Solution Explorer will also be available.
Access command line arguments in entry file
- use
args
keyword to access command line arguments in the entry csharp file
Console.WriteLine("Hello, World!");
foreach (var s in args)
{
Console.Write(s);
Console.Write(' ');
}
Video
The video tutorial for this post can be found here
References
- dotnet cli docs - https://learn.microsoft.com/en-us/dotnet/core/tools/
Comments
Post a Comment