可移植类库 - 您必须添加对程序集'System.Net,Version = 2.0.5.0的引用

时间:2013-11-12 17:57:54

标签: c# .net portable-class-library

我们有一个针对4.0的可移植类库。 WPF应用程序引用了这是一个标准的.NET 4.0应用程序。

PCL引用System.Net.NetworkCredential类。

当我们构建.NET 4.0应用程序时,我们收到错误:

The type 'System.Net.NetworkCredential' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.

有几个帖子说要安装KB2468871。这不适用/改变事情。

如果我们在应用程序中添加“System.Net 4.0.0.0”的程序集引用,则错误会发生变化:

Reference to type 'System.Net.NetworkCredential' claims it is defined in 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll', but it could not be found...

当然,NetworkCredential不在System.Net中,它位于系统程序集中。

如果我重新定位到4.5,一切正常,但我们需要使用4.0。

有什么想法吗?感谢。

1 个答案:

答案 0 :(得分:1)

KB2468871使可移植库能够在4.0上运行,它不能使它们在Visual Studio中生成。

如果添加对System.Net,4.0.0.0的引用,则第一个错误应该消失。如果没有,那么你的机器缺少必需的补丁。

如果正在使用:

Visual Studio 2010

您需要安装可移植库工具:http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/。这将安装一个可以使其工作的补丁。

Visual Studio 2012或Visual Studio 2013

这应该是开箱即用的,如果没有,那么你安装可能是一个不完整的状态。尝试修复您的安装。

相关问题