Can't add Shared Project to Visual Studio Test Project

ε祈祈猫儿з 提交于 2019-12-21 07:29:07

问题


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).


回答1:


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)




回答2:


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.

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



来源:https://stackoverflow.com/questions/32626253/cant-add-shared-project-to-visual-studio-test-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!