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

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

问题描述

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

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

问题:

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

这是我已经走了多远:

一个.在项目的 nuspec 文件中,我有以下内容:

<references><参考文件="AjaxControlToolkit.dll"/><!-- nuget 依赖项--><参考文件="BjxContacts.Shared.dll"/><!-- 项目依赖--><参考文件="SomeExample.exe"/><!-- exe本地文件依赖--><参考文件="SomeOther.dll"/><!-- dll本地文件依赖--></参考><文件><file src="bin*.pdb" target="lib"/><file src="bin*.dll" target="lib"/><file src="bin*.exe" target="lib"/><file src="bin*.xml" target="lib"/></文件>

b.当我运行 pack 命令时,我使用这个:nuget pack {projectname}.csproj - IncludeReferencedProjects -Symbols

c.输出是两个独立的项目,一个带有 .symbols,一个没有,在 Package Explorer 中如下所示:

两个项目:

符号包:

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

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

我在这里撞到了一堵完整的砖墙.我已经在网上搜索了好几天,发现了一堆看起来可能会有所帮助的东西,但让我陷入了死胡同:


  • (来源:blabberjax.com)

    解决方案

    好的,所以在尝试了几乎所有事情之后,我认为问题与我命名主项目、Nuget 包和子项目有关项目名称相同 - (例如 MyProject.csproj & package MyProject.#.#.#).

    看起来,子项目的 .csproj 文件中的引用可能已被 Nuget 包中的 MyProject.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天全站免登陆