WinJS有#DEBUG还是#RELEASE指令?

时间:2012-12-04 12:52:32

标签: windows-8 winjs

我想在使用release vs debug时排除一些代码。基本上我有一个内部管理部分用于测试,我不会偶然进入应用程序商店:)

理想情况下,我只能做这样的事情:

#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

2 个答案:

答案 0 :(得分:2)

here。有一个nuget包here可以启用它而无需直接将代码添加到项目中。在你拥有它之后你就​​可以了:

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

if (Debug.isDebugBuild) {

以下是使用nuget包时不需要的完整代码:

(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;
              }
           });
       }
   }
})(); 

答案 1 :(得分:1)

我一直在研究它,我发现以下内容(基于VS解决方案中的配置管理器)

此外,我正在考虑使用MSBuild任务(或MSBuild内联任务)根据当前配置(例如DEBUG,RELEASE)替换特定文件中的文本。这应该发生在beforeBuild事件中。这也可以用于根据部署设置特定值。

干杯, 草本植物