# Using .NET with NubesGen

This documentation is for running .NET applications with NubesGen, and there is another other options that might interest you:

NubesGen supports creating Azure App Service instances and Azure Functions instances, depending on the type of .NET application that you wish to deploy.

# Tutorial: running a .NET application with NubesGen

Prerequisites:

Tip: You can go to https://aka.ms/nubesgen-azure-shell (opens new window) to have those prerequisites installed, and run the script from a Web browser.

Steps:

  1. Create a sample .NET Web application using the .NET CLI (opens new window). We'll follow the beginning of the official "Get started with ASP.NET Core" tutorial (opens new window):
    dotnet new webapp -o dotnet-sample-app -f net7.0
    
  2. Create a project on GitHub called dotnet-sample-app, and push the generated project to that repository. Change <your-github-account> by the name of your GitHub account:
    cd dotnet-sample-app
    git init
    git add .
    git commit -m "first commit"
    git remote add origin https://github.com/<your-github-account>/dotnet-sample-app.git
    git branch -M main
    git push -u origin main
    
  3. In the cloned project (cd dotnet-sample-app), set up GitOps with NubesGen by running the NubesGen CLI (more information here):
     ./nubesgen-cli-linux gitops
    
  4. Use the command-line with NubesGen (more information here) to generate a NubesGen configuration:
    curl "https://nubesgen.com/demo.tgz?runtime=dotnet&application=app_service.standard&gitops=true" | tar -xzvf -
    
  5. Create a new branch called env-dev, and push your code:
    git checkout -b env-dev
    git add .
    git commit -m 'Configure GitOps with NubesGen'
    git push --set-upstream origin env-dev
    
  6. Go to your GitHub project, and check that the GitHub Action is running.
  7. You can go to the Azure Portal (opens new window) to check the created resources.
  8. The application should be deployed on your App Service instance. Its URL should be in the form https://app-demo-XXXX-XXXX-XXXX-XXXX-dev-001.azurewebsites.net/, and you can also find it in the GitHub Action workflow (Job: "display-information", step "Display Azure infrastructure information"), or in the Azure portal. As it is a simple application, it should print by default Hello, world.
  9. Once you have finished, you should clean up your resources:
    1. Delete the resource group that was created by NubesGen to host your resources, which is named rg-demo-XXXX-XXXX-XXXX-XXXX-001.
    2. Delete the storage account used to store your Terraform state, in the rg-terraform-001 resource group.

# Which Azure resources are created

If you deploy your .NET application to an Azure App Service instance, NubesGen will generate:

If you deploy your .NET application to an Azure Function, NubesGen will generate:

# .NET version support

NubesGen supports .NET 7.0 by default, as it's the current long term support version. If you want to use .NET 6, you will need to configure it in two places:

  • In the generated terraform/modules/app-service/main.tf, you need to modify dotnet_version = "7.0" to be dotnet_version = "6.0""
  • If you selected the GitOps option, at the beginning of the generated .github/workflows/gitops.yml file, there is a specific DOTNET_VERSION: '7.0' environment variable that should be modified to DOTNET_VERSION: '6.0'

# Configuration options

In the generated terraform/modules/app-service/main.tf file, NubesGen will configure some environment variables for your application.

  • DATABASE_URL: the URL to your database
  • DATABASE_USERNAME: the database user name
  • DATABASE_PASSWORD: the database password
  • REDIS_HOST: the Redis host name
  • REDIS_PASSWORD: the Redis password
  • REDIS_PORT: the Redis port (by default 6380)
  • AZURE_STORAGE_ACCOUNT_NAME: the storage account name
  • AZURE_STORAGE_ACCOUNT_KEY: the storage account key
  • AZURE_STORAGE_BLOB_ENDPOINT: the blob storage endpoint
  • MONGODB_DATABASE: the MongoDB database name
  • MONGODB_URI: the MongoDB database URL