5
votes

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:

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)

1
What is in the lib\net451 folder inside the .nupkg? I would guess the assemblies should be going in there but your .nuspec is putting them just in the lib directory. I would guess that NuGet is finding the lib\net451 directory and ignoring the assemblies that are in the parent lib directory. You also do not need the references section if all the assemblies in the lib\net451 folder will be referenced. If you are using nuget pack .csproj then you can probably just remove the files section from your .nuspec.Matt Ward
Hey @MattWard, the project references are going into that folder, but they too are not getting added as references in the child projects being created. Any other idea what might be keeping the child project from picking these up as references? Also, I tried changing the file path to target="lib\net451" and it still didn't work.pharophy

1 Answers

2
votes

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.