16

I'm using Visual Studio 2015

I have a Shared Project as an Independent Solution (A collection of Extensions used in several others Solutions).

I want to TEST the Shared Project (Independently any other solution).

So, I add a new TEST Project.

But, in my TEST Project I can't add ANY reference to the Shared Project (No option).

enter image description here

user2864740
  • 60,010
  • 15
  • 145
  • 220
RamonEeza
  • 623
  • 6
  • 18

2 Answers2

20

You can edit the project's csproj file and at end of imports add an entry like

<Import Project="..\SharedProject\SharedProject.projitems" Label="Shared" />

changing path & SharedProject as appropriate

probably best adding it to another project and copying the row created there (assuming same path depths)

John M
  • 1,041
  • 8
  • 5
3

Since a shared project can't be compiled on its own it cannot be added as a reference directly to a unit test project.

However, a work-around I've used is to create a helper class library and use that as a reference in the test project. In your case, create a new class library and call it RobHelperTest.Helper. This project won't contain any code on its own, so delete the class1.cs file. Since this is a class library, you can reference shared projects so simply add a reference to all your shared projects to RobHelperTest.Helper and then create a reference to RobHelperTest.Helper in your unit test project RobHelperTest.

Screenshot showing the setup

Now you have full access to all your objects within the shared projects.

GeirR
  • 58
  • 6