web-applications - 在 64 位 : missing targets file 上从命令行使用 MSBuild 构建 Web 应用程序项目

标签 web-applications powershell msbuild 64-bit target

使用来自 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。问题已经记录在案 herehere .基本上在 VS 的 64 位安装上,MSBuild 所需的 Microsoft.WebApplication.targets 位于 Program Files(x86) 目录中,而不是 Program Files 目录中,但 MSBuild 无法识别这一点,因此看起来位置错误。

到目前为止,我拥有的两个解决方案都不理想:
  • 手动将 64 位文件从 Program Files(x86) 复制到 Program Files。这是一个糟糕的解决方案 - 每个开发人员都必须手动执行此操作。
  • 手动编辑 csproj 文件,使 MSBuild 看起来正确。再次不理想:我不想让每个人都在 64 位上手动编辑每个新项目的 csproj 文件。

  • 例如
    <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/

    相关文章:

    java - 类加载/使用后是否可以抛出NoClassDefFoundError?

    css - JQuery-Mobile 页面转换 - 闪烁(单独的页面)

    powershell - GoCD - 如何以彩色显示 PowerShell 输出?

    .net - 可以将 null 从 Powershell 传递到需要字符串的 .Net API 吗?

    c# - 使用 MsBuild 时 Wix 的构建顺序不正确

    运行旧文件的 Azure Web App (Linux) 与 ACR artefact 进行比较

    ajax - 如果我在页面上使用 Ajax 进行所有操作,我该如何进行搜索引擎优化?

    Powershell 3.0-工作流程-并行执行的限制数量

    .net - 我需要在生成服务器上安装 Azure 2.7 SDK 的哪些部分?

    msbuild - 将构建标识为依赖项目引用