Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a reference to a Shared Code project (.shproj) from another project

When I created a new universal app project in Visual Studio it created a shared project that let me share code between the Windows Phone 8.1 and Windows 8.1 projects that were created.

Now I have other projects that I would also like to use that shared code. However, I do not see a way to add select that project in the "Add Reference..." window.

If I try to copy the reference from one of the existing projects I get the error:

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))

when I click 'Paste Reference'. How do I reference the shared project from other projects?

like image 617
vossad01 Avatar asked Jun 18 '14 20:06

vossad01


People also ask

How do I add references from one project to another?

Add a reference In Solution Explorer, right-click on the References or Dependencies node and choose either Add Project Reference, Add Shared Project Reference, or Add COM Reference. (You can right-click the project node and select Add from the fly-out menu to choose from these options, too.)

How do you reference a class from another project?

You will need to right click your project and select add -> Reference... -> Projects and tick the project you would like to reference. The result of this should show the referenced project under the references section of your project tree.

How do I reference another project in Visual Studio?

Adding a reference to another project is something I do quite often. In a recent update, Visual Studio introduced a new way to add a project reference. Instead of opening the "Add Reference" window, you can simply drag and drop a project. This post is part of the series 'Visual Studio Tips and Tricks'.


2 Answers

Adding the reference will require editing the project files where you want to add it. If it helps, you can peek at the project file where it is already referenced to see a working example.

Near the bottom of the project file (ex, a .csproj) there is likely already an <Import> element such as

<Project ...>   [...]   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project> 

You add the Shared project by adding another element like that for the Shared project. For example:

<Project ...>   [...]   <Import Project="..\Shared\Shared.projitems" Label="Shared" />   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project> 

It is important for the Label attribute to be set to "Shared." If you set it to something else it will not be recognized as a Shared project by Visual Studio and will not appear under References. Project should be set to the path to the appropriate ".projitems" file.

like image 106
vossad01 Avatar answered Sep 27 '22 21:09

vossad01


Visual Studio 2017:

Right-click the References or Dependencies item in the Solution Explorer and choose "Add Reference..."

Dependencies or References context menu

The Reference Manager will open. Click "Shared Project" on the left side of the Reference Manager

enter image description here

Then select your project and click OK.

like image 40
theguy Avatar answered Sep 27 '22 20:09

theguy