How to reference related projects in the same solution when Nuget packages are the required output

无人久伴 提交于 2019-12-22 04:33:24

问题


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.

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


回答1:


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 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

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.

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.



来源:https://stackoverflow.com/questions/17135689/how-to-reference-related-projects-in-the-same-solution-when-nuget-packages-are-t

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