.Net编译时出现无法解决"xxx"之间的冲突

栏目: ASP.NET · 发布时间: 5年前

内容简介:今天遇到一个非常风骚的问题。我们老老实实的编译asp.net mvc项目,只是从nuget引入了阿里的两个sdk包,没有改任何配置的前提下,生成项目会报如下警告:作为一个非专业的程序员,对warning还做不到视而不见,于是着手解决这个问题。

今天遇到一个非常风骚的问题。

我们老老实实的编译asp.net mvc项目,只是从nuget引入了阿里的两个sdk包,没有改任何配置的前提下,生成项目会报如下警告:

6>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3243: 无法解决“System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”与“System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”之间的冲突。正在随意选择“System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”。
6>  请考虑使用 app.config 将程序集“System.Net.Http, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”从版本“4.0.0.0”[C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\System.Net.Http.dll]重新映射到版本“4.2.0.0”[C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net471\lib\System.Net.Http.dll],以解决冲突并消除警告。

作为一个非专业的程序员,对warning还做不到视而不见,于是着手解决这个问题。

然后随手必应一下,随手贴上了一段

<dependentAssembly>
  <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

小手一敲,依旧警告。

难道文档是错的?但是看其他人的文章,都说这样可以解决,难道我用了个假的.net framework?

经过一顿操作,输出改成详细模式,终于找到了一点点蛛丝马迹:这个4.2.0.0版本的dll存在一个叫Microsoft.NET.Build.Extensions的文件夹,而编译的时候仿佛引入了Microsoft.NET.Build.Extensions文件夹里的一个targets文件。

3>来自项目“xxx”的文件“C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.NETFramework.targets”中的目标“ImplicitlyExpandNETStandardFacades”(目标“ResolveAssemblyReferences”依赖于它):
3>正在使用程序集“C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\\tools\net46\Microsoft.NET.Build.Extensions.Tasks.dll”中的“GetDependsOnNETStandard”任务。
3>任务“GetDependsOnNETStandard”
3>已完成执行任务“GetDependsOnNETStandard”的操作。

看起来问题解决了一部分,项目自动引入了一个.net standard的类库,导致冲突。

但是我也没引入这东西啊,csproj里也没配置ImplicitlyExpandNETStandardFacades相关的东西,所以打开targets看下里面是什么东西:

<PropertyGroup>
  <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>

  <!-- Add NETStandard references if targetframeworkversion supports netstandard2.0 (net461 or later) -->
  <ImplicitlyExpandNETStandardFacades Condition="'$(ImplicitlyExpandNETStandardFacades)' == '' AND '$(_TargetFrameworkVersionWithoutV)' >= '4.6.1'">true</ImplicitlyExpandNETStandardFacades>
</PropertyGroup>

<!-- ... -->

    <!--
      .NET 4.7.1 has support for .NET Standard 2.0 built-in, so most of the facades aren't necessary.  However, the assembly versions of a few set of assemblies
      do not yet match the ones shipped in the support package for .NET Standard 2.0 on .NET 4.7 and below. This means that .NET 4.7 or lower libraries might have
      references to higher versions of these assemblies than are available in-box in .NET 4.7, leading to assembly loading errors. So if there is a dependency on
      netstandard.dll, we include DLLs for .NET 4.7.1 from the support package to avoid these errors.
      -->
<ItemGroup Condition="'$(_TargetFrameworkVersionWithoutV)' == '4.7.1'">
  <_NETStandardLibraryNETFrameworkLib Include="$(MSBuildThisFileDirectory)\net471\lib\*.dll" Condition="'$(DependsOnNETStandard)' == 'true'"/>
</ItemGroup>

你妈的,神经病啊。在项目文件csproj的第一个PropertyGroup中添加

<ImplicitlyExpandNETStandardFacades>false</ImplicitlyExpandNETStandardFacades>

编译通过,运行正常,以后出问题再说。

这个问题应该只会出现在现在这个Framework到core的过渡期,先凑合着来吧。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Convergence Culture

Convergence Culture

Henry Jenkins / NYU Press / 2006-08-01 / USD 30.00

"Convergence Culture" maps a new territory: where old and new media intersect, where grassroots and corporate media collide, where the power of the media producer, and the power of the consumer intera......一起来看看 《Convergence Culture》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具