首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当目标为System.Net.Http 4.7.2时,引用.NET的正确方法是什么?

当目标为System.Net.Http 4.7.2时,引用.NET的正确方法是什么?
EN

Stack Overflow用户
提问于 2019-10-05 19:59:31
回答 1查看 5.3K关注 0票数 10

我有一个解决方案,其中包含了一些web应用程序,所以在构建过程中AspNetCompiler任务正在运行。还提供了:

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

在从头构建代码时,我得到以下错误(可能是升级警告,我不在乎):

代码语言:javascript
复制
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:

代码语言:javascript
复制
<Reference Include="System.Net.Http" />

没有任何项目在其app.config或web.config文件中对此程序集进行绑定重定向。

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

总之,我在网上搜索过:

  1. 有些人声称引用System.Net.Http应该只从NuGet中进行,有些人则说相反。
  2. 有些人声称绑定重定向是必要的,而另一些则相反。
  3. 有人说这个问题是用.NET框架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及更低版本),显示了装配版本为4.0.0.0的System.Net.Http.dll,因此在.NET框架4.7.2中引入了这种混乱。

那么,我如何使这该死的东西编译干净呢?另外,我不明白为什么只有AspNetCompiler会抱怨。如何才能彻底排除故障呢?二进制日志似乎对AspNetCompiler错误没有一点帮助。

EN

回答 1

Stack Overflow用户

发布于 2020-08-07 15:49:42

到目前为止,我只找到了一种方法来解决这个问题。我们必须使用.net框架4.7.2来处理Chromium需求。似乎有几个站点记录了这一点,但是由于大量的Microsoft.Owin依赖问题,我们无法访问NuGet 4.x。下面的一些信息是关于SameSite修复的,但是我在.net框架4.7.2中的System.Net.Http程序集中遇到了很多困难,所以下面也是如此。

我发现,如果您将MVC和Web.Api项目带到.net框架4.7.2,那么确保所有使用System.Net.Http的项目都引用了GAC4.2.0.0版本。我有类库项目也运行Web.api控制器。我还在GAC版本旁边安装了NuGet System.Net.Http。您可能必须编辑您的项目文件以同时引用两者。项目文件中的NuGet程序集引用应该包括一个ExcludeAssets元素。最后,示例排除资产我将我的非主项目web.api类库项目转换为使用PackageReference而不是packages.config。我认为这是使用excludeAssets所必需的。

我还使用nuget包管理器控制台重新安装所有nuget软件包,以达到4.7.2的目标框架。将NuGet包重新安装到重新目标框架4.7.2

您的主项目web.config应该而不是为System.Net.Http定义一个运行时dependentAssembly部分。需要排除它,以便自动选择它。我所做的其他类库项目包括对dependentAssembly版本4.2.0.0的System.Net.Http引用。我还将程序集定义和运行时dependentAssembly添加到我的视图、web.config和我所在区域内的所有视图web.config文件中。我不知道这有多必要。

代码语言:javascript
复制
<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>

我用这个网站来帮助写一个曲奇重写器。我发现这只负责system.web cookie,而不是OWIN。相同站点的Cookie重写器

我无法访问4.xowin补丁来将SameSite属性添加到OWIN中,但我找到了一种方法,即通过将SystemWebCookieManager添加到OWIN选项中,系统将自动为您完成此操作。SameSiteCookieManager

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58251873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档