首页 文章

外部VS2013生成错误“错误MSB4019:找不到导入的项目<path>”

提问于
浏览
195

我正在通过命令行而不是Visual Studio 2013内部构建项目 . 注意,我已将项目从Visual Studio 2012升级到2013.项目在IDE中构建良好 . 另外,我首先完全卸载了VS2012,重新启动并安装了VS2013 . 我拥有的唯一Visual Studio版本是2013 Ultimate .

ValidateProjects:
    39>path_to_project.csproj(245,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
    39>Done Building Project "path_to_project.csproj" (Clean target(s)) -- FAILED.

以下是有问题的两条线:

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

原来的第二行是v10.0,但我手动将其更改为v12.0 .

$(VSToolsPath)从我看到的v11.0(VS2012)文件夹中拉长,显然不再存在了 . 路径应该是v12.0 .

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications\

我尝试在系统环境变量表中指定VSToolsPath,但外部构建实用程序仍使用v11.0 . 我尝试在注册表中搜索,但没有提到任何内容 .

遗憾的是,我没有看到任何简单的方法来获得使用的确切命令行 . 我使用构建工具 .

思考?

23 回答

  • 244

    我刚收到Kinook的回复,他给了我一个link

    基本上,我需要在建造之前调用以下内容 . 我想Visual Studio 2013不会首先自动注册环境,但2012年确实如此,或者我做了并忘了 .

    call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86
    

    希望这篇文章可以帮助别人 .

  • 21

    在命令行中运行它也将解决问题 . SETX VisualStudioVersion“12.0”

  • 70

    如果将Visual Studio 2012迁移到2013,则使用edior打开* .csprorj项目文件 .
    并检查'Project'标签的ToolsVersion元素 .

    这是4.0的 Value
    你做到12.0

    • 来自

    <?xml version =“1.0”encoding =“utf-8”?>
    <Project ToolsVersion =“4.0”

    <?xml version =“1.0”encoding =“utf-8”?>
    <Project ToolsVersion =“12.0”

    或者如果使用msbuild构建,则只需指定VisualStudioVersion属性

    msbuild /p:VisualStudioVersion=12.0

  • 0

    你会找到

    C:\Program Files  (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets
    

    在csproj文件中出现此错误 . 只需从csproj中删除它然后构建 .

  • 1

    我安装一些VS组件时出现此错误 . 不幸的是,这些答案都没有帮助我 . 我使用TFS进行命令开发,我没有编辑构建定义的权限 . 我通过删除调用 VS110COMNTOOLSVS120COMNTOOLS 的环境变量解决了这个问题 . 我认为它是与我的VS组件一起安装的 .

  • 0

    giammin's solution部分不正确 . 您 SHOULD NOT 从解决方案中删除整个PropertyGroup . 如果这样做,MSBuild's "DeployTarget=Package"功能将停止工作 . 此功能正在设置relies on the "VSToolsPath" .

    <PropertyGroup>
      <!-- VisualStudioVersion is incompatible with later versions of Visual Studio.  Removing. -->
      <!-- <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> -->
      <!-- VSToolsPath is required by MSBuild for features like "DeployTarget=Package" -->
      <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    </PropertyGroup>
    ...
    <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
    
  • 10

    我发现我错过了本地PC上的WebApplications文件夹,没有像我在使用2012时那样安装Visual Studio 2017 .

  • 2

    我也有这个,您可以通过在构建定义中设置工具版本来修复它 .

    这很容易做到 . 打开构建定义并转到“ Process " page. Then under the " 3. Advanced " group you have a property called " MSBuild Arguments ” . 使用以下语法将参数放在那里

    /p:VisualStudioVersion=12.0
    

    如果您有更多参数,请用空格而不是逗号分隔它们 .

  • 0

    您应该将文件夹WebApplications从C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v12.0 \复制到C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v11.0 \

  • 1

    我的FSharp目标有这个问题(FSharpTargetsPath为空) .

    许多路径都是参考VS版本构建的 .

    由于各种原因,我们的构建以系统权限运行,环境变量“VisualStudioVersion”仅在“用户”级别设置(由VS 2013安装程序) - 这是公平的 .

    确保您运行的级别(系统或用户)上的“ VisualStudioVersion " environment variable is set to " 12.0 ” .

  • 2

    我正在使用外部构建实用程序 . 想想像 Ant 这样的东西,如果我理解正确的产品,只是一个商业版本 . 我不得不联系制造商寻求答案 .

    事实证明,项目中有一个全局宏,DEVSTUDIO_NET_DIR . 我不得不改变.Net的路径 . 他们将各种视觉工作室版本列为“动作”,通过我关闭,但所有道路都回到了幕后的那个全局变量 . 我会列出这是对产品的缺陷,如果我按照我的方式,除非我在理解中遗漏了一些东西 . 纠正那里的路径修复了构建问题 .

  • 0

    我已经尝试了所有上述解决方案但仍然没有运气 . 我听说人们在他们的构建服务器上安装visual studio来修复它,但我只有5GB的可用空间所以我只是将C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio复制到我的构建服务器并且每天调用它 . 之后开始工作,使用team city 9.x和visual studio 2013 .

  • 0

    在我的案例中,开发环境是VS2013,我使用的是TFS 2010.Build是针对.NET 4.5.1的 . 我正在为CI设置自动构建 . 每当我尝试上面提到的变通方法时 - 比如完全删除属性组或替换某些行等等 . 我的构建曾经发生过在TFS中,但我发布到azure曾经失败过'MSDeploy'或者有时会出现一些不同的错误 . 我无法同时实现这两个目标 .

    所以最后我不得不通过MSBuild参数来解决问题 .

    转到编辑构建定义>进程> 3.高级> MSBuild参数(设置为)/p:VisualStudioVersion=12.0

    它对我有用 .

  • 49

    解决问题只需要做一件事:将TeamCity升级到8.1.x或更高版本,因为仅在TeamCity 8.1中引入了对Visual Studio 2012/2013和MSBuild Tools 2013的支持 . 在您的构建步骤中升级TeamCity后,相应地修改MSBuild工具版本设置,问题将消失 . 欲了解更多信息,请阅读:http://blog.turlov.com/2014/07/upgrade-teamcity-to-enable-support-for.html

  • 22

    我有类似的问题 . 所有提出的解决方案都只是解决了这个问题,但并未解决错误来源 . 如果您使用的是tfs构建服务器,则不应该应用@giammin解决方案,因为它只是崩溃的发布功能 . @ cat5dev解决方案 - 解决问题,但不解决它的来源 .

    我几乎可以肯定你正在使用VS2012的构建过程模板,如 ReleaseDefaultTemplate.11.1.xaml or DefaultTemplate.11.1.xaml 这些构建模板已经为VS2012和$(VisualStudioVersion)设置为11.0

    should use build process template for VS2013 ReleaseTfvcTemplate.12.xaml or TfvcTemplate.12.xaml 将$(VisualStudioVersion)设置为12.0

    这不需要在项目文件中进行任何更改 .

  • 2

    我也有同样的错误..我这样做是为了解决它

    <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" />
    

    改成

    <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
    

    它已经完成了 .

  • 2

    我有同样的问题,并找到一个更容易的解决方案

    这是由于Vs2012在csproj文件中添加了这一部分:

    <PropertyGroup>
      <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
      <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    </PropertyGroup>
    

    您可以安全地删除该部件,您的解决方案将构建 .

    正如Sielu指出的那样,您必须确保.proj文件以<Project ToolsVersion =“12”开头,否则下次使用visual studio 2010打开项目时,它将再次添加已删除的节点 .

    否则,如果您需要使用webdeploy或使用构建服务器,则上述解决方案将无效,但您可以在构建脚本中指定 VisualStudioVersion 属性:

    msbuild myproject.csproj /p:VisualStudioVersion=12.0
    

    或编辑您的构建定义:

    edit build definition to specify the VisualStudioVersion property

  • 0

    我 - 没有任何帮助将VisualStudioVersion变量的v11.0值更改为v10.0 . 更改.csproj文件中的变量没有 . 通过命令promt设置它没有 . 等等...

    完成将该特定版本(v11.0)的本地文件夹复制到我的构建服务器 .

  • 6

    Based on TFS 2015 Build Server

    如果你反击这个错误 ... Error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

    打开错误消息中指定的项目的 .csproj 文件,并注释掉以下部分

    <!-- <PropertyGroup> --> <!-- <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> --> <!-- <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> --> <!-- </PropertyGroup> -->

  • 0

    在我的情况下,我使用的是 MSBuild.exe 的错误版本 .

    您需要使用的版本取决于您用于创建项目的Visual Studio版本 . 在我的情况下,我需要14.0(使用Visual Studio 2015) .

    This was found at:

    C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe
    

    You can look under:

    C:\Program Files (x86)\MSBuild
    

    寻找其他版本 .

  • 2

    在我的情况下,我只是通过打开.csproj文件评论下面的行,并做了伎俩

    . <!-- <Import Project="..\PRPJECTNAME.targets" /> -->

    我的问题可能有所不同,但我被拖到这里,但这可能对某人有所帮助 .

    我从我的解决方案中选择了一个单独的Web项目,并尝试将其作为一个独立的项目打开,这是一个问题,之后我能够解决问题 .

  • 0

    我安装了Visual Studio 2013 . 这对我有用:

    <PropertyGroup>
        <VisualStudioVersion Condition="'$(VisualStudioVersion)' != ''">12.0</VisualStudioVersion>`
        <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    </PropertyGroup>
    

    所以我已将条件从 == 更改为 != ,将值从 10.0 更改为 12.0 .

  • 3

    这是密切相关的,但可能会或可能不会修复OP的具体问题 . 就我而言,我试图使用VS2013自动部署Azure站点 . 但是,通过VS工作构建和部署,使用MSBuild在"targets"周围显示了类似的错误 . 事实证明MSBuild在VS2013下是不同的,现在是VS的一部分而不是.Net Framework(见http://timrayburn.net/blog/visual-studio-2013-and-msbuild/) . 基本上,使用正确版本的MSBuild:

    老,VS2012

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
    

    新的,VS2013

    C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe
    

    更新,VS2015

    C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe
    

    更新,VS2017(没有完全测试但发现 - 他们已经移动了一些东西)

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe
    

相关问题