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

 

 

One thought on “Fixing Build Errors with Database Unit Test Projects in Visual Studio 2017

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s