How do I get the .NET Core runtime version of a se

2019-08-27 08:11发布

问题:

I publish my .NET Core app using dotnet publish -r linux-x64, so it is self-contained and .NET Core runtime is not installed on the server where it runs. It's being built using .NET Core 2.1.something - I think. How do I get the exact version to know for sure? Ideally I'd like to get this at runtime, so the application itself can report what runtime it's running on, but even if there is some SDK tool that reports it (like dotnet get-runtime-version My.Assembly.Dll) that's better than nothing.

回答1:

When the application is published, it will generate My.Assembly.deps.json and this contains the information about the included runtime. Look for the version of Microsoft.NETCore.App that is referenced.

Example (trimmed only to the relevant properties):

{
  "targets": {
    ".NETCoreApp,Version=v2.2/win-x86": {
      "My.Assembly/1.0.0": {
        "dependencies": {
          "Microsoft.NETCore.App": "2.2.4"
        },
        "runtime": {
          "My.Assembly.dll": {}
        }
      }
    }
  }
}

deps.json is further documented in Runtime Configuration Files as part of the .NET Core CLI spec, although it doesn't directly define the relationship to the runtime version.



标签: .net-core