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

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解决了这个问题。但是现在我从头开始安装一个新的服务器,我想知道是否有更好的解决方案来解决这个问题。


当前回答

我通过添加来解决这个问题 / p: VCTargetsPath = " C: \ Program Files \ MSBuild \ Microsoft.Cpp \ v4.0 \ V120” 成 使用MSBuild >命令行参数构建Visual Studio项目或解决方案

其他回答

如上所述,除了针对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可能实际上更少的整体下载和更少的工作。

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

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

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

之前:

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

安装后:

(构建正确)

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

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开关,请参考此处输入链接说明 在这里输入图像描述

如果你正在使用MSBuild,就像在构建服务器的情况下一样,对我来说有用的是:

修改如下:

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

to:

<Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

我的Msbuild命令是:*“C:\Program Files (x86)\ Msbuild \14.0\Bin\ Msbuild .exe”方案。sln /p:Configuration=Debug /p:Platform="任意CPU"* .

希望这能帮助到一些人。

新版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/