3

I want to add a reference to an assembly in my unit test project, because it has to be referenced in order to call the method to be tested, but... I can't. I don't have the option to do so in the "Add reference" window in Visual Studio. I can only add Project references or Browse for dll references (see image below, left is unit test project and right is the app project's "Add reference" window)

Unit test project add reference window Main app add reference window

I have the error "The type is defined in an assembly that is not referenced. You must add a reference to the assembly.", but when I go ahead and use the quick action to do so, nothing happens.

Why can't I add a reference to the assembly and is there another way around the missing assembly issue?

Note: Using Visual Studio 2017

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
DMX David Cardinal
  • 599
  • 2
  • 7
  • 19
  • Is the target assembly another project in the same solution, inside a NuGet package, or a `*.dll`/`*.exe` file on-disk? – Dai May 31 '20 at 23:55
  • 1
    I'm assuming your Unit Test project is using .NET Core or .NET Standard instead of .NET Framework - is that correct? Is that what you want or need for what you're doing? – Dai May 31 '20 at 23:55
  • @Dai The desired target assembly is a Microsoft assembly. However, the unit test project is indeed .NET Core. I'm assuming you're suggesting to replace it with a .NET Framework unit test project to fix the issue? – DMX David Cardinal Jun 01 '20 at 00:04
  • 1
    What do you mean by "a Microsoft assembly"? If you mean it's an assembly that's in the .NET Framework then yes, you will need to change your test project to be a .NET Framework test project and not a .NET Core test project. – Dai Jun 01 '20 at 00:09
  • 1
    @Dai I suppose it is part of .NET Framework. The project doesn't discover the tests now so I have to deal with that issue, but I suppose it fixes what this question was looking for. Will post an answer for the question following our discussion. – DMX David Cardinal Jun 01 '20 at 00:44

1 Answers1

3

Following the discussion with @Dai, the assembly references weren't available because an NUnit Test Project created in Visual Studio is created using .NET Core rather than .NET Framework.

To have access to .NET Framework assemblies, you need to create a .NET Framework Unit Test Project and then replace the MS Test Framework with the NUnit Test Framework.

DMX David Cardinal
  • 599
  • 2
  • 7
  • 19