Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 - Shared Projects Reference Tab Missing on Web Project

Tags:

I upgraded to Visual Studio 2015 from our MSDN subscription because I was pretty excited to read about Shared Projects... No more managing 21382 nuget packages in our dependencies when all we want to do is reuse code.

So I built a test shared project with some code in it. Then I add a new empty web application on .Net 4.6 to the project. Now I expected to go to references and see a "Shared Projects" tab on the references window, but I do not see one.

Now I can add a class library to the same solution and I see the tab and can add the shared reference. However I cannot add the shared project to my web application.

I was rather hoping I could use this concept to share views with multiple MVC projects.

Am I missing something here, or are shared projects not compatible with Web Projects?

The only way I see around this is to have two projects for every web application I build. 1 for the code, and 1 for the content.

For example

XYZ.SomeWebSite.Code (Class Library Project Type) -> references Shared Project XYZ.SomeWebSite (Web Project Type) 

However going this route, I would not be able to push views, text files, css files, javascript files, etc into the web application.

like image 234
Ryan Mann Avatar asked Aug 03 '15 19:08

Ryan Mann


1 Answers

[Temporary Answer]

I was able to work around the problem by manually editing the csproj file for my web application.

Here are the steps:

  1. Unload the web application project
  2. Edit the *.csproj file by right clicking the project and clicking edit...
  3. Now look for the ProjectTypeGuids element.

    {349C5851-65DF-11DA-9384-00065B846F21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}

The first guid is the guid for an ASP.Net MVC 5 Project, and the 2nd guid is for C#.

All you need to do is temporarily remove the first guid and the semicolon, leaving just the c# guid (the 2nd one).

Reload the project and add your shared projects. Once they are all added, edit the project file and put the first guid and the semicolon back.

Reload the project.

The Shared Project reference will still be there, and it will build and link into your web application.

Optionally, you can just manually add the shared project referrence, the format is like this

<Import Project="..\XYZ.UPlugin\XYZ.Plugin.projitems" Label="Shared" /> 
like image 118
Ryan Mann Avatar answered Oct 22 '22 12:10

Ryan Mann