I have built and deployed a dotnet 6 6.0.300
application under IIS. The application contains this global.json
file:
{
"sdk": {
"version": "6.0.300"
}
}
The IIS app pool is configured to use No Managed Code
under the .NET CLR version.
There is a previous version of dotnet (3.1.421
) installed.
If I run the dotnet --version
command I see 3.1.425
and dotnet --info
shows:
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
How can I confirm conclusively that the net6 version is being used to run the application?
--version
outputs the SDK version, not runtime. From the docs:
Prints out the version of the .NET SDK used by
dotnet
commands, which may be affected by aglobal.json
file. Available only when the SDK is installed.
It has nothing to do with runtime selected for your app during runtime.
And you can be completely sure that older major runtime version will never be used because runtime selection does not support rolling backwards to the previous major version (for quite obvious reasons).
From the .NET version selection doc:
Framework-dependent apps roll-forward
The host chooses the latest patch version installed on the machine. For example, if you specifiednet5.0
in your project file, and5.0.2
is the latest .NET runtime installed, the5.0.2
runtime is used.
global.json
determines SDK used to build the app, but required runtime is determined by the specified target framework (i.e. you can use .NET 7 SDK to build .NET 6 app).
But if you want to be really-really sure you can always check the version programmatically:
Console.WriteLine(Environment.Version);
Console.WriteLine(RuntimeInformation.FrameworkDescription);