Setup dotnet development in Visual Studio, dotnet CLI and VS code

dotnet_setup

Install dotnet

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

image.png

  • Select project type as “Console Application”

image.png

  • Enter the solution name and project name

image.png

  • Select the dotnet version

image.png

  • Now a solution is created in visual studio as shown below

image.png

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

image.png

  • Open a folder in VS code
  • Open command palette (Ctrl+Shift+P) and search “.NET New Project”

image.png

  • Select the project type as Console App

image.png

  • Enter the project name and proceed

image.png

  • A solution and project named HelloWorld are created. A Visual studio like Solution Explorer will also be available.

image.png

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

Comments

Popular posts from this blog

ClaimsPrincipal, ClaimsIdentity, Claims explained in dotnet authentication

Implicit usings, top level statements, file scoped namespaces in dotnet

Introduction to dotnet with a simple hello world example