Skip to main content
Version: v3

Developing with .NET

Step 0. Creating the initial source code (optional)

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

Before we begin, we will create a new directory and cd into it.

mkdir quickstart-demo && cd quickstart-demo

This is optional and you may use an existing project instead (make sure you cd into the project directory before running any odo commands) 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 --output .
Example
$ dotnet new mvc --name app --output .
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 /home/user/quickstart-demo/app.csproj...
Determining projects to restore...
Restored /home/user/quickstart-demo/app.csproj (in 96 ms).
Restore succeeded.

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

Step 1. Preparing the target platform

Before starting on Podman, you should have Podman installed and configured properly on your machine. See Podman installation instructions for further details.

You also need odo 3.8.0 or later.

To make sure that odo has the appropriate version and detects your local Podman, run the command below and check that it reports the Podman Client version.

odo version
Sample Output
$ odo version
⚠ unable to fetch the cluster server version
odo v3.13.0 (6c1c8b2a1)

Podman Client: 4.6.0

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
Sample Output
$ odo init
__
/ \__ Initializing a new component
\__/ \ Files: Source code detected, a Devfile will be determined based upon source code autodetection
/ \__/ odo version: v3.15.0
\__/

Interactive mode enabled, please answer the following questions:
✓ Determining a Devfile for the current directory [1s]
Based on the files in the current directory odo detected
Supported architectures: all
Language: .NET
Project type: dotnet
The devfile "dotnet60:1.0.2" from the registry "DefaultDevfileRegistry" will be downloaded.
? Is this correct? No
? Select architectures to filter by: [Use arrows to move, space to select, <right> to all, <left> to none, type to filter]
> [x] amd64
[ ] arm64
[ ] ppc64le
[ ] s390x
? Select architectures to filter by: amd64
? Select language: .NET
? Select project type: .NET 6.0
✓ Downloading devfile "dotnet60" from registry "DefaultDevfileRegistry" [3s]

↪ Container Configuration "dotnet":
OPEN PORTS:
- 8080
ENVIRONMENT VARIABLES:
- ASPNETCORE_ENVIRONMENT = Development
- ASPNETCORE_URLS = http://*:8080
- CONFIGURATION = Debug
- STARTUP_PROJECT = app.csproj

? Select container for which you want to change configuration? NONE - configuration is correct
? Enter component name: my-dotnet-app

You can automate this command by executing:
odo init --name my-dotnet-app --devfile dotnet60 --devfile-registry DefaultDevfileRegistry

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.
note

If you skipped Step 0 and selected "starter project", your output will be slightly different.

note

When you first run odo init, it will detect the required devfile to be 'dotnet50', if this happens to you, please select No when asked Is this correct? and then select .NET 6.0 when asked for Select project type:. Take a look at the sample output for a reference.

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 --platform podman
Sample Output
$ odo dev --platform podman
__
/ \__ Developing using the "my-dotnet-app" Devfile
\__/ \ Platform: podman
/ \__/ odo version: v3.15.0
\__/

↪ Running on podman in Dev mode
✓ Deploying pod [14s]
✓ Syncing files into the container [312ms]
✓ Building your application in container (command: build) [7s]
• Executing the application (command: run) ...
✓ Waiting for the application to be ready [1s]
- Forwarding from 127.0.0.1:20001 -> 3000

↪ Dev mode
Status:
Watching for changes in the current directory /home/user/quickstart-demo

Keyboard Commands:
[Ctrl+c] - Exit and delete resources from podman
[p] - Manually apply local changes to the application on podman

Then wait a few seconds until odo dev displays Forwarding from 127.0.0.1:... in its output, meaning that odo has successfully set up port forwarding to reach the application running in the container.

You can now access the application via the local port displayed by odo dev (127.0.0.1:20001 in the sample output above) and start your development loop. odo will watch for changes and push the code for real-time updates.

You can now follow the advanced guide to deploy the application to production.