16

I ran into the following probem, when trying to build using a TFS build definition.

When executing a Build the agent logs following errors:

Error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Error CS0246: The type or namespace name 'TestInitializeAttribute' could not be found (are you missing a using directive or an assembly reference?)

Error CS0246: The type or namespace name 'TestCleanupAttribute' could not be found (are you missing a using directive or an assembly reference?)

Error CS0246: The type or namespace name 'TestCleanup' could not be found (are you missing a using directive or an assembly reference?)

Error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)

So i understand the message that way, that the buildAgent is unable to find the following .dll

Microsoft.VisualStudio.TestTools.UnitTesting;

I have installed Visual Studio 2017 RC and Visual Studio 2017 Build Tools on the server, that runs TFS and the Buildagents.

I have also installed .net 4.6.1 on that mashine.

This accepted answer is not a solution for me.

There must be some kind of solution, that does not include to copy that dll into the git trunk and reference it from there.

Update

I am able to locally build the Solution using Visual Studio 2017 RC on that mashine. But the build agent still throws the same errors.

Community
  • 1
  • 1
Tobias Theel
  • 3,088
  • 2
  • 25
  • 45
  • 1
    Are you able to build your project locally in VS 2017 RC? Go to your build agent machine and use msbuild command line to run your project manually to see what result would you get? Also, check causes of Error CS0234 and Error CS0246 on websites below to see whether they can help: https://learn.microsoft.com/en-us/dotnet/articles/csharp/language-reference/compiler-messages/cs0234, https://learn.microsoft.com/en-us/dotnet/articles/csharp/language-reference/compiler-messages/cs0246 – Cece Dong - MSFT Mar 01 '17 at 02:22
  • Thx for the hint with trying to build it using msbuild from command line. I'll also check that and give feedback – Tobias Theel Mar 01 '17 at 08:47

3 Answers3

32

I finaly figured out how to solve this issue.

I added the following nuget package as reference to my project:

https://www.nuget.org/packages/MSTest.TestFramework/

That is the mstestv2 Framework.

Afterwards i had to remove the old reference to the mstestv1 framework.

The build errors are gone now.

Update:

If you want to have your tests discoverable add MSTest TestAdapter to your project.

Thanks to Maciej for that Information.

Tobias Theel
  • 3,088
  • 2
  • 25
  • 45
  • 4
    If you want your tests to be discoverable/runable from within Visual Studio, you will want to add MSTest.TestAdapter version 1.2.0 also: Install-Package MSTest.TestAdapter -Version 1.2.0 – Maciej Nov 17 '17 at 19:29
  • I have the similar issue with a custom dll. Then I have deleted old reference to the dll, pasted new reference to the same dll and it works! – Rekshino Dec 12 '17 at 11:15
3

I changed the target framework from 4.7 to 4.6.1 in VS 2017, and it was fixed

Charlie
  • 639
  • 9
  • 19
2

Make sure you have not checked in the /packages directory that contains the NuGet packages & DLLs. I accidentally checked this directory into source control and it prevented the NuGet restore task from correctly downloading the needed DLLs

The key message was a warning earlier in the build log:

Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

JordanBean
  • 1,949
  • 21
  • 28