6

I've got a C# MsTest project that targets net48. I've change the project it tests to the newer style Microsoft.NET.Sdk csproj format and that went ok. Now I want to convert the unit test project too.

I get errors about namespace Microsoft.VisualStudio.TestTools.UnitTesting cannot be found: error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft'

To solve that, I added the assembly reference to the csproj:

  <ItemGroup>
    <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
  </ItemGroup>

But I get errors that it can't be found. warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

This was found ok when the old csproj format was used.

How can I get this assembly reference to be found, or what is the preferred way of making this work?

7
  • Did you try MSTest.TestFramework package? Commented May 12, 2020 at 20:13
  • Does this answer your question? Where to find "Microsoft.VisualStudio.TestTools.UnitTesting" missing dll? Seems to be an exact duplicate Commented May 12, 2020 at 20:14
  • @PavelAnikhouski Thanks for the link. No it didn't answer the question, I've effectively tried the first answer there, but I'm using a different project format and the assembly can't be resolved. Commented May 12, 2020 at 20:37
  • @Pavel I tried a different package, I'm having more success with MSTest.TestFramework. It now builds, thanks. Commented May 12, 2020 at 20:51
  • I'm now just having this issue: Starting test execution, please wait... Test run will use DLL(s) built for framework .NETFramework,Version=v4.0 and platform X64. Following DLL(s) do not match framework/platform settings. MyTest.VsTests.dll is built for Framework .NETFramework,Version=v4.8 and Platform AnyCPU. Commented May 12, 2020 at 20:52

2 Answers 2

1

Here are 3 possible solutions:

  1. Upgrade to MSTestV2 by adding the nuget packages MSTest.Framework and MSTest.TestAdapter.
  • CAVEAT: MSTestV2 only supports .NET Framework 4.5 and later.
  1. Continue using MSTestV1 by helping visual studio find the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll reference, by adding this to your csproj: <PropertyGroup><AssemblySearchPaths></AssemblySearchPaths></PropertyGroup>
  1. Continue using MSTestV1 by browsing to the dll's path when adding the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
  • Depending on your version of VS the path will be something like: Program Files\Microsoft Visual Studio\2019\Professional\Common7\IDE\PublicAssemblies

I used #2 because we target net40 and have multiple developers working on different versions of VS.

Sign up to request clarification or add additional context in comments.

Comments

1

Add the nuget packages MSTest.TestFramework and MSTest.TestAdapter.

The test framework allows the unit tests to build and brings in the required namespaces. The second allows the test runner to find the tests in the project.

1 Comment

The nuget packages you linked to are MSTestV2 but Microsoft.VisualStudio.QualityTools.UnitTestFramework is MSTestV1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.