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

我只是一个虾纸丫 提交于 2020-01-14 17:51:32

问题


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:

symbols pkg:

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:

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.
(source: blabberjax.com)


回答1:


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.



来源:https://stackoverflow.com/questions/36796591/nuget-package-referenced-assemblies-are-not-being-included-as-project-referenc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!