简体   繁体   English

如何将Windows Universal App迁移到Portable Library Project?

[英]How to migrate a Windows Universal App to Portable Library Project?

I have previously developed a Windows Universal App. 我以前已经开发了Windows Universal App。 I would like to migrate all the non-platform specific code to place in a portable class library project for further development.How to achieve this? 我想将所有非平台特定的代码迁移到可移植类库项目中,以进行进一步的开发。如何实现此目标?

In the Windows Universal App there are some backend C# code controlling UI contents and manipulate the data as well. 在Windows Universal App中,有一些后端C#代码可控制UI内容并处理数据。 I may not able to seperate the non-platform specific code nicely. 我可能无法很好地分隔非平台特定的代码。 Can I still migrate to PCL project in this case? 在这种情况下,我仍然可以迁移到PCL项目吗?

I searched on the portable class library documentation as the link below: https://msdn.microsoft.com/library/gg597391.aspx 我在便携式类库文档中搜索了以下链接: https : //msdn.microsoft.com/library/gg597391.aspx

可移植类库文档

The description looks confusing. 该描述令人困惑。 Does it mean that I just include my previous app package in the PCL project and then everything works? 这是否意味着我只将以前的应用程序包包含在PCL项目中,然后一切正常?

You will need to extract the platform specific code. 您将需要提取平台特定的代码。 The docs you quote go in the other direction: the PCL is included in the appx package, not the app package in the PCL. 您引用的文档朝另一个方向:PCL包含在appx包中,而不是PCL中的应用包。

Depending on how entrenched the platform specific code is you may be able to separate it out via inversion of control: define an interface the PCL can use to call back into the host to acquire platform specific data which the PCL can then manipulate. 取决于特定于平台的代码的牢固程度,您可以通过控制反转将其分离:定义PCL可用于回调到主机的接口,以获取PCL随后可以操作的平台特定数据。

For example, if the current code has platform specific code to open a file and get its contents, the PCL could call a funtion in the host which opens a file and returns a stream to the contents. 例如,如果当前代码具有特定于平台的代码来打开文件并获取其内容,则PCL可以在主机中调用一个函数,该函数打开文件并向内容返回流。

How to Migrate 如何迁移

Unless you changed your question title to "how can I move platform independent portion of my code to PCL", I believe no others can easily understand your meaning. 除非您将问题标题更改为“如何将代码的平台无关部分移至PCL”,否则我相信没有其他人可以轻易理解您的意思。

I assume that you already have a Windows Universal app project in Visual Studio. 我假设您已经在Visual Studio中拥有Windows Universal应用程序项目。 Then to move code to PCL, 然后将代码移至PCL,

  1. Simply create an empty PCL project (choose a proper profile), and add it as a reference to your original Windows Universal app project. 只需创建一个空的PCL项目(​​选择适当的配置文件),并将其添加为对原始Windows Universal应用程序项目的引用。
  2. Cut (not copy) and paste some source files from your app project to this PCL project. 剪切(而非复制)并将一些源文件从您的应用程序项目粘贴到此PCL项目中。
  3. Compile the solution and fix issues. 编译解决方案并解决问题。

If you don't know what is a PCL profile, read MSDN related materials. 如果您不知道什么是PCL配置文件,请阅读MSDN相关材料。 If you don't know which source files should go to PCL, and which should remain in app project, do experiments or check out other guys' sample project. 如果您不知道哪些源文件应该转到PCL,哪些源文件应该保留在应用程序项目中,请进行实验或查看其他人的示例项目。

About The Confusion You Got 关于您的困惑

I can only say to understand what you highlighted, you should read carefully what is not highlighted in the same sentence, and the subtitle. 我只能说要了解您突出显示的内容,您应该仔细阅读同一句子中未突出显示的内容以及副标题。

Clearly when you have a PCL project, and a Windows Store/Phone app project that references the PCL, when you generate the deployment package (.appx) in Visual Studio, the final package will include every needed assemblies. 显然,当您拥有PCL项目以及引用PCL的Windows应用商店/电话应用程序项目时,在Visual Studio中生成部署程序包(.appx)时,最终程序包将包括每个所需的程序集。

It obviously isn't what you described. 显然不是您所描述的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Universal App便携式库中的颜色? - Colors in a Universal App portable library? Windows XAML通用便携式库中的Windows Phone API在哪里? - Where are the Windows Phone APIs in Windows XAML Universal Portable Library? 在Windows Phone项目中使用可移植类库 - Use portable class library in windows phone project 将SQLite Windows窗体应用程序迁移到通用Windows应用程序(C#) - Migrate SQLite windows forms app to universal windows app (C#) Windows Universal / Store App中的类库本地化 - Class Library Localization in Windows Universal / Store App Netcore库与通用Windows应用程序及其他应用程序的兼容性 - Netcore library compatibility with universal windows app and others Windows Universal App的Active Directory身份验证库 - Active Directory Authentication Library with Windows Universal App 通用Windows应用程序项目中的MSBuild错误 - MSBuild error in Universal Windows app project Windows通用应用程序(运行时)中的Silverlight项目 - Silverlight project in Windows universal app (Runtime) 如何将现有的C#项目导入可移植类库,并使用它引用Visual Studio中的android应用? - How to import your existing C# project into a portable class library and use it to reference to android app in visual studios?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM