MSTestHacks icon indicating copy to clipboard operation
MSTestHacks copied to clipboard

Error CS0012: The type 'TestContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Open minyuanchen opened this issue 7 years ago • 0 comments

Hi, I Have installed MSTestHawks 2.3.2.0 in VS2017, with .net core 2.0 as the target framework and created a new test project. I used your code but got the error as:

Error CS0012 The type 'TestContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

I noticed that the message "Package 'MSTestHacks 2.3.20' was restored using '.NetFramework, Version=v4.6.1' instead of the project target framework '.NetCoreApp, Version=v2.0' This package may not be fully compatible with your project" displayed on my Solution Explore.

I have installed following packages from NuGet in my project:

"Microsoft.NET.Test.Sdk" Version="15.5.0" "MSTest.TestAdapter" Version="1.2.0" "MSTest.TestFramework" Version="1.2.0" "MSTestHacks" Version="2.3.20"

I also tried to install "Microsoft.VisualStudio.QualityTools.UnitTestFramework v11.0.50727.1", which the problem still exists. And "Microsoft.VisualStudio.QualityTools.UnitTestFramework.Update v15.0.26228" (This package is not compatible with netcoreapp2.0)

The code I used is as below:

[TestClass]
public class UnitTest1 : TestBase
{
  [TestMethod]
  [DataSource("Namespace.UnitTest1.Stuff")]
  public void TestMethod1()
  {
      var number = this.TestContext.GetRuntimeDataSourceObject();

      Assert.IsNotNull(number);
  }

  private IEnumerable Stuff
  {
      get
      {
          //This could do anything, fetch a dynamic list from anywhere....
          return new List { 1, 2, 3 };
      }
  }
}

So, is this really a compatibility problem of .Net Core 2.0 or do I miss something to get it be right? Thanks.

minyuanchen avatar Nov 20 '17 09:11 minyuanchen