I am building a .NET 5 based ASP.NET Web Application for REST APIs. It is a proof-of-concept at the moment. My hosting provider only supports 5.0.2 runtime but the SDK version came with .NET 5.0.103 (runtime 5.0.3) installed. I need to produce DLL with a target runtime of 5.0.2.
In order to be able to produce DLL for runtime 5.0.2, I installed .NET SDK version 5.0.102.
Now, I have SDKs and Runtimes as below (dotnet --info
):
.NET SDKs installed:
.NET runtimes installed:
I tried to force use of an earlier version using a global.json file. I put the file in the folder where the .csproj file exists. The content is as below:
{
"sdk": {
"version": "5.0.102"
}
}
dotnet --version
and dotnet --info
also report the SDK in use is 5.0.102
if I run these commands from the project directory:
D:\Projects-DriveD\VS\AspNetCoreWebSample\AspNetCoreWebSample>dotnet --version
5.0.102
D:\Projects-DriveD\VS\AspNetCoreWebSample\AspNetCoreWebSample>dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.102
Commit: 71365b4d42
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.102\
Host (useful for support):
Version: 5.0.3 <==========================================
Commit: c636bbdc8a
.NET SDKs installed:
5.0.102 [C:\Program Files\dotnet\sdk]
5.0.103 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
But even then, the DLL produced is targeting the runtime version 5.0.3. I think the problem could be because of Host Version is still 5.0.3, but I am not entirely sure.
I am verifying the runtime version of produced DLL using the Jetbrains dotpeek tool.
How can I force Visual Studio to produce a DLL which targets runtime version 5.0.2 instead of 5.0.3?
From the official documentation Select the .NET version to use :
The RuntimeFrameworkVersion element overrides the default version policy. For self-contained deployments, the RuntimeFrameworkVersion specifies the exact runtime framework version. For framework-dependent applications, the RuntimeFrameworkVersion specifies the minimum required runtime framework version.
In your csproj, you can add :
<RuntimeFrameworkVersion>5.0.2</RuntimeFrameworkVersion>