【问题标题】:Build another project by prebuild event without adding reference通过 prebuild 事件构建另一个项目而不添加引用
【发布时间】:2012-06-05 10:49:09
【问题描述】:

我在预构建事件中将 .exe 文件从一个单独的文件复制到我的主项目的文件夹中,但我需要在构建我的主项目之前构建该项目,所以我想在我的主项目的预构建事件中构建该项目。

【问题讨论】:

标签: visual-studio-2010 pre-build-event


【解决方案1】:

并不是说这是最好的解决方案,但它绝对可以满足您的需求:将以下内容放入您的预构建活动中

"$(VS100COMNTOOLS)..\IDE\devenv" "<em>csproj location OR sln location</em>" /Rebuild "<em>configuration required if you have more than configuration ex: Debug|x64</em>"

【讨论】:

  • 谢谢!我使用 Visual Studio 2015,现在它看起来像 "$(DevEnvDir)\devenv" "csproj location OR sln location" /Rebuild "configuration required if you have more than configuration ex: Debug|x64"
【解决方案2】:

这对我有用:

"$(DevEnvDir)devenv" "$(SolutionDir)MySolution.sln" /Build $(configuration) /project "$(SolutionDir)MyProjectFolder\MyProject.csproj"

这里$(DevEnvDir)$(SolutionDir)$(configuration)Visual Studio Macros,所以这条命令会被翻译成:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\devenv" "D:\Learning\MySolutionFolder\MySolutionName.sln" /Build Debug /project "D:\Learning\MySolutionFolder\MyProjectFolder\MyProject.csproj"

【讨论】:

  • $(DevEnvDir) 和 $(SolutionDir) 后面不应有 \,因为变量以 \ 结尾
【解决方案3】:
"$(DevEnvDir)devenv" "$(SolutionPath)" /Rebuild $(configuration) /project "$(SolutionDir)MyProjectFolder\MyProject.csproj"

现已在 Visual Studio Community 16.11.1 上测试

【讨论】:

    【解决方案4】:

    在 Visual Studio 2019 中使用以下命令,与“$(DevEnvDir)devenv”相比,msbuild 的构建速度更快。

    msbuild "$(SolutionDir)Sample.sln" /p:configuration=$(configuration)

    【讨论】:

      猜你喜欢
      • 2018-04-28
      • 1970-01-01
      • 2017-03-16
      • 2012-04-13
      • 2018-07-26
      • 1970-01-01
      • 2020-12-06
      • 2022-11-20
      • 2012-06-15
      相关资源
      最近更新 更多