简体   繁体   English

将.net类库移植到Windows应用商店类库

[英]Porting A .net Class Library To Windows Store Apps Class Library

I have a class library that targets .net 4 and is used across different platforms via Mono. 我有一个以.net 4为目标的类库,通过Mono在不同的平台上使用。 I now want to port it to be used by Windows 8. I know the name keeps changing but this is currently called a "Class Library (Windows Store Apps)" in VS2012. 我现在想将它移植到Windows 8使用。我知道名称不断变化,但这在VS2012中目前称为“类库(Windows应用商店应用)”。
I initially started with trying to port everything to a "Portable Class Library" but this was proving too difficult as some things simply didn't have a generic approach that would work on all platforms targeted, and other things that were supported simply weren't available to the compiler. 我最初开始尝试将所有内容移植到“可移植类库”中,但事实证明这太难了,因为有些东西根本就没有适用于所有目标平台的通用方法,而其他支持的东西根本就没有可供编译器使用。
So I've created a Windows Store Class Library and created links to the existing files of my standard Class Library so updating once will update both. 因此,我创建了一个Windows应用商店类库,并创建了指向我标准类库的现有文件的链接,因此更新一次将更新两者。 I am planning on using pre-processing directives to make changes between the two class libraries EG 我打算使用预处理指令在两个类库EG之间进行更改

#if NETFX_CORE
    Task.Delay(someTime);
#else
    new System.Threading.ManualResetEvent(false).WaitOne(sometime);
#endif

My question is if this method seems a sensible approach? 我的问题是,这种方法似乎是一种明智的做法吗? I have the same default namespace and assembly name. 我有相同的默认命名空间和程序集名称。 Could this ever cause issues to my compiler? 这会不会给我的编译器带来问题? The assemblies target different platforms so would never be used together in the same application but do both sit in the same solution in Visual Studio. 程序集针对不同的平台,因此永远不会在同一个应用程序中一起使用,但两者都在Visual Studio中使用相同的解决方案。

Overall, yes that should work. 总的来说,是的,这应该工作。 That specific case is a poor example, because the two implementations function very differently, illustrating that you may need to rethink some aspects of your design. 这个特定情况很糟糕,因为这两个实现的功能完全不同,说明您可能需要重新考虑设计的某些方面。 For cases where there is a similar API swap (with similar semantics), I personally tend to move the difference behind a helper method, so my "main" code doesn't need to worry about this - just the helper code. 对于其中一个类似的API交换(具有类似的语义)的情况下,我个人倾向于移动后面的helper方法的差异,所以我的“主”的代码并不需要担心这个-只是助手代码。 Reflection would be a good example of this (the changes to reflection are annoyingly deep). 反思就是一个很好的例子(反思的变化令人讨厌地深刻)。

The two projects with different target platforms should be fine. 具有不同目标平台的两个项目应该没问题。 I occasionally hit an IDE glitch where it complains about temp files. 我偶尔会遇到一个抱怨临时文件的IDE故障。 I think this is due to sharing files between projects. 我认为这是由于项目之间共享文件。 I've logged it on connect 我已经在连接上登录了

尝试

Task.Delay(msDelay).Wait()

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

相关问题 面向.NET4.5,SL和Windows Store应用的MEF for Portable Library Class - MEF for Portable Library Class targeting .NET4.5, SL and Windows Store apps 将HttpModule .Net类库移植到.Net Core Web API - Porting HttpModule .Net Class Library to .Net Core Web API Windows Universal / Store App中的类库本地化 - Class Library Localization in Windows Universal / Store App 从类库(Windows)引用.NET Core类库 - Referencing .NET Core Class Library from Class Library (Windows) Windows应用商店:通过反射从customcontrol类库加载样式,未调用OnApplyTemplate吗? - Windows Store Apps : Loading styles from a customcontrol class library via reflection, OnApplyTemplate is not called? 是否可以在面向Windows Phone 8和.NET for Windows Store的可移植类库中使用System.Windows.Visibility? - Is it possible to use System.Windows.Visibility in a portable class library targeting Windows Phone 8 and .NET for Windows Store? 从Windows类库引用.NET标准库 - Referencing a .NET Standard library from a Windows Class Library Silverlight类库到Windows phone 7类库 - Silverlight class library to Windows phone 7 class library .NET CLI的类库 - Class Library with .NET CLI .net mvc 与类库 - .net mvc with class library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM