In this post, I will explain to you how to fix the error: MSB4019: The imported project «Microsoft.Data.Tools.Schema.SqlTasks.targets» was not found.
What generates this issue?
Error MSB4019: The imported project “C:\Program Files\dotnet\sdk\7.0.100\Microsoft\VisualStudio\v14.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets” was not found. Confirm that the expression in the Import declaration “Microsoft.Data.Tools.Schema.SqlTasks.targets” is correct, and the file exists on disk.
This error occurs when you try to compile a database project(sqlproj) with DotNet build instead of MsBuild. You won’t get this error when you compile your project with Visual Studio.
How do I fix it?
You can build your project with MsBuild; this applies to solutions where no project has to be built on DotNet Core. If you have database projects with SDK projects, then I recommend using the following steps.
-
Open the database projects, and remove all the import blocks that mention the files: «Microsoft.Common.props» and «Microsoft.Data.Tools.Schema.SqlTasks.targets».
- Add the reference Microsoft.Build.Sql in the csproj file.
-
Save changes and build in Visual Studio; you shouldn’t have any problem building the project from Visual Studio.
-
Delete the bin and obj directories of all projects in the solution. I recommend a manual delete instead of a «Clean» execution.
Compile with Cake and DotNet Build.
When you build the project with the changes in the csproj file, not all projects within your solution may be compatible. In that case, you must move your database projects to another solution. This may or may not happen; it depends on your projects.
You must use the following command to build the solution that contains the SQL projects with dotnet build.
To use Cake, you must add the NetCoreBuild parameter to your Task.
References:
- NVL in SQL Server - 2023-11-01
- ¿Que es Cake Build? - 2023-02-22
- #How to fix error: MSB4019: The imported project «Microsoft.Data.Tools.Schema.SqlTasks.targets» was not found - 2023-02-20