Xamarin 便携式库 PCL 预处理器平台
Xamarin Portable Library PCL Preprocessor Platform
我正在尝试为跨平台创建和使用 de Portable 库 Xamarin.Forms。但是当我插入代码时,平台的预处理器似乎没有设置。
#if WINDOWS_PHONE || __ANDROID__
Debug.WriteLine("Passed");
#endif
逐步使用我可以看到预处理器条件之间的所有代码都被跳过(在 Android 和 Windows Phone 上尝试过)。但是当我在开始项目中尝试同样的事情时,它起作用了。
在 Visual Studio 中,代码在激活时应该突出显示,但它不在 PCL 中。
启动项目中定义的预处理器应该与库共享,不是吗?
PCL 这样不行。
试试这个:
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");
这里 (https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/)
您可以找到相应的 Xamarin 文章。你要做的是
共享资产方法而不是 PCL 方法。
我正在尝试为跨平台创建和使用 de Portable 库 Xamarin.Forms。但是当我插入代码时,平台的预处理器似乎没有设置。
#if WINDOWS_PHONE || __ANDROID__
Debug.WriteLine("Passed");
#endif
逐步使用我可以看到预处理器条件之间的所有代码都被跳过(在 Android 和 Windows Phone 上尝试过)。但是当我在开始项目中尝试同样的事情时,它起作用了。
在 Visual Studio 中,代码在激活时应该突出显示,但它不在 PCL 中。
启动项目中定义的预处理器应该与库共享,不是吗?
PCL 这样不行。 试试这个:
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");
这里 (https://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/) 您可以找到相应的 Xamarin 文章。你要做的是 共享资产方法而不是 PCL 方法。