【发布时间】:2017-06-25 18:43:36
【问题描述】:
我将一个类库项目迁移到 .Netstandard1.4,其中包含一个 nuget 包 System.Net.Http" Version="4.3.2"
xml .cproj 描述如下:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.2" />
</ItemGroup>
</Project>
我的单元测试(使用 Nunit 2.4.6 版本)仍然是一个类库项目(.net 4.6.1)(无需迁移)并引用 myStandard1.4 库并编译成功。
我正在使用带有 Resharper 的 vs 2017。
当我尝试运行单元测试时,会触发异常:
System.IO.FileNotFoundException : Could not load file or assembly 'System.Net.Http, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
注意它说的是“System.Net.Http, Version=4.1.1.1”而不是 NetStandard1.4 库中使用的版本“4.3.2”。
我不得不修改 .NetStandard 项目以通过添加 net461 来支持多目标,异常消失并且工作正常:
<TargetFrameworks>netstandard1.4;net461</TargetFrameworks>
我的问题:
Q1:为什么异常要求“System.Net.Http,Version=4.1.1.1”而不是我在 NetStandard1.4 中使用的版本“4.3.2”?
Q2:尽管.NET platforms support for .netstandard1.4 支持net461,为什么添加多目标net461 解决了问题?
Q3:我是否必须将我的单元测试类库项目迁移到其他类型?这是什么类型的?
【问题讨论】:
标签: c# nunit resharper .net-standard