Can't add Shared Project to Visual Studio Test

2019-04-04 01:46发布

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

2条回答
混吃等死
2楼-- · 2019-04-04 02:13

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.

查看更多
太酷不给撩
3楼-- · 2019-04-04 02:24

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)

查看更多
登录 后发表回答