简体   繁体   中英

Adding references in a shared (.shproj) project

I'm having an issue with adding a dll reference to a shared project. As seen in the picture below I have a Universal solution with a project for windows and a project for windows phone.

解决方案

In the HubApp1.Shared project I need to add a reference for some code in Class.cs. I will be using Class.cs in both the Windows project and the Windows Phone project. I have scoured Bing for how to fix this and I couldn't find anything.

You must add the reference in WP and Windows project.WP和Windows项目的参考。

The reason for this is that shared project is not compiled into any output DLL - it is compiled the project that references it, so it cannot reference any other project types except other Shared Projects.引用它的项目中,因此它不能引用除其他共享项目之外的任何其他项目类型。

I know this is an old question but I had a similar problem with a shared project. I needed a class in the shared project to use ConfigurationManager and the normal way would be to add a reference to the project, but you can't do that with a shared project.

In my case the solution was so simple it should have been obvious (but I was overthinking it!) - just give the full reference when using the configuration manager - EG:

var someVal = System.Configuration.ConfigurationManager.AppSettings["someKey"];

Not very elegant but simple enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM