2

I have two different projects in a Visual Studio solution. I want to use one of the two as the main part of my program and so have referenced the second project like:

I know that I can use all the public classes from the project x on my main project. My question is: can I have dlls on the second project, x, and use the methods of those dlls in my first project?

A good example will be if, every month, I have a new version of a dll and I do not want to change this dll on 10 different projects in the solution explorer, I want to add those dlls as references on the x project and then all other projects to use the same dll.

leppie
  • 115,091
  • 17
  • 196
  • 297
  • no, if you use a class from a DLL in a project, you need to have a reference to it. If you don't want to manually update every project, look at putting the DLL in a local nuget repository package so you just need to update the package – Rhumborl Jan 03 '15 at 21:13
  • Best solution is to have 1 class library and use it in all your projects. But you can reference one project to another and share classes from each project within the same solution. – prospector Jan 04 '15 at 07:53
  • possible duplicate of [Circular reference among two .net assemblies](http://stackoverflow.com/questions/3501242/circular-reference-among-two-net-assemblies) – user287107 Jan 04 '15 at 13:51

2 Answers2

0

it is not possible by referencing both projects, you would create a circuilar reference.

anyway, it is possible by doing this over reflection. for example in project x you can enumerate all types (Assembly.GetTypes or so), also of the referenced project. then you can create an instance of a class Activator.CreateInstance and execute members.

user287107
  • 9,286
  • 1
  • 31
  • 47
0

If you have 2 projects:

  1. x.dll
  2. MyProgram.exe

Making MyProgram.exe reference x.dll is fine. However if you want x.dll to also reference MyProgram.exe, this creates a circular reference.

This is a dangerous road to go down because you can only build either project when you have a binary of the other. In other words you can't build both from source at the same time because the references are not yet compiled.

I would highly advise against this. Instead consider further abstracting your code by moving the code x.dll needs to get from MyProgram.exe to a separate y.dll. This way you would have 3 projects:

  1. y.dll
  2. x.dll (references y.dll)
  3. MyProgram.exe (references x.dll and y.dll)

This way you can build all from source as all the dependencies are linear.

Jason Faulkner
  • 6,378
  • 2
  • 28
  • 33