Visual Studio 中的多个预构建事件?

发布于 2024-08-06 06:57:54 字数 273 浏览 5 评论 0原文

我关注了 Scott Hanselman 的一篇博客文章 使用预构建事件管理配置 并拥有它工作正常。

我现在想将配置分成几个不同的文件,因此需要在构建之前再次执行该命令。问题是 PreBuild 事件文本全部作为一个控制台命令执行。如何将其拆分为多个命令?

I've followed a blog post by Scott Hanselman for managing configuration with PreBuild Events and have it working fine.

I now want to split up my configuration into a couple of different files, so need to exectue the command again before the build. The problem is the PreBuild event text all gets executed as one console command. How can I split it up as several commands?

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

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

发布评论

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

评论(3

我的影子我的梦 2024-08-13 06:57:54

事实证明,问题是 Scott 的示例在行开头不包含 call 命令。只要您不想使用不同的参数多次执行 .bat 文件,就可以了。

这:

call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)connectionStrings.config.$(ConfigurationName)" "$(ProjectDir)connectionStrings.config"
call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)appSettings.config.$(ConfigurationName)" "$(ProjectDir)appSettings.config"

对我来说效果很好。

Turns out the problem is Scott's example doesn't include the call command at the start of the line. This is fine as long as you don't want to execute the .bat file multiple times with different parameters.

This:

call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)connectionStrings.config.$(ConfigurationName)" "$(ProjectDir)connectionStrings.config"
call "$(ProjectDir)copyifnewer.bat" "$(ProjectDir)appSettings.config.$(ConfigurationName)" "$(ProjectDir)appSettings.config"

worked fine for me.

木格 2024-08-13 06:57:54

我在 Windows 7 64 位上使用 Visual Studio 2010。

我找到了一个更符合我喜好的解决方案,我将命令与 && 链接在一起^,例如,像这样编辑我的 .vcxproj xml 文件:

    <PreBuildEvent>
      <Command>echo "hello 1" && ^
echo "hello 2" && ^
echo "hello 3"</Command>
      <Message>Performaing pre-build actions ...</Message>
    </PreBuildEvent>

我将三个命令链接在一起。 “&&”如果前一个命令出错,则告诉 shell 停止执行。

请注意,在 .xml 文件中,不能直接使用 &&,因此 '& &amp;&amp;必须使用 amp;' 来代替。另请注意 ^ 字符的使用,这是 cmd shell 的行继续字符(如 BASH 的 \ 字符)。

每个新命令必须从行首开始。使用这种方法,人们可以根据需要链接任意数量的命令,但如果任何命令失败,则链中的其余命令将不会被执行。

例,我使用 Python 脚本执行一些环境检查,然后将预编译头的调试文件复制到另一个子项目的目录:

    <PreBuildEvent>
        <Command>C:\Python27\python.exe "$(SolutionDir)check_path.py" 32 && ^
copy "$(SolutionDir)h1ksim_lib\vc$(PlatformToolsetVersion).pdb" "$(IntDir)" /-Y > nul</Command>
        <Message>Performaing pre-build actions ...</Message>
    </PreBuildEvent>

这是我的实际用 在复制命令上使用 nul 可防止在构建窗口中显示任何输出,因此当它显示 0 个文件已复制时,我的队友不会被吓到。

参考共享 pre - 子项目之间的编译标头位于:

在项目之间共享预编译标头视觉工作室

I'm using Visual Studio 2010 on Windows 7 64-bits.

I found a solution that's better to my liking, I'm chaining commands together with && ^, for example, editing my .vcxproj xml file like so:

    <PreBuildEvent>
      <Command>echo "hello 1" && ^
echo "hello 2" && ^
echo "hello 3"</Command>
      <Message>Performaing pre-build actions ...</Message>
    </PreBuildEvent>

I've chained three commands together. The '&&' tells the shell to stop executing if the previous command errors out.

Note, in the .xml file, one can't use && directly, so '& amp;& amp;' must be used instead. Also note the use of the ^ character, this is the cmd shell's line continuation character (like BASH's \ char).

Each new command must start at the beginning of the line. Using this approach, one can chain as many commands as one wants, but if any fail, the rest in the chain won't get executed.

Here's my actual usecase, I'm performing some environment checks with a Python script, followed by copying my pre-compiled header's debug file to another sub-project's directory:

    <PreBuildEvent>
        <Command>C:\Python27\python.exe "$(SolutionDir)check_path.py" 32 && ^
copy "$(SolutionDir)h1ksim_lib\vc$(PlatformToolsetVersion).pdb" "$(IntDir)" /-Y > nul</Command>
        <Message>Performaing pre-build actions ...</Message>
    </PreBuildEvent>

The > nul usage on the copy command prevents any output showing up in the build window, so my teammates won't get freaked out when it says 0 file(s) copied.

Reference to sharing pre-compiled headers between sub-projects is here:

Sharing precompiled headers between projects in Visual Studio

撩发小公举 2024-08-13 06:57:54

您应该能够将命令放在单独的行上,然后每个命令将按顺序执行。或者,执行相同操作的“作弊”方法如下:

  • 创建第二个批处理文件来运行新功能的所需部分,然后创建一个运行两个组件批处理文件的父批处理,并在您的应用程序中运行该新批处理。预构建事件。例如:batch1.bat修改文件1,batch2.bat修改文件2,然后batch3.bat同时运行batch1.bat和batch2.bat

You should be able to put the commands on a separate line, and then each command will be executed in sequence. Alternatively, a "cheater" way to do the same thing is as follows:

  • Create a second batch file that runs the desired portion of new functionality, then create a parent batch that runs the two component batch files, and run that new batch in your pre-build event. For example: batch1.bat modifies file 1, batch2.bat modifies file 2, then batch3.bat runs both batch1.bat and batch2.bat
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文