如果它使用全框架库,将代码从 Windows Store app 移出 DLL?

Move code to DLL out of Windows Store app if it uses full-framework library?

我在 .Net 4.5 上创建了 Windows Store 应用程序,它使用 AngleSharp 0.8.5,HTML 解析器引擎。我的项目包含许多我将在另一个应用程序中使用的代码文件,所以我决定将这些代码移动到 PCL 库中,以单独的项目。

但是我无法将 AngleSharp DLL 从 NuGet 系统添加到我的 PCL 项目中,正如它所说:

Could not install package 'AngleSharp 0.8.5'. You are trying to install this package into a project that targets 'portable-win+net45+sl40+wp', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

我尝试手动将 AngleSharp DLL 添加到项目中,但是如果我尝试构建我的 PCL 项目,我会收到这样的警告:

Warning 2 The primary reference "AngleSharp" could not be resolved because it was built against the ".NETPortable,Version=v4.5,Profile=Profile259" framework. This is a higher version than the currently targeted framework ".NETPortable,Version=v4.0,Profile=Profile4". prototypeLibrary

还有这个

The primary reference "AngleSharp" could not be resolved because it has an indirect dependency on the framework assembly "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile4". To resolve this problem, either remove the reference "AngleSharp" or retarget your application to a framework version which contains "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". prototypeLibrary

我也尝试创建一个普通的 Class 库项目并将我的代码移到那里,但我无法从我的 Windows 商店应用程序添加对它的引用。

如果我需要将一些代码移出 Windows 存储可执行文件并重新使用,我该怎么办?

根据警告 2,您已经创建了一个配置文件 4 PCL 库,它被认为是一个遗留配置文件VS 2013 及更高版本不支持。配置文件 4 的目标是 .NET 4.5、Silverlight 4、Windows 8 和 Windows Phone 7。A​​ngleSharp 与 SL4 和 WP7 都不兼容,所以这个PCL 配置文件不是一个可行的选项。

为了最大程度地兼容 A​​ngleSharp,我建议您切换到 PCL 配置文件 259,它的目标是:

  • .NET 4.5
  • Windows 8
  • Windows Phone 8.1
  • Windows Phone 银光 8
  • Xamarin Android
  • Xamarin iOS 经典和统一 API

如果切换到此 PCL 配置文件,从 Windows 商店应用程序引用便携式 class 库应该没有问题。