Lost
Lost

Reputation: 13645

What if two nuget package point to the same Dll

Ok. So I have one solution with three projects

  1. Project-A.csproj(turned into A.nupkg)
  2. Project B.csproj(turned into B.nupkg)
  3. Utils.csproj

Since utils.csproj has a lot of central functions both A and B have reference to utils.dll as a project reference. So basically when I go to /bin folder of either A or B I can see utils.dll. So far so good.

Now, I have another project. LEt's call it consumer.csproj which does reference both A.nupkg and B.nupkg in the same order mentioned. Also, Utils.dll has some functions which expects certain .json files which it does expect to be at certain location.

Now, when I reference A.nupkg first, it does bring in utils.dll with it and then my consumer project knows that it needs to go to /A/lib when running code does ask for utils.dll. which was OK until when my consumer project did call some B.nupkg functionality which in turn called, utils.csproj functionality which was looking for some json files in a.nupkg/lib folder because now everytime utils.csproj is called, compiler just goes to A.nupkg folder looking for it.

Is there anything I am doing wrong here? If not, what can I do to resolve this issue

Now I

Upvotes: 0

Views: 470

Answers (2)

Lost
Lost

Reputation: 13645

From what I have learnt in my experience from portability perspective is one thing. Shipping Nuget packages is not magically streamlined for users from Nuget. If you want to ship multiple Project Dlls with a Nuget package then you have following options:

  1. One NuGet Package: This means pack multiple Dlls in one Nuget Package. And in definition of this Nuget package, explicitly copy dlls of other projects using .nuspec file.

  2. Multiple Nuget Packages: If you have to ship multiple Nuget packages then, make sure that scenario that is faced above does not happen. What I mean by that is that IF Project A and Project B are Nuget packages going out of the same solution and are using utils.dll then utils.csproj should be a .Nuget package and A.Csproj and B.csproj should reference Utils.nupkg as a package rather then project reference. This way there would not be any confusion for any consumer downstream about who is responsible for shipping and packaging utils.dll

  3. You can just turn everything into one project and that way it will produce only one Dll.

Upvotes: 0

Neville Nazerane
Neville Nazerane

Reputation: 7039

Your library projects and nugets need to be maintained in a portable format. This means that if you would need it to dynamically fetch config etc from json files, your utils project shouldn't internally try to use these json. Your utils project must instead have a function like UtilsConfig.UseJson("your json path"). This function can now be used in the start up of your consumer project. If A and B will also need specific json files, you can always use the UseJson function and the consumer project would override them if needed.

Upvotes: 1

Related Questions