【问题标题】:Node packages not building on Windows 8.1 - Missing Microsoft.Cpp.Default.props未在 Windows 8.1 上构建的节点包 - 缺少 Microsoft.Cpp.Default.props
【发布时间】:2014-01-30 22:11:13
【问题描述】:

NPM 包未在 Windows 8.1 上构建 - 失败并出现以下错误,

error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

我已经尝试了以下,

  • 将环境变量 VCTargetsPath 设置为 C:\Program Files (x86)\MSBuild\12.0\(错误会相应更改,但在 2012 构建工具中没有 Microsoft.Cpp.Default.props)。
  • 按照this answer安装VisualStudio 2010环境(卸载后按正确顺序安装)
  • 完全删除 VisualStudio 2010 并尝试使用 VisualStudio 2012,它应该可以根据 Node-gyp wiki 工作
  • 根据this answer添加了注册表项
  • 根据this answer尝试使用Windows 7.1 SDK命令提示符
  • 在根据this answer运行npm之前尝试设置VisualStudioVersion
  • 尝试根据this answer--msvs_version=2012传递给npm

以上方法均无效。

我已经为此花费了很长时间。有人有明确的答案吗?

【问题讨论】:

  • 它位于 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110 目录中。由 VS2012 安装程序放在那里。 VCTargetsPath 需要指向那里。
  • 我也试过了,它实际上需要最后没有V11.0的路径,但它仍然不起作用......
  • 得到了类似的东西,但在 Windows 7 上使用 VS 2013。为了解决它,我使用“VS2013 的开发人员命令提示符”运行npm install

标签: c++ visual-studio-2010 node.js visual-studio-2012 msbuild


【解决方案1】:

以防万一人们再次遇到这个问题,当我做了一个问题时,这个问题在我的案例中得到了解决

npm install -g --production windows-build-tools

Link for reference

Related question

【讨论】:

    【解决方案2】:

    设置以下解决了我的问题

    /property:VCTargetsPath="C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120
    

    正如forum中提到的那样

    【讨论】:

    • 在哪里指定/property?如果指定为npm install,则不会传递给 MSBuild..
    • 您可以编辑 C:\Windows\Microsoft.NET\Framework\v<Version>\msbuild.rsp 来设置全局 MSBuild 属性。
    • 我无法编辑 C:\Windows\Microsoft.NET\Framework\v\msbuild.rsp。我收到警告,“请检查此文件是否在另一个程序中打开”但我没有任何其他程序正在运行。
    【解决方案3】:

    我只是想用最新的答案更新这个问题。您现在不需要安装 Visual Studio。

    来源:https://github.com/nodejs/node-gyp/issues/629#issuecomment-153196245

    以下说明,以防源发生故障。

    1. 使用默认安装选项安装VC++ Build Tools Technical Preview

      [仅限 Windows 7] 需要 .NET Framework 4.5.1

    2. 安装Python 2.7,并将其添加到您的PATH:npm config set python python2.7

    3. 启动 cmd 并运行: npm config set msvs_version 2015 --global(这是每次都不是 lnpm install [package name] --msvs_version=2015l。)

    【讨论】:

    【解决方案4】:

    微软终于向 VS 提供了much better solution

    【讨论】:

    【解决方案5】:

    安装人员的快速说明:

    1. Visual Studio 2012 (Express)

    2. MSBuild 2012

    问题:

    1. MSBuild 加载 Microsoft.Cpp.Default.props

    2. MSBuild 无法加载 Microsoft.Cpp.props

    解决方案在这里: 设置 MSBuild 的参数: /property:VCTargetsPath="C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110"

    【讨论】:

    • 我有同样的问题 (1) 但使用 Visual Studio 2015。The imported project "C:\Microsoft.Cpp.Default.props" was not found. 所以我认为我应该使用C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140(路径存在)但是在哪里设置这个 MSBuild 参数?
    【解决方案6】:

    这与此处描述的问题相同

    NPM native builds with only Visual Studio 2013 installed

    如果你安装了 VS2013 版本,请在运行 npm 命令之前设置此环境变量:

    set GYP_MSVS_VERSION=2013
    

    或者对于 VS2012

    set GYP_MSVS_VERSION=2012 
    

    背景阅读:https://github.com/Automattic/socket.io/issues/1151

    【讨论】:

      【解决方案7】:

      我的快速解决方法是:

      set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120
      npm install
      

      【讨论】:

      • 如果您的机器上不存在此文件夹,请安装最新的 VS Community IDE visualstudio.com/en-us/products/visual-studio-community-vs.aspx 并重新启动。这个新文件夹将默认设置为:C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140。
      • 就我而言,必须将 V120 切换到 V140 才能正常工作。确保实际检查目录路径在资源管理器中的位置。
      • 这个快速修复也可以让 node-openzwave-shared 编译 (github.com/OpenZWave/node-openzwave-shared)
      • PowerShell 版本:[Environment]::SetEnvironmentVariable("VCTargetsPath", "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140", "Machine")
      【解决方案8】:

      所以现在是凌晨 2.47 - 想通了。

      虽然 node-gyp site seems to suggest using Visual Studio 2010 or 2012,但对于 Windows 8.1,安装 Visual Studio Express 2013 for Windows Desktop,如 this issue 中所述。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-10-23
        • 1970-01-01
        • 1970-01-01
        • 2014-06-03
        • 2019-12-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多