Giter VIP home page Giter VIP logo

setup-vscode-for-csharp's Introduction

VS Code setup guide for C# .NET development

Required software

  • Download VS Code

  • Download .NET SDK

  • Install C# extension by Microsoft (ID: ms-dotnettools.csharp)

  • (optional) Install IntelliCode extension by Microsoft (ID: VisualStudioExptTeam.vscodeintellicode)

  • (optional) Install vscode-icons extension (ID: vscode-icons-team.vscode-icons)

  • (optional) Install GitLens extension (ID: eamodio.gitlens)

  • (optional) Install NuGet Package Manager extension (ID: jmrog.vscode-nuget-package-manager)

Setup of a Console App

  • Create a new solution

    dotnet new sln -n "SOLUTION_NAME"
    
  • Create new Console App project

    dotnet new console -n "PROJECT_NAME"
    
  • Create desired library projects

    dotnet new classlib -n "LIBRARY_NAME"
    
  • Add each project to the solution

    dotnet sln SOLUTION_NAME.sln add ./PROJECT_NAME/PROJECT_NAME.csproj
    
  • Add references betwen projects (if there are any)

    dotnet add PROJECT_NAME/PROJECT_NAME.csproj reference LIBRARY_NAME/LIBRARY_NAME.csproj
    
  • Create .gitignore file to exclude output files

    dotnet new gitignore
    

    in case You already commited some of the files that are being excluded, before actually generating gitignore file, you should perform:

    git rm -rf --cached .
    git add .
    

    which will remove and read all of the files with respect to the .gitignore file. That means that this time files won't be tracked by git anymore. Some more detail can be found on Stack Overflow issue regarding that matter.

  • Generate assets for build and debug - C# Extension should automatically prompt You whether You want to generate them, but if it does not, You can generate them manually ussing command pallette.

    • open command pallette:

       CTRL + SHIFT + P
      
    • look for:

      .NET Generate Assets for Build and Debug
      

    If an error occurs, especially one that says that OmniSharp is not running (and all attempts to restart it from command pallette fail), some previous version of C# Extension could be installed to solve it. But if that's not the case, or if You want to check different solutions, feel free to check out Stack Overflow issue related to that matter.

    In case of succes, directory with files containing configuration is created

    Generated assets structure

Running the app

  • To directly run the app, cd into the Project directory in VS Code's integrated terminal and use:

    dotnet run
    

    The project will run directly in the integrated terminal without any additional functionalities like debugger.

  • Make use of the Run and Debug Assets generated previously, to benefit for example from debbugging capabilities.

    • Press F5 to run the default selected profile (since the right profile will be the first one, of two we generated, it will be selected by default)
    • Go to Run and Debug side menu and launch .NET Core Launch (console) profile - notice that it's name matches with the name stated in launch.json file that was generated previously.

Adding NuGet Packages to the project

  • While being in the Project's directory, use:

    dotnet add package PACKAGE_NAME
    

    to add the latest non-preview version of a package to the Project.

  • Insert the reference manually

    • add entry into .csproj file between ItemGroup tags

      <ItemGroup>  
          <PackageReference Include="PACKAGE_NAME" Version="PACKAGE_VERSION" />  
      </ItemGroup>
    • perform

      dotnet restore
      

      to fetch referenced packages

  • Use NuGet Package Manager extension

    • open command pallette:

      CTRL + SHIFT + P
      
    • look for:

      NuGet Package Manager: Add Package
      
    • insert desired package name

    • choose the package version

    • select the Project You want to add the NuGet reference to


References

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.