WinJS are there #DEBUG or #RELEASE directives?

萝らか妹 提交于 2020-02-06 06:48:20

问题


I would like to exclude some code when using release vs debug. Basically I have an internal admin section for testing that I don't to ever make it into the app store by accident :)

Ideally, I would just be able to do something like this:

#IF DEBUG
    <div id="appBar" data-win-control="WinJS.UI.AppBar">
        <button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'cmdAdmin', label:'Admin', section:'global' }">
        </button>
    </div>
#ENDIF

回答1:


See here. There is a nuget package here to enable it without adding the code to your project directly. After you have it then you just do:

<script src="/js/debugSymbols.js"></script> 

if (Debug.isDebugBuild) {

Here is the full code that you don't need if you use the nuget package:

(function () {     
   "use strict";
   if (Debug.hasOwnProperty("isDebugBuild")) {
     return;
   }
   var thisPackage = Windows.ApplicationModel.Package.current,
            installedPath = thisPackage.installedLocation.path;
   if (typeof installedPath === "string") {

       if (installedPath.match(/\\debug\\appx$/i)) {

           Object.defineProperty(Debug, "isDebugBuild", {
              get: function () {
                 return true;
              }
           });
       }
   }
})(); 



回答2:


I have been researching about it, I found the following (which is based on configuration manager in your VS solution)

  • keeping different files per configuration in your VS solution. http://www.kraigbrockschmidt.com/2014/02/25/differentiate-debug-release-builds-javascript/

Moreover I am considering to use MSBuild tasks (or MSBuild Inline Tasks) to replace text in specific file based on the current configuration (e.g. DEBUG, RELEASE). This should happen in the beforeBuild event. This may also work for setting specific values based on deployment.

Cheers, Herb



来源:https://stackoverflow.com/questions/13703378/winjs-are-there-debug-or-release-directives

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!