简体   繁体   中英

Why is my ASP.NET Web Site project targeting .NET Framework 4.6.1 when I have told it to target 4.8?

We have a large Visual Studio 2015 solution with several Web Site (as opposed to Web Application ) projects and dozens of business-logic DLL projects. We were targeting .NET Framework 4.6.1, but I've now installed Visual Studio 2019 on my local PC and re-targeted all the projects to 4.8

When I build the solution using our existing PowerShell/MSBuild script, all the DLLs build successfully, but I get the following error when it comes to our first Web Site project:

C:\\[omitted]_MyWebSite.metaproj : warning MSB3274: The primary reference "C:\\[omitted]\\MyDLL.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.8" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.6.1".

Then later, when the compiler reaches some code on the site that tries to use the DLL:

c:\\[omitted]MyController.cs(6): error CS0246: The type or namespace name 'MyDLL' could not be found (are you missing a using directive or an assembly reference?) [C:\\[omitted]_MyWebSite.metaproj]

(This is just a sample reference error. In fact, all of the DLLs seem to suffer from this issue wherever they are used in the Web Site project.)

Relevant lines in the site's web.config file:

  <location path="." inheritInChildApplications="false">
    <system.web>
    [omitted]
      <httpRuntime targetFramework="4.8" requestValidationMode="2.0" maxRequestLength="10240" />
      <compilation debug="true" strict="false" explicit="true" targetFramework="4.8">

I am using the following MSBuild.exe path:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\msbuild.exe -maxcpucount:1 -verbosity:detailed

Looks like it's not enough to update the web.config file for Web Site Projects. You also have to update the target in the property pages. So in Solution Explorer, find your Web Site Project, right-click > Property Pages > Build > Target Framework > change to .NET Framework 4.8.

This is independent of the web.config file and resulted in a change in my .sln file from:

ProjectSection(WebsiteProperties) = preProject
[...omitted...]
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.6.1"

to:

ProjectSection(WebsiteProperties) = preProject
[...omitted...]
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.8"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM