Fixing Build Errors with Database Unit Test Projects in Visual Studio 2017


I have been playing around with the Visual Studio RC version since few months now. Visual Studio 2017 was available for download on 7th March, 2017 – hence I thought of using it for my day to day development work. The good thing was that since I had the RC already installed, I just had to upgrade to get to the VS Enterprise version – which took me a few minutes. Earlier we had to uninstall the RC version and get a fresh new Visual Studio version installed. I must admit, the installation process is lot better now.

However I bumped into an issue when I opened my solution in VS2017 Enterprise.
I noticed that the Database Unit Test project fails to build. The same solution opens fine in Visual Studio 2015 Enterprise, so I think it’s a problem related with VS2017. I was not sure if there was any additional Nuget Package that needs to be installed. I did not find any documentation in MSDN about this.

Below are the error messages which I got —

The type or namespace name ‘Data’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?)
The type or namespace name ‘SqlDatabaseTestClass’ could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name ‘SqlDatabaseTestActions’ could not be found (are you missing a using directive or an assembly reference?)

Database project Build Errors

Opening the References folder of the Database Test project,I saw the below 2 missing dlls –
Microsoft.Data.Tools.Components
Microsoft.Data.Tools.Schema.Sql.UnitTesting

Missing References
Looks like it is related to SQL Server Data Tools and its support in VS 2017.
I reported the issue with Visual Studio Team yesterday and the issue is currently in a ‘Triaged’ state —
https://developercommunity.visualstudio.com/content/problem/29842/database-unit-test-project-does-not-build-in-visua.html

However after researching a bit more, I think I might have found a solution to get around/ fix this problem with Database Unit test Projects not building in VS2017.
It worked for me and I was able to build and run my project successfully. Try the below steps and let me know if it fixes the issue in your case too —

Right Click on the Database project, you will see an option – ‘Convert to SQL Server Unit testing project’

SQL Server Unit Testing Project

Once you click that, it will automatically update the Service References and prompt the final Conversion Report.

Conversion Report

I went back to my Database Unit Test project and saw that the below new references were added —

Microsoft.Data.Tools.Schema.Sql.dll
Microsoft.Data.Tools.Schema.Sql.UnitTesting.dll
Microsoft.Data.Tools.Schema.Sql.UnitTestingAdapter.dll

Updated References

Now when I built my project, everything ran fine and I was able to get rid of the Build Errors and all my database unit tests ran fine.

Related Posts on Visual Studio 2017 –

Automatic Performance monitoring of Extensions in Visual Studio 2017

Lightweight Solution Load in Visual Studio 2017

Windows Workflow is now an individual component in VS 2017 RC

New Installation Experience with Visual Studio 2017 RC

 

 



Categories: C#, Visual Studio, Visual Studio 2017

4 replies

  1. And still have problem on build server after that… 😦

    Like

  2. Samir, have you had similar issues with Visual Studio 2019? Have you found a solution for it?

    Like

  3. Had the similar issue, and following worked for me, sharing if people are still facing this issue:-

    had to mark the Specific Version = False for the following References in the TEST project

    Microsoft.Data.Tools.Components
    Microsoft.Data.Tools.Schema.Sql
    Microsoft.Data.Tools.Schema.Sql.UnitTesting
    Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

    do not set Specific Version = False for the following reference, not sure why but it breaks the test project, and it stays unloaded unless you fix the property in the project code manually.

    hope it helps.

    Liked by 1 person

  4. Microsoft.Data.Tools.Schema.Sql.UnitTestingAdapter (leave it as Specific Version = True)

    Like

Leave a Reply