Skip to content

Instantly share code, notes, and snippets.

@devpro
Last active March 10, 2020 17:12
Show Gist options
  • Save devpro/93676a31d6aa4e7775e4d8e29f58af25 to your computer and use it in GitHub Desktop.
Save devpro/93676a31d6aa4e7775e4d8e29f58af25 to your computer and use it in GitHub Desktop.
.NET development best practices

General best practices in .NET development

File structure

root:
  - .azure:
    - pipelines:
      - ci.yaml
      - pkg.yaml
      - cd.json
  - src:
    - MyLib:
      - Dockerfile
      - MyLib.csproj
    - MyConsoleApp
    - MyWebApp:
      - Dockerfile
      - MyWebApp.csproj
  - test:
    - MyLib.UnitTests
    - MyWebApp.IntegrationTests
  - .editorconfig
  - .gitignore
  - mysolution.sln
  - README.md

Solution file (sln)

It should always be at the root folder of the git repository.

Folders should be used to improve visibility (folders in Visual Studio are not real file folders).

Project file (csproj)

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <!-- ONLY for applications! -> Console, Web App, Tests projects -->
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <!-- For all the other projects = libraries projects -->
    <TargetFramework>netstandard2.1</TargetFramework>
    <!-- Define full namespaces to be able to shorten the folder and project names -->
    <AssemblyName>My.Full.Namespace</AssemblyName>
    <RootNamespace>My.Full.Namespace</RootNamespace>
    <!-- Mandatory for Sonar: easy to create with Visual Studio tool to generate Guids -->
    <ProjectGuid>{xxxx-xxx-xxx-xxx-xxxxx}</ProjectGuid>
    <!-- On tests projects and console / web applications -->
    <IsPackable>true</IsPackable>
  </PropertyGroup>

  <!-- Mandatory -->
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

EditorConfig file

dotnet format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment