我通过命令行构建一个项目,而不是在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。我试着在登记处搜索,但一无所获。

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

想法吗?


当前回答

我-没有什么能帮助将VisualStudioVersion变量的v11.0值更改为v10.0。在.csproj文件中改变变量没有。通过命令提示符设置却没有。等等……

最终将特定版本(v11.0)的本地文件夹复制到构建服务器。

其他回答

如果将Visual Studio 2012迁移到2013,则打开*。Csprorj项目文件编辑器。 并检查'Project'标签的ToolsVersion元素。

值为4.0 你坚持到12点0分

从 <?XML版本="1.0"编码="utf-8"?> <项目ToolsVersion = " 4.0 " 来 <?XML版本="1.0"编码="utf-8"?> <项目ToolsVersion = " 12.0 "

或者如果你用msbuild构建,那么只需指定VisualStudioVersion属性

msbuild / p: VisualStudioVersion = 12.0

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

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

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

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

这是密切相关的,但不一定能解决OPs特定的问题。在我的案例中,我试图使用VS2013自动化Azure站点的部署。然而,通过VS works构建和部署,使用MSBuild在“目标”周围显示了类似的错误。原来MSBuild在VS2013下是不同的,现在是VS的一部分,而不是。net框架(参见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

你会发现

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

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

我发现我在本地PC上缺少WebApplications文件夹,没有像我使用2012年那样安装Visual Studio 2017。