Nuget程序包-引用的程序集不包含在项目引用中 [英] Nuget Package - Referenced Assemblies Are Not Being Included As Project References

查看:546
本文介绍了Nuget程序包-引用的程序集不包含在项目引用中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在讨论问题之前,让我快速解释一下我的目标:

我有一个用于创建的每个网站的模板项目,其中包括基类,通用页面(例如,与我们联系),有用的实用程序(异常记录)等.我想使此模板可重用和可更新.以前我使用的是Visual Studio项目模板,但是在引用所需的所有程序集时遇到了问题,因此我转向了Nuget.我的印象是这样做会更容易,并且还为我提供其他好处.

问题:

我不知道如何创建一个nuget包,该包将在包中包括所有引用(解决方案中的其他项目以及本地计算机上的dll),并使其成为安装此模板的子项目的依赖项

这是我所走的路:

a.在该项目的nuspec文件中,我具有以下内容:

<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.运行pack命令时,将使用以下命令:nuget pack {projectname} .csproj-IncludeReferencedProjects -Symbols

c.输出是两个单独的项目,一个带有.symbols,另一个没有.在Package Explorer中看起来像这样:

两个项目:

符号pkg:

因此,在这一点上,感觉就像我在做所有正确的事情.但是,一旦我在Visual Studio中创建了一个新的空Web应用程序并安装了此程序包,这些引用的程序集或项目就不会包含在引用中:

d.在Visual Studio的新(子)项目中:

我在这里打了完整的砖墙.我已经在网上搜索了好几天,但发现一堆看起来可能有帮助的东西,但使我陷入困境:

我要去哪里错了?

更新 在.net451文件夹中,它添加了所有外部项目引用.正如您在WebApplication屏幕快照中看到的那样,这些引用也未添加.
(来源: blabberjax.com )

解决方案

好吧,所以在尝试了所有阳光下的工作之后,我认为问题与我命名主项目,Nuget包和子项有关.项目具有相同的名称-(例如MyProject.csproj&包MyProject.#.#.#).

看来,这些引用可能已被Nuget程序包中具有本地../引用的MyProject.csproj文件覆盖在子项目的.csproj文件中.所以我在nuspec中将Nuget包的ID重命名为 <id>$id$.Client</id>,然后一切开始工作.

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:

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)

解决方案

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.

这篇关于Nuget程序包-引用的程序集不包含在项目引用中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆