Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget Package - Referenced Assemblies Are Not Being Included As Project References

Before I go into the problem, let me quickly explain my goal:

I have a template project that I use for each website that I build, which includes base classes, common pages (e.g. contact us), useful utilities (exception logging), etc. I want to make this template reusable and updatable. Previously I was using a Visual Studio Project Template, but I had issues in referencing all of the assemblies I needed, so I turned to Nuget. I was under the impression that this would be easier, and also provide me with additional benefits.

The problem:

I can't figure out how to create a nuget package that will include all references (both other projects within the solution and dlls on my local machine) in the package, and also make them dependencies in child projects that install this template.

This is how far I've gotten:

a. in the nuspec file for the project, I have the following:

<references>
  <reference file="AjaxControlToolkit.dll" /> <!-- nuget dependency -->
  <reference file="BjxContacts.Shared.dll" /> <!-- project dependency -->
  <reference file="SomeExample.exe" /> <!-- exe local file dependency -->
  <reference file="SomeOther.dll" />  <!-- dll local file dependency -->
</references>
<files>
    <file src="bin\*.pdb" target="lib" /> 
    <file src="bin\*.dll" target="lib"/>
    <file src="bin\*.exe" target="lib"/>
    <file src="bin\*.xml" target="lib"/>
</files>

b. When I run the pack command, I use this: nuget pack {projectname}.csproj - IncludeReferencedProjects -Symbols

c. The output is two separate projects, one with .symbols, and one without, which looks like this in Package Explorer:

both projects: enter image description here

symbols pkg: enter image description here

So at this point, it feels like I'm doing everything right. But then, once I create a new empty web application in Visual Studio, and Install this package, none of these referenced assemblies or projects are included under references:

d. In new (child) project in Visual Studio: enter image description here

I've hit a complete brick wall here. I've been searching the web for days, and I found a bunch of things that look like they might help, but bring me down dead ends:

  • https://github.com/dittodhole/powershell-nuget-packager
  • Build NuGet Package automatically including referenced dependencies
  • NuGet Packaging and referencing dll's
  • Why doesn't nuget include the referenced project when packing?

Where am I going wrong?

Update In the .net451 folder, it adds all the external project references. As you can see in the WebApplication screenshot though, these references aren't added either. enter image description here
(source: blabberjax.com)

like image 716
pharophy Avatar asked Oct 31 '22 05:10

pharophy


1 Answers

Okay, so after trying just about everything under the sun, I think the issue had to do with that I was naming the master project, Nuget package, and child project the same names - (e.g. MyProject.csproj & package MyProject.#.#.#).

It looks like the references may have been getting overwritten in the child project's .csproj file by the MyProject.csproj file from the Nuget package, which had local ../ references. So I renamed the Nuget package's id in the nuspec to <id>$id$.Client</id>, and then everything started working.

like image 160
pharophy Avatar answered Nov 17 '22 22:11

pharophy