I'm facing an issue deploying a .NET Framework 4.8 project on a new Windows Server 2019 machine. Similar projects with the same .NET Framework version was previously running without any problems on an older Windows Server 2019 setup.
Error Message:
During deployment, I encounter the following error related to the targetFramework attribute in the Web.config file:
The 'targetFramework' attribute in the <compilation> element of the Web.config file is used only to target version 4.0 and later of the .NET Framework (for example, '<compilation targetFramework="4.0">'). The 'targetFramework' attribute currently references a version that is later than the installed version of the .NET Framework. Specify a valid target version of the .NET Framework, or install the required version of the .NET Framework.
The error points to these lines in the Web.config:
Line 49: <compilation targetFramework="4.8" />
Line 50: <httpRuntime targetFramework="4.8" executionTimeout="1800" maxRequestLength="102400" />
To diagnose the problem, I checked the installed .NET Framework versions on both the new and old servers using the following PowerShell command:
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version
The command results suggest that .NET Framework 4.8 is not present on either server, which is confusing because the project runs fine on the old server but not on the new one.
Questions:
- Should I manually install the .NET Framework 4.8 version on the new server?
- Why does this behavior occur, where the project runs on one server but not the other, despite both seemingly lacking the .NET Framework 4.8?
- Would it be advisable to consider deploying the project under a different .NET Framework version, such as 4.7, and what are the key differences between .NET Framework 4.7 and 4.8 that might influence this decision? Any insights or suggestions would be greatly appreciated.