如何在VS11中为javascript metro应用程序创建预构建步骤? [英] How do I create a pre-build step for a javascript metro app in VS11?
问题描述
我想在每次构建之前运行一些自定义批处理代码。在VS< 11 / C#应用程序中,我可以在项目设置中设置预构建事件。我在javascript metro VS11解决方案中找不到类似的设置。
I want to run some custom batch code just before every build. In a VS<11/C# app I could set the pre-build events in the project settings. I can't find similar settings in a javascript metro VS11 solution.
任何人都知道它在哪里,或者选项是否已经消失(!)我可以使用哪种解决方法在它的位置吗?
Anyone know where it is, or if the option is gone (!) what kind of workaround I can do in its place?
推荐答案
您可以使用Visual Studio .jsproj文件中的BeforeBuild目标来完成此任务:
You can use the BeforeBuild target in the Visual Studio .jsproj file to accomplish this:
<Target Name="BeforeBuild"></Target>
<Target Name="AfterBuild"></Target>
到达这里:
- 在Visual Studio中右键单击项目,然后在Windows资源管理器中选择打开文件夹
- 在资源管理器中,右键单击.jsproj文件并选择打开方式...并选择像记事本这样的编辑器
- 滚动到文件的底部,你会注意到这两个Target部分被注释掉了
取消注释BeforeBuild目标并在其中添加自定义步骤。您可以使用该元素执行命令行脚本;可以使用与C#预构建步骤相同的$变量(例如$(ProjectDir))。除了在目标中调用命令行脚本之外,您可以做更多的事情,但这与您通常使用C#预构建步骤进行的操作最接近。
Uncomment the BeforeBuild target and add your custom step inside of it. You can use the element to execute a command line script; the same $ variables are available as in C# pre-build steps (e.g. $(ProjectDir)). You can do more than call command line scripts in a Target, but this is closest to what you would normally do with C# pre-build steps.
作为示例,下面的代码将调用一个名为processFile.bat的批处理文件,在项目根目录中传递一个default.js的路径,并在项目的输出目录中创建一个名为output.js的文件的输出路径(例如/ bin / Debug in Debug模式) :
As an example, the following code would call a batch file named processFile.bat passing it a path to default.js in the project root and an output path to create a file named output.js in the project's output directory (e.g. /bin/Debug in Debug mode):
<Target Name="BeforeBuild">
<Exec Command="processFile.bat "$(ProjectDir)default.js" "$(OutDir)output.js"">
</Target>
注意:& quot;在Command参数内部有用,这可以确保在传递给processFile.bat并通过cmd.exe调用时引用这两个参数。
Note: The " is on purpose inside of the Command arguments, this makes sure the two parameters are quoted when passed to processFile.bat and called via cmd.exe.
这篇关于如何在VS11中为javascript metro应用程序创建预构建步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!