Skip to content

Setup 1. Dev Environment

Sandro Ferreira edited this page Nov 29, 2021 · 4 revisions

Setting Up Development Environment

By: Sandro Ferreira - Mar. 26, 2020

1. Visual Studio and Solution Setup

Install ASP.NET and web development workload.

1.1. Defining the connection string

In order to match the Heroku connection string, it must be created like this:

<!--Template:-->
postgres://<user>:<password>@<host>:<port>/<database>

<!--Example:-->
postgres://postgres:password@localhost:5432/postgres

1.2. Setting the Environment Variables on the Solution

The environment variables are setted on the launchSettings.json property file. Example:

{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "DATABASE_URL": "postgres://postgres:password@localhost:5432/postgres"
      }
    },
    "Docker": {
        "commandName": "Docker",
        "launchBrowser": true,
        "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
        "publishAllPorts": true,
        "useSSL": false,
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development",
            "DATABASE_URL": "postgres://postgres:password@<psql_container_ip>:5432/postgres"
        }
    }
}

2. PostgreSQL on Docker

2.1. Create Postgresql container

docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres

2.2. Database Schema

Create the database schema using the Database.sql file available on the resources folder.


3. Setup Sonar Qube - Static Code Quality Analysis

3.1. Create Sonar Qube Container

docker pull sonarqube
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube

Start the container:

docker start sonarqube

Access Sonar Qube with the following URL: http://localhost:9000

Login details:
Username: admin
Password: admin

3.2. Install dotnet sonarqube command line tools

dotnet tool install --global dotnet-sonarscanner

3.3. Analyse solution

dotnet sonarscanner begin /k:"<app-name>" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="<app-key>"
dotnet build
dotnet sonarscanner end /d:sonar.login="<app-key>"