简体   繁体   English

Xamarin便携式库PCL预处理程序平台

[英]Xamarin Portable Library PCL Preprocessor Platform

I'm trying to create and use de Portable library for a cross platform Xamarin.Forms. 我正在尝试为跨平台Xamarin.Forms创建和使用de Portable库。 But the preprocessor for the platform doesn't seem set when I break in the code. 但是,当我中断代码时,似乎未设置平台的预处理器。

#if WINDOWS_PHONE || __ANDROID__
  Debug.WriteLine("Passed");
#endif

Using step by step I can see all the code between the preprocessor condition be skipped (tried on Android and Windows Phone). 通过逐步使用,我可以看到跳过预处理器条件之间的所有代码(在Android和Windows Phone上尝试过)。 But when I try the same thing in the start project it works. 但是,当我在启动项目中尝试相同的操作时,它将起作用。

In Visual Studio the code should be highlighted when active but it's not in the PCL. 在Visual Studio中,代码处于活动状态时应突出显示,但不在PCL中。

The preprocessors defined in the startup project should be shared with the library, no ? 启动项目中定义的预处理器应该与库共享,不是吗?

PCL doesn't work this way. PCL无法以这种方式工作。 Try this: 尝试这个:

using Xamarin.Forms;
...
if(Device.OS == TargetPlatform.Android)
    Debug.WriteLine("I'm on Android");
else if(Device.OS == TargetPlatform.iOS)
    Debug.WriteLine("This is iOS");

Here ( https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/ ) you can find the appropriate Xamarin article. 您可以在此处( https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/ )找到合适的Xamarin文章。 What you are trying to do is Shared Assets approach and not PCL approach. 您尝试做的是共享资产方法而不是PCL方法。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM