当Nuget包是必需的输出时如何在同一解决方案中引用相关项目 [英] How to reference related projects in the same solution when Nuget packages are the required output

查看:47
本文介绍了当Nuget包是必需的输出时如何在同一解决方案中引用相关项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在同一解决方案中引用项目的最佳方法是什么.您是使用添加引用"功能创建引用还是管理 nuget 包"并下载某个已发布版本.每个项目依次生成一个 Nuget 包,可供其他解决方案引用.

I was wondering what's the best approach to reference a project in the same solution. Do you create the reference using the 'Add reference' feature or do you 'manage the nuget package' and download a certain published version. Each project in its turn will result in a Nuget package which can be referenced by other solutions.

所以对于其他解决方案,这很清楚.他们使用 Nuget 创建引用,但是解决方案内部的项目引用如何?

So for other solutions it's clear. They create the reference using Nuget, but how about intrasolution project references?

推荐答案

最好的方法是在引用的项目上创建 NuGet 依赖项.

The best approach is to create a NuGet dependency on the referenced project.

假设您的解决方案中有两个项目:

Suppose you have two projects in your solution:

Solution
    | ProjectA
    | ProjectB

ProjectA 引用了 ProjectB,并且它们都是 NuGet 包(都有 nuspec 文件).如果要创建依赖于ProjectB的包ProjectA,在ProjectA的根目录执行:

ProjectA has a reference to ProjectB and both of them are NuGet packages (both have nuspec files). If you want to create a package ProjectA that depends on ProjectB, execute in the root of ProjectA:

NuGet Pack -IncludeReferencedProjects

在 IncludeReferencedProjects 存在的情况下,NuGet 将遍历解决方案中的引用项目,寻找 nuspec 文件(表示项目是包).如果找到 nuspec,则将其添加为依赖项.

In the presence of IncludeReferencedProjects, NuGet will traverse the referenced projects inside the solution, looking for nuspec files (that indicates that a project is a package). If a nuspec if found, it is added as a dependency.

在这个例子中,它会在 ProjectB 中找到一个 nuspec 文件,并将其添加为依赖项.当您安装 ProjectA 时,也会安装 ProjectB,并将其添加为参考.

In this example, it will find a nuspec file in ProjectB, and add it as a dependency. When you install ProjectA, ProjectB will also be installed and it will be added as reference.

这篇关于当Nuget包是必需的输出时如何在同一解决方案中引用相关项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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