Reputation: 11958
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?
Upvotes: 27
Views: 33962
Reputation: 11
I got the same error, trying to add windows forms to something. I added the windows forms reference to all the projects using my shared project, and the code compiled.
Im guessing that using a shared project, instead of a reference to a dll means the projects using your shared project. MUST have the references your shared one needs.
Upvotes: 0
Reputation: 11958
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.
Upvotes: 40
Reputation: 743
Check your version of Visual Studio. in VS2017 there was a bug fix for version 15.9 which will show the Shared Project selector. Click Tools -> Update to get the lastest version of VS
Upvotes: 0
Reputation: 35
In TargetProject.csproj file add that string:
<Import Project="..\YourSharedProject\YourSharedProject.projitems" Label="Shared" Condition="Exists('..\YourSharedProject\YourSharedProject.projitems')" />
Upvotes: 4
Reputation: 871
Visual Studio 2017:
Right-click the References or Dependencies item in the Solution Explorer and choose "Add Reference..."
The Reference Manager will open. Click "Shared Project" on the left side of the Reference Manager
Then select your project and click OK.
Upvotes: 11