在 Windows 8 Metro Javascript 应用程序中构建特定的条件符号?

发布于 2024-12-29 06:04:30 字数 178 浏览 3 评论 0原文

在 C++ 和 C# 应用程序中,可以定义条件编译符号,例如 DEBUG、TRACE 或 RELEASE,并在程序代码中使用这些符号来通过 #if 启用/禁用代码生成。

我需要在 Windows 8 Metro Javascript 应用程序中执行类似的操作:不同的版本(调试/发布)的行为略有不同。这是否以某种方式得到支持?

In C++ and C# applications one can define conditional compilation symbols, such as DEBUG, TRACE or RELEASE and use these in program code to enable/disable code generation with #if.

I need to do similar thing in a Windows 8 Metro Javascript application: have different builds (Debug/Release) behave slightly differently. Is this supported somehow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔芯 2025-01-05 06:04:30

在 Windows 8 开发人员预览版中,Visual Studio for Metro Style JavaScript 应用程序没有 JavaScriot 的预处理,也没有编译步骤。但是,您可以通过 MSBuild 插入您自己的预处理器(或重用 C 预处理器)。您只需编辑 .wwaproj 文件并添加调用预处理器的目标即可。

  <Target Name="BeforeBuild">
  </Target>

网上有几篇很好的文章*,可以在 Visual Studio 中缩小 JavaScript 来执行类似的操作,这与您的要求非常相似。
* http://amusedia.blogspot.com/2010/ 11/最小化-javascript-and-css-with.html

In the Windows 8 Developer Preview, Visual Studio for Metro Style JavaScript applications there is no pre-processing of JavaScriot nor is there a compilation step. However, you can via MSBuild plug in your own pre-processor (or reuse the C one). You can just edit the .wwaproj file and add target that invokes your pre-processor.

  <Target Name="BeforeBuild">
  </Target>

There are a couple of good articles* online for doing a similar thing with minifying JavaScript in Visual Studio which is very similar to your requirements.
* http://amusedia.blogspot.com/2010/11/minimize-javascript-and-css-with.html

歌入人心 2025-01-05 06:04:30

我找到了一种确定构建配置名称的方法。这可能不是最稳定的方法,但至少它在开发者预览版中有效。该字符串似乎

Windows.ApplicationModel.Package.current.installedLocation.folderRelativeId 

包含构建配置名称作为子字符串(例如“.Debug.”)。然后,我们可以在运行时使用此信息根据构建配置名称执行不同的操作。

I've found a way to determine the build configuration name. This might not be the most stable way of doing it but at least it works in the Developer Preview. It seems the string

Windows.ApplicationModel.Package.current.installedLocation.folderRelativeId 

contains the build configuration name as a substring (e.g. ".Debug."). One can then use this information at run-time to do different things base on build configuration name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文