Sturla
Sturla

Reputation: 3626

Can´t build .net core project with a database project. Error MSB4019

I have a new .net Core 2.0 Web API project (In Visual Studio 2017 Version 15.3.5) where I can´t build the solution if I add a new database project.

error MSB4019: The imported project "C:\Program Files\dotnet\sdk\2.0.0\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

I have tried all kinds of solutions

So why can I add a database project to a normal API project and everything works just fine but not to a .net core one?

Do database projects not work with .net Core? I have searched for information on this but sorry I just can´t find it.

I´m not sure what to do. Hope somebody can help.

Upvotes: 6

Views: 7772

Answers (2)

ccoutinho
ccoutinho

Reputation: 4556

I was having the exact same issue building a SQL Server project on an Azure DevOps CI/CD pipeline, and locally on VS Code. On Azure DevOps none of the pre-built build tasks would work for me, and locally I could only compile the SQL Server project on Visual Studio, which was annoying. Your solution didn't work for me, after doing what you suggest, I would get a .dll missing error, related with the first error.

I solved this by avoiding to add a SQL Server project to the solution.

I achieved this by using an MSBuild SDK, capable of producing a SQL Server Data-Tier Application package (.dacpac) from the set of SQL scripts. By adding this second project to the solution, I managed to continue taking advantage of linking the project to a live database through SQL Server Object Explorer on Visual Studio. I gave a more detailed explanation about my implementation in this answer.

Upvotes: 2

Sturla
Sturla

Reputation: 3626

Ok I managed to find the Microsoft.Data.Tools.Schema.SqlTasks.targets file on my computer.

I then needed to unload the project and edit it

There I changed this line

<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>

to the hardcoded path of my file

<SSDTExists Condition="Exists('C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>

And now it builds on my computer and on VSTS.

But why this is like this I don´t know.

Upvotes: 2

Related Questions