locked
Conditional If

    Question

  • Can I do something like

    #if DEBUG

    var currentApp = Windows.ApplicationModel.Store.CurrentAppSimulator;

    #else

    var currentApp = Windows.ApplicationModel.Store.CurrentApp; 

    #endif


    www.emadibrahim.com

    Wednesday, October 3, 2012 11:55 PM

Answers

  • The original post was asking about a way that would not require changing the code, but would automatically detect the build target in Visual Studio.

    In C++, #ifdef DEBUG picks up a compiler flag that is determined by the build target.

    Setting a variable that still has to be changed does not accomplish that, though it can certainly isolate one place to make such a change.

    • Marked as answer by Dino He Tuesday, October 16, 2012 2:02 AM
    Monday, October 8, 2012 4:18 AM

All replies

  • No in JavaScript, so far as I know. If someone does know a way, I'd be glad to hear it.

    Lacking such, you'll need to change the object back to CurrentApp before you upload to the Store.

    Thursday, October 4, 2012 4:43 AM
  • We are working on a vastly improved project file handling for VS (which really sucks in that since Version 6). It's based on the idea that you have special file name notation like appConfig.debug.js and appConfig.release.js where you put different configs depending on the solution configuration.

    We have that already in place in the VS project files but VS chokes when switching solution configurations. Bug is open @MSFT.

    Thursday, October 4, 2012 10:48 AM
  • Are you serious?

    var DEBUG = false;

    var currentApp = DEBUG? Windows.ApplicationModel.Store.CurrentAppSimulator : Windows.ApplicationModel.Store.CurrentApp;


    Monday, October 8, 2012 3:09 AM
  • Are you serious?

    var DEBUG = false;

    var currentApp = DEBUG? Windows.ApplicationModel.Store.CurrentAppSimulator : Windows.ApplicationModel.Store.CurrentApp;

    Monday, October 8, 2012 3:09 AM
  • The original post was asking about a way that would not require changing the code, but would automatically detect the build target in Visual Studio.

    In C++, #ifdef DEBUG picks up a compiler flag that is determined by the build target.

    Setting a variable that still has to be changed does not accomplish that, though it can certainly isolate one place to make such a change.

    • Marked as answer by Dino He Tuesday, October 16, 2012 2:02 AM
    Monday, October 8, 2012 4:18 AM
  • Please don't talk down to me, Kraig.  Everyone knows what #define does.

    Maybe you didn't know this, but you can inject variables into the JS namespace from nmake.  The answer I gave him is correct.

    I did not set a variable that had to be changed, and you should learn your build tools.

    Monday, October 8, 2012 7:06 AM
  • John, you did not mention that you inject the variable DEBUG from nmake, did you? And if so, how does that work in the common IDE build scenario? Would be nice if you could share your knowledge.
    Monday, October 8, 2012 8:54 AM
  • Yes, I did not know that either and would appreciate learning more.

    And John, don't take me wrong. There are many people on this forum who are extremely new to Windows, Visual Studio, JavaScript, and just about everything else we talk about. We try to make sure questions get answered fully and not assume too much common knowledge. Accept my apologies for not knowing that about you, as you obviously have a great deal of experience beyond what many of us do. We simply ask for some courtesy in sharing that experience, because each thread here becomes a repository for others who might have the same question in the future.

    I can see from other posts that you're frustrated right with other problems you are having. I'm sorry that's the case, and I hope you resolve those issues soon.

    Monday, October 8, 2012 2:33 PM
  • John, I am interested in knowing how you inject it using nmake...  I guess I could google it and spend a couple of hours trying to figure it out...

    Another solution I thought off is to reference a c# project that defines #if DEBUG... but that's kind of a hack...


    www.emadibrahim.com

    Monday, October 8, 2012 2:38 PM
  • In any case it just shows that there is a lot that can be improved in the JS tooling chain still. Heck, VS2012 still has bugs from VS6 despite the several rewrites (non resizeable project settings dialog, startup project cannot be changed during compiling) I wonder what MS uses internally? Emacs? :)

    Monday, October 8, 2012 3:35 PM