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.