试图在构建服务器上构建我的项目给我以下错误:

Microsoft (R) Build Engine Version 4.0.30319.1
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.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.
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.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.

几个月前,我通过在Build Server上安装Visual Studio 2010解决了这个问题。但是现在我从头开始安装一个新的服务器,我想知道是否有更好的解决方案来解决这个问题。


当前回答

解决方案是在构建服务器代理上安装可重新分发的包。它可以通过多种方式实现,下面将介绍其中3种方式。挑一个最适合你的。

使用UI安装程序

这是原来的答案

现在,在2017年,你可以用MSBuildTools安装WebApplication重定向。只需转到这个页面,下载MSBuild 2017工具,在安装时单击Web开发构建工具,即可安装这些目标:

这将导致默认情况下在C:\Program Files (x86)\Microsoft VisualStudio\ 2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications中安装缺失的库

使用命令行

免责声明:我没有测试过以下任何建议

正如@PaulHicks和@WaiHaLee在评论中建议的那样,它也可以从CLI以无头模式(没有ui)安装,这实际上可能是解决移除服务器问题的更好方法。

解决方案A -使用包管理器(choco)

choco install visualstudio2017-workload-webbuildtools

解决方案B -运行安装程序在无头模式 请注意,这是在原始答案中建议使用的相同安装程序

vs_BuildTools.exe --add Microsoft.VisualStudio.Workload.WebBuildTools --passive

其他回答

根据这篇文章,你可以简单地下载Microsoft Visual Studio 2010 Shell (Integrated) Redistributable Package并安装目标。

这避免了在构建服务器上安装Visual Studio的需要。

我刚刚尝试了这一点,现在可以验证它的工作:

之前:

错误MSB4019:导入项目“C:\Program Files . 微软(x86) \ [\ \ VisualStudio \ v10.0 \ WebApplications \ Microsoft.WebApplication.targets” 没有找到。确认声明中的路径为 正确,并且该文件存在于磁盘上。

安装后:

(构建正确)

显然,这是比在构建服务器上安装Visual Studio更好的解决方案。

如果你试图使用VSTS部署一个项目,那么问题可能与检查“托管的Windows容器”选项而不是“托管的VS2017”(或18等)有关:

对我来说,它只是一个端口块。

如上所述,除了针对Microsoft. webapplication .targets的“Microsoft Visual Studio 2010 Shell(集成)可重分发包”和针对Microsoft. data . schema . sqltasks .targets的“Microsoft Visual Studio Team System 2008 Database Edition GDR R2”之外,最新的Windows SDK应该可以减少安装Visual Studio 2010的需求。然而,安装VS 2010可能实际上更少的整体下载和更少的工作。

回答问题的标题(而不是你得到的输出的问题):

如果只是web应用程序,将以下文件夹从开发机器复制到构建服务器可以修复此问题

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

根据构建中断的方式删除x86。如果你有其他项目类型,你可能需要复制整个msbuild文件夹。