试图在构建服务器上构建我的项目给我以下错误:
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解决了这个问题。但是现在我从头开始安装一个新的服务器,我想知道是否有更好的解决方案来解决这个问题。
新版msbuild似乎没有附带Microsoft.WebApplication.targets。要修复你需要更新你的csproj文件,如下所示:
1)编辑web应用程序csproj(右键单击)。在csproj的底部找到关于构建工具的部分。应该是这样的。
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
2)你需要在VisualStudioVersion标签下面添加一个VSToolsPath行,这样看起来就像这样
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<!--Add the below line to fix the project loading in VS 2017 -->
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<!--End -->
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
参考链接:
https://alastaircrabtree.com/cannot-open-vs-2015-web-project-in-vs-2017/
解决方案是在构建服务器代理上安装可重新分发的包。它可以通过多种方式实现,下面将介绍其中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
After installation of MSBuild tools from Microsoft, define the MSBuild path in the environment variable, so that it can be run from any path.
Edit the .csproj file in any notepad editor such as notepad++, and comment the
Check for the following elements,
-->
Make sure you use import only once, choose whichever works.
Make sure you have the following folder exists on the drive, "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0" or whichever version is referenced by MSBuild target at "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets"
From the command prompt, run the following command, to check
C: > msbuild“C: \ \ DotnetCi。/p:Configuration=Release /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false
根据需要选择/p开关,请参考此处输入链接说明
在这里输入图像描述