Skip to main content
Version: 3.0.0 (RC 1) 🚧

Developing with .NET

Step 0. Creating the initial source code (optional)

We will create the example source code by using some popular frameworks.

This is optional and you may use an existing project instead or a starter project from odo init.

For .NET we will use the ASP.NET Core MVC example.

ASP.NET MVC is a web application framework that implements the model-view-controller (MVC) pattern.

  1. Generate an example project:
dotnet new mvc --name app
$ dotnet new mvc --name app
Welcome to .NET 6.0!
---------------------
SDK Version: 6.0.104

...

The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/6.0-third-party-notices for details.

Processing post-creation actions...
Running 'dotnet restore' on /Users/user/app/app.csproj...
Determining projects to restore...
Restored /Users/user/app/app.csproj (in 84 ms).
Restore succeeded.

Your source code has now been generated and created in the directory.

Step 1. Connect to your cluster and create a new namespace or project

Before starting you should make sure that odo is connected to your cluster and that you have created a new namespace (or project if you are using OpenShift).

Creating a new namespace

If you are using Kubernetes, you can create a new namespace with the odo create namespace command.

$ odo create namespace odo-dev
✓ Namespace "odo-dev" is ready for use
✓ New namespace created and now using namespace: odo-dev

Step 2. Initializing your application (odo init)

Now we'll initialize your application by creating a devfile.yaml to be deployed.

odo handles this automatically with the odo init command by autodetecting your source code and downloading the appropriate Devfile.

Note: If you skipped Step 0, select a "starter project" when running odo init.

Let's run odo init and select .NET:

odo init
$ odo init
  __
 /  \__     Initializing new component
 \__/  \    Files: Source code detected, a Devfile will be determined based upon source code autodetection

/ \__/ odo version: v3.0.0~beta3 \__/

Interactive mode enabled, please answer the following questions: Based on the files in the current directory odo detected Language: dotnet Project type: dotnet The devfile "nodejs" from the registry "DefaultDevfileRegistry" will be downloaded. ? Is this correct? Yes ✓ Downloading devfile "dotnet" from registry "DefaultDevfileRegistry" [501ms] Current component configuration: Container "runtime": Opened ports: - 8080 Environment variables: ? Select container for which you want to change configuration? NONE - configuration is correct ? Enter component name: my-dotnet-app Your new component 'my-dotnet-app' is ready in the current directory. To start editing your component, use 'odo dev' and open this folder in your favorite IDE. Changes will be directly reflected on the cluster.

A devfile.yaml has now been added to your directory and now you're ready to start development.

Step 3. Developing your application continuously (odo dev)

Now that we've generated our code as well as our Devfile, let's start on development.

odo uses inner loop development and allows you to code, build, run and test the application in a continuous workflow.

Once you run odo dev, you can freely edit code in your favourite IDE and watch as odo rebuilds and redeploys it.

Let's run odo dev to start development on your .NET application:

odo dev
$ odo dev
  __
 /  \__     Developing using the my-dotnet-app Devfile
 \__/  \    Namespace: default

/ \__/ odo version: v3.0.0~beta3 \__/

↪ Deploying to the cluster in developer mode ✓ Waiting for Kubernetes resources [3s] ✓ Syncing files into the container [330ms] ✓ Building your application in container on cluster [4s] ✓ Executing the application [1s] Your application is now running on the cluster - Forwarding from 127.0.0.1:40001 -> 8080 Watching for changes in the current directory /Users/user/dotnet Press Ctrl+c to exit `odo dev` and delete resources from the cluster

You can now access the application at 127.0.0.1:40001 in your local browser and start your development loop. odo will watch for changes and push the code for real-time updates.