If NETFX_CORE is for Windows 8, what is for Windows Phone 8?
Asked Answered
N

4

6

I understand using the NETFX_CORE directive, like this:

#if NETFX_CORE 
    // Windows 8
#else 
    // Windows Phone 8
#endif

More info: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj714084(v=vs.105).aspx

But is there a directive specific to Windows Phone 8?

Neoplasticism answered 27/11, 2012 at 22:38 Comment(2)
The link is for .NET development, but the question wasn't tagged either way. Am I right this is primarily about .NET? Native development will have different defines.Gigolo
Um, NETFX_CORE sort of implies the tech, sorry if you missed that.Neoplasticism
J
9

Yes, the Windows Phone directive is:

#if WINDOWS_PHONE

This is documented here, but I'm surprised that it isn't mentioned here. I also tested this in some code, and it works.

Jeanmariejeanna answered 28/11, 2012 at 4:3 Comment(1)
And for projects targeting Windows 8.1 and Windows Phone 8.1 these will be WINDOWS_APP and WINDOWS_PHONE_APP.News
C
4

WP8 should use custom conditional compilation flags introduced by the developer. Read more about this exact topic here. Nokia has an entire article dedicated to coding for both WP7 and WP8 and I highly recommend you go over all techniques to see what's the best one for you to use.

Defining conditional compilation symbol:

  1. Right click on the WP 8 project and select Properties. Open up the
  2. Build page of Project Designer and insert WP8 into Conditional compilation symbols. After this, they should contain something like this: SILVERLIGHT;WINDOWS_PHONE;WP8

And here's the inline code sample

// Separate implementations for different OS versions
#if WP8
    // code using enhancements introduced in Windows Phone 8 
#else
    // code using Windows Phone OS 7.1 features 
#endif


// A new Windows Phone 8 feature
#if WP8
    // code using new Windows Phone 8 feature
#endif 
Cangue answered 29/11, 2012 at 1:53 Comment(2)
can you please help me i have same issue #22094643Devitalize
Do you mean #UNITY_WP8 or is WP8 different? If you meant UNITY_WP8 then this is incorrect as it should be WINDOWS_PHONE: forum.unity3d.com/threads/…Molality
K
1

As far I know, there is not such directive. But you can use if not :

#if !NETFX_CORE 
    // Windows Phone 8
#endif
Kellum answered 27/11, 2012 at 22:43 Comment(1)
Haha! Not exactly what I meant, but that's funny.Neoplasticism
R
0

But is there a directive specific to Windows Phone 8?

You can define your own preprocessor directives you know. WINDOWS_PHONE just happens to be defined by the Visual Studio project templates for Windows Phone projects.

Same goes for DEBUG, TRACE and whatever custom ones you might have like EXTENSIVE_LOGGING or LOOKING_FOR_A_CATBUS

Rubeola answered 28/11, 2012 at 4:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.