Dotnet Core 简明教程

.NET Core - PCL Troubleshooting

在本章中,我们将修复在 Xamarin.Forms 项目中从我们的专用馈送安装 NuGet 程序包时遇到的错误。

In this chapter, we will be fixing the error we got while installing the NuGet package from our private feed in Xamarin.Forms project.

fixing error

我们将进一步简要了解问题。首先,让我们右键单击 PCL 库并选择“属性”。

We will further understand the problem in brief. To start with, let us right-click on the PCL library and select Properties.

在此页面上,您将看到所有目标框架系列。从错误中,您会看到 .NETPortable 配置文件 259 与我们的 StringLibrary 1.0.1 不兼容。但是,它试图从 .NET Standard 1.1 库获取引用。

On this page, you will see the whole series of frameworks targeted. From the error, you can see that the .NETPortable profile 259 is not compatible with our StringLibrary 1.0.1. However, it is trying to take reference from the .NET Standard 1.1 library.

compatible

现在让我们查看 .NET Standard 库并确定哪个平台与我们的库不兼容。

Let us now see the .NET Standard Library and identify which platform is not compatible with our library.

platform

您可以看到 Windows Phone Silverlight 8 与 .NET Standard 1.0 兼容。如果您打开以下网页,您将看到 Profile259 只能支持 .NET Standard 1.0。

You can see that Windows Phone Silverlight 8 is compatible with .NET Standard 1.0. If you open the following webpage, then you will see that Profile259 can support only .NET Standard 1.0.

profile259

现在让我们取消选中 Windows Phone Silverlight 8。

Let us now uncheck Windows Phone Silverlight 8.

silverlight

单击 OK 按钮。

Click the OK button.

ok button

现在,要修复此问题,请点按“确定”,取消“更改目标”对话框,然后打开程序包管理器控制台,并执行以下命令。

Now to fix this issue click OK and cancel the Change Targets dialog and then open Package Manager Console and execute the following command.

PM > Uninstall-Package Xamarin.Forms
execute command

现在让我们转到 PCL 库的“属性”。点按“更改”按钮。

Let us now go to the Properties of PCL library. Click on the Change button.

pcl library

取消选中 Windows Phone Silverlight 8,然后点按“确定”。

Uncheck Windows Phone Silverlight 8 and Click OK.

uncheck

您现在可以看到,Windows Phone Silverlight 8 不再出现在“目标框架”中了。您还可以看到当前目标的配置文件。要看到此内容,让我们卸载 PCL 库并编辑 XamarinApp.csproj 文件。

You can now see that Windows Phone Silverlight 8 is no longer available in Targeted framework. You can also see the profile that is the target now. To see this, let us unload the PCL library and edit the XamarinApp.csproj file.

unload

您现在可以看到,TargetFrameworkProfile 现在是 Profile111。

You can see now that TargetFrameworkProfile is now Profile111.

targetframeworkprofile

如果您打开文档,您将看到 Profile111 支持 .NET Standard 1.1。

If you open the documentation, then you will see that Profile111 is supporting .NET Standard 1.1.

documentation

现在,让我们重新加载 PCL 并打开 NuGet 程序包管理器,然后尝试从专用馈送安装 StringLibrary 程序包。

Let us now reload the PCL again and open the NuGet Package Manager and try to install the StringLibrary package from private feed.

package private feed

从“依赖关系行为”下拉列表中,选择“忽略依赖关系”,然后点按 Install

From the Dependency behavior dropdown list, select Ignore Dependencies and then click Install.

dependencies

您可看到 StringLibrary 包已从专用源进行安装。如果您展开 PCL 的引用,您将看到 StringLibrary 引用也按以下所示添加进来。

You can see that the StringLibrary package is now installed from the private feed. If you expand the References of PCL, then you will see that the StringLibrary reference is also added as shown below.

pcl reference

我们已针对 Windows Phone Silverlight 8 问题卸载了 Xamarin.Forms。需要重新安装 Xamarin.Forms。建议安装相同版本。

We had uninstalled the Xamarin.Forms for the Windows Phone Silverlight 8 issue. The Xamarin.Forms needs to be installed again. It is recommended that the same version is installed.

same version

一旦完成安装,让我们在您的应用程序中使用 StringLibrary 功能。

Once the installation completes, let us use the StringLibrary functionality in your application.