使用来自 powershell 的 MSBuild 构建包含 Web 应用程序项目的解决方案,如下所示:
msbuild "/p:OutDir=$build_dir\" $solution_file
在 32 位上对我来说效果很好,但在 64 位机器上我遇到了这个错误:
error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
我正在使用 Visual Studio 2008 和 powershell v2。问题已经记录在案 here和 here .基本上在 VS 的 64 位安装上,MSBuild 所需的 Microsoft.WebApplication.targets 位于 Program Files(x86) 目录中,而不是 Program Files 目录中,但 MSBuild 无法识别这一点,因此看起来位置错误。
到目前为止,我拥有的两个解决方案都不理想:
例如
<Import Project="$(MSBuildExtensionsPathx86)\$(WebAppTargetsSuffix)" Condition="Exists('$(MSBuildExtensionsPathx86)\$(WebAppTargetsSuffix)')" />
理想情况下,我想要一种方法来告诉 MSBuild 从命令行从正确的位置导入目标文件,但是 I can't work out how to do that .任何解决方案?
最佳答案
您还有其他几种选择:
由于 MSBuild 基本上不受环境变量影响,因此您始终可以在启动 msbuild 之前将 Program Files 更改为 ProgramFiles (x86)。
$env:ProgramFiles = ${env:ProgramFiles(x86)}
这应该会诱使 MSBuild 寻找正确的位置
我能想到的另一种方法是使用 Start-Job 从脚本中运行 MSBuild。这更像是一种通用的解决方法:
Start-Job {
Import-Module YourProject
Start-YourMsBuildProject
} -RunAs32
希望这可以帮助
关于web-applications - 在 64 位 : missing targets file 上从命令行使用 MSBuild 构建 Web 应用程序项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2523265/