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

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


当前回答

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

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

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

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

其他回答

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

UPD:从VS2017开始,构建工具中的工作负载完全消除了这个问题。见@SOReader的答案。

如果您不希望在构建服务器上修改任何内容,并且仍然希望在源代码控制之外构建项目,那么将所需的二进制文件置于源代码控制之下可能是一个好主意。你需要修改项目文件中的imports部分,如下所示:

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

第一行是从相对于解决方案目录的新位置实际导入的。第二个是关闭的版本(Condition="false"),它允许Visual Studio仍然认为您的项目是一个有效的Web应用程序项目(这是VS 2010 SP1自己做的技巧)。

不要忘记将C:\Program Files (x86)\Microsoft\ VisualStudio\v10.0\WebApplications复制到源代码控制下的BuildTargets文件夹。

我在CI/CD管道上构建SQL Server项目时遇到了这个问题。事实上,我在当地也遇到过,但我没有设法解决它。

对我有效的是使用MSBuild SDK,它能够从一组SQL脚本生成SQL Server Data-Tier Application包(.dacpac),这意味着创建一个新项目。但是我想保留SQL Server项目,这样我就可以通过Visual Studio上的SQL Server对象资源管理器将它链接到活动数据库。我采取了以下步骤让它运行起来:

Kept my SQL Server project with the .sql database scripts. Created a .NET Standard 2.0 class library project, making sure that the target framework was .NET Standard 2.0, as per the guidelines in the above link. Set the contents of the .csproj as follows: <?xml version="1.0" encoding="utf-8"?> <Project Sdk="MSBuild.Sdk.SqlProj/1.0.0"> <PropertyGroup> <SqlServerVersion>Sql140</SqlServerVersion> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> </Project> I have chosen Sql140 as the SQL Server version because I am using SQL Server 2019. Check this answer to find out the mapping to the version you are using. Ignore the SQL Server project on build, so that it stops breaking locally (it does build on Visual Studio, but it fails on VS Code). Now we just have to make sure the .sql files are inside the SDK project when it is built. I achieved that with a simple powershell routine on the CI/CD pipeline that would copy the files from the SQL Server project to the SDK project:

Copy-Item -Path "Path.To.The.Database.Project\dbo\Tables\*" -Destination (New-item name "dbo\Tables" -Type Directory -Path "Path.To.The.DatabaseSDK.Project\")

PS: The files have to be physically in the SDK project, either in the root or on some folder, so links to the .sdk files in the SQL Server project won't work. In theory, it should be possible to copy these files with a pre-build condition, but for some obscure reason, this was not working for me. I tried also to have the .sql files on the SDK project and link them to the SQL Server project, but that would easily break the link with the SQL Server Object Explorer, so I decided to drop this as well.

如果你正在使用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"* .

希望这能帮助到一些人。

来这里参加Visual Studio 2017的人。我也有类似的问题,更新到15.6.1后无法编译项目。 我不得不安装MSBulild工具,但错误仍然存在。

通过将v14.0文件夹从C:\Program Files (x86)\MSBuild\Microsoft\ VisualStudio复制到与v15.0相同的文件夹,我能够解决这个问题,这解决了所有错误。 现在我的文件夹结构如下所示,其中两个文件夹包含相同的内容。