6

What are the practical implications of adding a normal Project (WPF Application, Windows Forms Application, etc...) vs a Shared Project as a reference in Visual Studio 2015?

I know that Shared Projects are a rather new (since VS 2013) and presumably superior feature, so I would like to know all differences.

Could one difference be that files in the Shared Project can use code from projects where the Shared Project is added as a reference if all of those projects do have the code to be used? This is not possible in a normal Project of course.

Also for some reason Visual Studio shows me far less suggestions if I do "Add -> New Item..." on a Shared Project.

  • My understanding is that Shared project let you share common code between otherwise unrelated projects. Ie if you had a struct `MyStruct` that for some reason would be the same in both you don't have to copy paste it into both. There's no common compiled dll that both projects share. Instead the code is 'copied' into each independent project. You'd end up with two distinct structs `Project1.MyStruct` and `Project2.MyStruct` which while identical would be different Types – pinkfloydx33 Feb 14 '17 at 12:31
  • @pinkfloydx33 Yes but that is also the case with a normal Project (WPF Application, Windows Forms Application) added as a reference, right? –  Feb 14 '17 at 12:40
  • No because those are compiled into an assembly (either an exe or dll) and that gets referenced. A shared project copies the code itself whereas the other case uses the assemblies directly. See the duplicate I linked – pinkfloydx33 Feb 14 '17 at 12:41
  • The duplicate does not mention that normal Projects (WPF Applications, Windows Forms Applications, etc...) are also compiled if added as a reference and I did not know that. Thanks for that knowledge, it's one more difference. –  Feb 14 '17 at 12:47

2 Answers2

7

As a sum up of differences found so far (take that with a grain of salt as I'm not an expert):

Shared Projects vs normal Projects (Class Library, WPF Application, Windows Forms Applications, etc...) added as a reference:

  • Files in Shared Projects can use code from projects where the Shared Project is added as a reference if all of those projects do have the code to be used.

  • Shared Projects do have less suggestions when "Add -> New Item..." as they are more generic.

  • Shared Projects are not compiled to .dll or .exe but added with source code to the project referencing them and therefore can be debugged step by step.

1

Project, assuming a class library, will be compiled and the dll will be referenced from the other project. Shared Projects are fancy way of file linking (or copy pasting the code file when compiling). This has benefits as in you can have access source code that is not only in shared project but also in the target project (as long it works for all referenced projects). But can also give conflicts if using this in an library that will be referenced in your target projecct too. I think you best can go for a normal class library and only use shared project if you are really sure you needed (was introduced to have better code sharing between your win8.1 and wp8.1 app)

Dave Smits
  • 1,871
  • 14
  • 22
  • I am not talking about a class library but a normal non-compiled project (e.g. WPF Application, Windows Forms Application, etc...) –  Feb 14 '17 at 12:27