Can't add Shared Project to Visual Studio Test Project
Asked Answered
M

2

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

Moujik answered 17/9, 2015 at 8:54 Comment(1)
Having the same problem, would love a solution...Darcidarcia
D
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)

Disject answered 17/11, 2015 at 21:0 Comment(0)
G
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.

Greening answered 14/11, 2015 at 16:28 Comment(1)
It works, thx. Do not forget to add all necessary library references to the Helper project.Terr

© 2022 - 2024 — McMap. All rights reserved.