[英]How do I convert a PCL to a .Net Standard library
So I have a PCL project but would like to now update it to support .Net Standard所以我有一个 PCL 项目,但现在想更新它以支持 .Net Standard
I have read on the Microsoft website steps to do this:我已在Microsoft 网站上阅读了执行此操作的步骤:
- Right-click on the project file and select Properties.右键单击项目文件并选择属性。
- Under Library, select Target .NET Platform Standard.在库下,选择目标 .NET 平台标准。
But this button does not exist in the latest version of Visual Studio 2017.但是这个按钮在最新版本的 Visual Studio 2017 中不存在。
I have also read here :我也在这里阅读过:
- Close the solution in VS关闭VS中的解决方案
- Take the existing csproj and make a copy of it somewhere else.使用现有的 csproj 并在其他地方复制它。 I'll keep this other copy open in Notepad.我会在记事本中保持另一个副本打开。
- Copy/paste the contents of the new project you created and replace the contents of your existing project.复制/粘贴您创建的新项目的内容并替换现有项目的内容。 Most of what you had in the old project isn't really needed anymore.您在旧项目中拥有的大部分内容都不再需要了。 What you'll likely need are settings like any signing or assembly names that don't match the folder name/conventions.您可能需要的是任何与文件夹名称/约定不匹配的签名或程序集名称等设置。 If you have ResX files with design-time generated code, you'll need to add the following.如果您有带有设计时生成代码的 ResX 文件,则需要添加以下内容。 Likewise, for Xamarin Forms pages, you'll need this.同样,对于 Xamarin Forms 页面,您将需要它。
But I don't understand the steps highlighted above as I have loads of nuget packages and ResX files so always causes build errors when I try但是我不明白上面突出显示的步骤,因为我有大量的 nuget 包和 ResX 文件,所以在我尝试时总是会导致构建错误
So are there any straight forward steps to updating a PCL project to a .NetStandrard one?那么是否有任何直接的步骤可以将 PCL 项目更新为 .NetStandrard 项目?
在我看来,最好的方法是从头开始创建一个新项目(.net 标准)并将所有内容复制到那里......这里有一些帮助: https : //blog.xamarin.com/building-xamarin-forms -应用程序网络标准/
The steps I took to convert a PCL to a .Net Standard library used some steps from here mixed with my own:我将 PCL 转换为 .Net Standard 库的步骤使用了这里的一些步骤与我自己的步骤:
packages.config
way to PackageReference
将所有 nuget 包从旧的packages.config
方式转换为PackageReference
Unfortunately there's no current migration tool, so it's probably easiest to uninstall your existing packages, make sure the packages.config file is gone and then install the package after setting the VS Options to PackageReference.不幸的是,目前没有迁移工具,因此卸载现有包可能是最简单的,确保packages.config 文件已消失,然后在将VS 选项设置为PackageReference 后安装包。 You can also do it by hand (which is what I did for my projects).您也可以手动完成(这是我为我的项目所做的)。
Create a New .Net Standard class library in your project, call it something similar like MyPclProject1在您的项目中创建一个新的 .Net Standard 类库,将其命名为类似 MyPclProject1
Drag and drop all files from old PCL lib to .Net Stanrdard lib将旧 PCL 库中的所有文件拖放到 .Net 标准库中
Open old PCL .csproj file in Notepad and copy and paste all the PackageReference
code into the new .Net Standard csproj file在记事本中打开旧的 PCL .csproj 文件并将所有PackageReference
代码复制并粘贴到新的 .Net Standard csproj 文件中
If you use .resx files you need to add this code to your .Net Standard .Csproj file (not sure why)如果您使用 .resx 文件,您需要将此代码添加到您的 .Net Standard .Csproj 文件中(不知道为什么)
then update all the references from the old pcl file to the new .Net Standard file and remove the old library然后将旧 pcl 文件中的所有引用更新到新的 .Net Standard 文件并删除旧库
rename your new .NEt Standard lib to the old pcl name将新的 .NEt Standard lib 重命名为旧的 pcl 名称
Based on the blog post from James Montemagno about How to Convert a Portable Class Library to .NET Standard and Keep Git History :基于James Montemagno关于如何将可移植类库转换为 .NET Standard 并保留 Git 历史记录的博客文章:
Delete Everything in the csproj and insert this:删除 csproj 中的所有内容并插入:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <!--<PackageReference Include="" Version=""/>--> </ItemGroup> </Project>
Add back NuGets (simply open packages.config, and add the package references above, or via the NuGet package manager.添加回 NuGet(只需打开 packages.config,然后添加上面的包引用,或通过 NuGet 包管理器。
Today there are many guides available (eg likethis one ), but they are basically the same (except some project specific peculiarities. And what I read is that you need VS 2017 at least for this.今天有很多可用的指南(例如像这个),但它们基本相同(除了一些项目特定的特性。我读到的是,你至少需要 VS 2017 来实现这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.