简体   繁体   English

为什么我的 ASP.NET 网站项目在我告诉它面向 4.8 时面向 .NET Framework 4.6.1?

[英]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.我们有一个大型 Visual Studio 2015 解决方案,其中包含多个网站(而不是Web 应用程序)项目和数十个业务逻辑 DLL 项目。 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我们的目标是 .NET Framework 4.6.1,但我现在已经在本地 PC 上安装了 Visual Studio 2019 并将所有项目重新定位到 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:当我使用我们现有的 PowerShell/MSBuild 脚本构建解决方案时,所有 DLL 都成功构建,但在我们的第一个网站项目中出现以下错误:

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. C:\\[omitted]_MyWebSite.metaproj:警告 MSB3274:无法解析主要引用“C:\\[omitted]\\MyDLL.dll”,因为它是针对“.NETFramework,Version=v4.8”框架构建的。 This is a higher version than the currently targeted framework ".NETFramework,Version=v4.6.1".这是比当前目标框架“.NETFramework,Version=v4.6.1”更高的版本。

Then later, when the compiler reaches some code on the site that tries to use the DLL:然后,当编译器在站点上找到一些尝试使用 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] c:\\[omitted]MyController.cs(6): 错误 CS0246:找不到类型或命名空间名称“MyDLL”(您是否缺少 using 指令或程序集引用?)[C:\\[omitted]_MyWebSite。元项目]

(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.) (这只是一个示例引用错误。事实上,所有 DLL 似乎在网站项目中使用的任何地方都存在此问题。)

Relevant lines in the site's web.config file:站点的 web.config 文件中的相关行:

  <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:我正在使用以下 MSBuild.exe 路径:

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.看起来更新网站项目的 web.config 文件是不够的。 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.因此,在解决方案资源管理器中,找到您的网站项目,右键单击 > 属性页 > 构建 > 目标框架 > 更改为 .NET Framework 4.8。

This is independent of the web.config file and resulted in a change in my .sln file from:这与 web.config 文件无关,并导致我的 .sln 文件发生了以下变化:

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

to:到:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 asp.net核心目标框架4.6.1发布 - asp.net core target framework 4.6.1 publish 调试 ASP.NET (.NET Framework 4.8) web 应用程序时,没有为新 csproj 格式的 (.NET Framework 4.8) 库加载符号 - No symbols loaded for a (.NET Framework 4.8) library in new csproj format when debugging a ASP.NET (.NET Framework 4.8) web application 如何使用Asp.Net.Identity和Entity Framework 6在Asp.Net Core 2.0 Target Framework 4.6.1中设置身份? - How can I setup identity in Asp.Net Core 2.0 Target Framework 4.6.1 using Asp.Net.Identity and Entity Framework 6? 框架 4.8 的 web.config Asp.net Web 项目中不允许使用“sameSite”属性 - The 'sameSite' attribute is not allowed in web.config Asp.net Web project with framework 4.8 将网站从.NET 2.0升级到.NET 4.0会在Visual Studio中打开网站时发出警告“此项目的目标是ASP.NET 2.0 ...” - Upgrading a web site from .NET 2.0 to .NET 4.0 gives warning when opening web site in Visual Studio “This project is targeting ASP.NET 2.0…” 将 .NET Framework 4.6.1 更新到 4.8 后出错 - Error after updating .NET Framework 4.6.1 to 4.8 ASP.NET 简单网站“框架” - ASP.NET simple web site 'framework' asp.net 核心针对 .net 框架 - asp.net core targeting .net framework 反编译Asp.Net网站项目 - Decompile Asp.Net web site Project 我应该如何对ASP.NET网站项目进行版本控制? - How should I version an ASP.NET Web Site project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM