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

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


当前回答

我在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.

其他回答

我在MS connect上找到了这个:

是的,您需要安装Visual Studio 2010在你的构建机器上进行构建 数据库项目。这样做确实 不需要额外的许可证 Visual Studio。

所以,这是我目前唯一的选择。

我的解决方案是这里几个答案的混合。

我检查了构建服务器,Windows7/NET4.0 SDK已经安装,所以我确实找到了路径:

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

但是,在这一行:

<进口项目=”(MSBuildExtensionsPath美元)\ Microsoft \ VisualStudio v9 WebApplication 0 WebApplications \ Microsoft。很明显" - >

$(MSBuildExtensionsPath)扩展到C:\Program Files\MSBuild,其中没有路径。

因此,我所做的就是创建一个符号链接,使用下面的命令:

mklink /J "C:\Program Files\MSBuild\Microsoft\VisualStudio" "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio"

通过这种方式,$(MSBuildExtensionsPath)扩展到一个有效的路径,应用程序本身不需要更改,只需要在构建服务器中更改(也许可以在每个构建中创建符号链接,以确保这一步不会丢失并被“记录”)。

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

希望这能帮助到一些人。

在build/CI服务器上构建时,通过指定/p:VSToolsPath= "来完全关闭Microsoft.WebApplication.targets的导入。这将从本质上使下面一行的条件为假:

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

在TeamCity中是这样做的:

如果没有安装VS,则不支持构建和发布wap。也就是说,如果你真的不想安装VS,那么你需要复制%ProgramFiles32%\MSBuild\Microsoft\下的所有文件。

您还需要安装Web部署工具。我想就是这样了。