skip to Main Content

How can I choose spesific version of dotnet in Ubuntu 20.04 service configration if there are multiple dotnet version installed ?

sample service conf :

[Unit]
Description=example .NET Web App running on Ubuntu

[Service]
WorkingDirectory=/var/www/example.com
ExecStart=/usr/bin/dotnet /var/www/axample.com/WebApplication.dll

How do I change ExecStart=/usr/bin/dotnet which version 5?

dotnet --info : 
.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  3.1.415 [/usr/share/dotnet/sdk]
  5.0.403 [/usr/share/dotnet/sdk]
  6.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.21 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.21 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

2

Answers


  1. There will be a file with extension .runtimeconfig.json

    That shows the framework that will be used.

    Example for a project that use .net core 3.1.0:

    {
      "runtimeOptions": {
        "tfm": "netcoreapp3.1",
        "framework": {
          "name": "Microsoft.AspNetCore.App",
          "version": "3.1.0"
        },
        "configProperties": {
          "System.GC.Server": true,
          "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
        }
      }
    }
    
    Login or Signup to reply.
  2. This isn’t a run-time setting, it’s a build time setting.

    When you are building your application, you have to pick what SDK is used to compile it and what .NET runtime it targets.

    After the application is built and you are looking to run it, all the decisions have already been made and you can’t really change them, without making things much harder for yourself.

    You can use global.json to select which SDK is used. You can use the project file itself (.csproj) to select which runtime is used by setting the TargetFramework appropriately.

    See https://learn.microsoft.com/en-us/dotnet/core/versions/selection for more details.

    Once you have dotnet published your application, all these decisions are frozen.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search