gpt4 book ai didi

.net - 针对 .NET 4.7.2 时引用 System.Net.Http 的正确方法是什么?

转载 作者:行者123 更新时间:2023-12-02 11:16:58 27 4
gpt4 key购买 nike

我有一个包含一些 Web 应用程序的解决方案,因此 AspNetCompiler 任务在构建期间正在运行。还给出:

  • VS 2017
  • 使用/err 开关在命令行上调用 msbuild,即将警告提升为错误

  • 从头开始构建我们的代码时,我收到以下错误(可能是升级警告,我不在乎):
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.SystemAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.SystemAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: RecruitingCommon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: RecruitingCommon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.Reporting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.Reporting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.ClientAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.Web.ClientAdmin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: DataCapturing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: DataCapturing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\CandidatePortal\CandidatePortal.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.BusinessAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\SSOLauncher\SSOLauncher.csproj]
    ASPNETCOMPILER : error : The following assembly has dependencies on a version of the .NET Framework that is higher than the target and might not load correctly during runtime causing a failure: Xyz.BusinessAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b3dac0a0872f0a93. The dependencies are: System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a; System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. You should either ensure that the dependent assembly is correct for the target framework, or ensure that the target framework you are addressing is that of the dependent assembly. [C:\Xyz\tip\UI\SSOLauncher\SSOLauncher.csproj]

    我们所有的项目都像这样引用 System.Net.Http:
    <Reference Include="System.Net.Http" />

    没有项目在其 app.config 或 web.config 文件中为此程序集绑定(bind)重定向。

    所有项目都针对 .NET 框架 4.7.2,但一些第 3 方依赖项是 .NET 标准。

    无论如何,我已经搜索了互联网并且:
  • 有些人声称引用 System.Net.Http 只能从 NuGet 完成,有些人则相反。
  • 有些人声称绑定(bind)重定向是必要的,其他人则相反。
  • 有人说问题已通过 .NET Framework 4.7.2 解决(显然不是)

  • 我也知道:
  • GAC 包含 System.Net.Http.dll,其程序集版本为 4.0.0.0,文件版本为 4.7.3190.0 built by: NET472REL1LAST_C。我从中得出结论,它对应于 .NET 4.7.2
  • 另一方面,在编译过程中,msbuild 解析对 c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Net.Http.dll 的引用,它的程序集版本为 4.2.0.0,文件版本为 4.7.3062.0 built by: NET472REL1

  • 现在我很困惑。引用程序集中的 System.Net.Http.dll 文件版本表明它比 GAC 的文件版本旧,但它的程序集版本是 4.2.0.0 ?如何在运行时在 GAC 中具有 4.0.0.0 版本的机器上解决这种依赖关系?检查较旧的 .NET 版本(如 3.7.1 及更低版本)的引用程序集显示 System.Net.Http.dll 的程序集版本为 4.0.0.0,因此 .NET 框架 4.7.2 引入了这种困惑

    那么,我怎样才能让这该死的东西编译干净呢?另外,我不明白为什么只有 AspNetCompiler 提示。如何解决它呢?二进制日志似乎对 AspNetCompiler 错误一点帮助都没有。

    最佳答案

    到目前为止,我只找到了一种方法来完成这项工作。我们必须使用 .net framework 4.7.2 来处理 Chromium SameSite cookie 要求。似乎有几个网站记录了这一点,但由于一长串 NuGet 依赖问题,我们无法访问 Microsoft.Owin 4.x。下面的一些信息是针对 SameSite 修复的,但我在 .net 框架 4.7.2 中的 System.Net.Http 程序集上遇到了很多困难,所以下面也是。
    我发现如果您将 MVC 和 Web.Api 项目带到 .net 框架 4.7.2,那么请确保您所有使用 System.Net.Http 的项目都引用 GAC 4.2.0.0 版本。我有也运行 Web.api Controller 的类库项目。我还在 GAC 版本旁边安装了 NuGet System.Net.Http。您可能必须编辑您的项目文件以引用两者。项目文件中的 NuGet 程序集引用应包含 ExcludeAssets 元素。 Example Exclude Assets
    我最终将我的非主项目 web.api 类库项目转换为使用 PackageReference 而不是 packages.config。我认为这是使用 excludeAssets 所必需的。
    我还使用 nuget 包管理器控制台将所有 nuget 包重新安装到目标框架 4.7.2。 Re-install NuGet packages to re-target framework 4.7.2
    您的主项目 web.config 应该 不是 为 System.Net.Http 定义了一个 runtimedependentAssembly 部分。它需要被排除,所以它会被自动选择。我所做的其他类库项目包括对 System.Net.Http 版本 4.2.0.0 的dependentAssembly 引用。我还将程序集定义和运行时依赖程序集添加到我的 Views web.config 和我的区域内的所有 Views web.config 文件中。我不确定这是多么必要。

    <system.web>
    <compilation>
    <assemblies>
    <add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </assemblies>
    </compilation>
    </system.web>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
    </dependentAssembly>
    </assemblyBinding>
    </runtime>
    我使用这个站点来帮助编写一个 cookie 重写器。我发现这只处理 system.web cookie 而不是 OWIN cookie。 Cookie rewriter for same site
    我无权访问 4.x OWIN 修复程序以将 SameSite 属性添加到 OWIN cookie,但我确实找到了一种方法,系统会通过将 SystemWebCookieManager 添加到 OWIN 选项来自动为您执行此操作。 SameSiteCookieManager

    关于.net - 针对 .NET 4.7.2 时引用 System.Net.Http 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58251873/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com