我通过命令行构建一个项目,而不是在Visual Studio 2013中。注意,我已经将我的项目从Visual Studio 2012升级到2013。项目在IDE中构建得很好。此外,我完全卸载VS2012,重新启动,并安装VS2013。我唯一拥有的Visual Studio版本是2013终极版。

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。我试着在登记处搜索,但一无所获。

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

想法吗?


当前回答

Giammin的解决方案部分是不正确的。您不应该从解决方案中删除整个PropertyGroup。如果你这样做,MSBuild的“DeployTarget=Package”特性将停止工作。这个特性依赖于“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)' != ''" />

其他回答

我也犯了同样的错误。我这么做是为了弥补

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

改变

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

做完了。

你会发现

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

在出现此错误的csproj文件中。 只需从csproj中删除这个,然后构建。

我刚收到Kinook的回复,他给了我一个链接:

基本上,我需要在构建之前调用以下命令。我猜Visual Studio 2013不会先自动注册环境,但2012做到了,或者我做到了,然后忘记了。

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

希望这篇文章能帮助到其他人。

我尝试了以上所有的解决方案,仍然没有运气。我听说有人在他们的构建服务器上安装visual studio来解决这个问题,但是我只有5gb的空闲空间,所以我只是把C:\Program Files (x86)\MSBuild\Microsoft\ VisualStudio复制到我的构建服务器上,然后就结束了。之后开始工作,使用城市9队。X和visual studio 2013。

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

这很容易做到。打开构建定义并转到“Process”页面。然后在“3”下面。高级”组中有一个名为“MSBuild Arguments”的属性。按照以下语法放置参数

/p:VisualStudioVersion=12.0 

如果有更多参数,请用空格分隔,而不是逗号。