简体   繁体   English

在同一解决方案中使用从一个项目到另一个项目的依赖关系

[英]Use dependency from one project to another in the same solution

Is it a way of using a dependency from a project to another while they are in the same solution?当他们在同一个解决方案中时,这是一种使用从一个项目到另一个项目的依赖关系的方法吗? For example:例如:

ComputerVisionProject (solution):
    1. ComputerVision.FaceRecognition
    2. ComputerVision.Core
    3 .ComputerVision.UI

In the first project: ComputerVision.FaceRecognition, I install a nugget, for example, "OpenCV" and I can use all the functions from it with "using OpenCV", but only in the ComputerVision.FaceRecognition project.在第一个项目:ComputerVision.FaceRecognition 中,我安装了一个块,例如“OpenCV”,我可以通过“使用 OpenCV”使用它的所有功能,但只能在 ComputerVision.FaceRecognition 项目中使用。 What I want is to use the same functions in the second project, ComputerVision.Core.我想要的是在第二个项目 ComputerVision.Core 中使用相同的功能。 but I don't want to install again the nugget, and seems that only "using OpenCV" doesn't work (even if I add the entire project as a reference to the second one) Is it possible to make another type of reference or something like: "using ComputerVision.FaceRecognition.OpenCV"?但我不想再次安装金块,而且似乎只有“使用 OpenCV”不起作用(即使我将整个项目添加为对第二个项目的引用)是否可以进行另一种类型的引用或类似:“使用 ComputerVision.FaceRecognition.OpenCV”?

Use a project reference.使用项目参考。

https://docs.microsoft.com/en-us/visualstudio/ide/managing-references-in-a-project?view=vs-2019 https://docs.microsoft.com/en-us/visualstudio/ide/managing-references-in-a-project?view=vs-2019

To test;去测试; create a new solution with two projects within it.创建一个包含两个项目的新解决方案。 Within one project, add a nuget package.在一个项目中,添加 nuget package。 Say, Newtonsoft.Json Add a project reference from your second project to the first说,Newtonsoft.Json 将第二个项目的项目引用添加到第一个

Dependencies should now look like so;依赖关系现在应该是这样的; 依赖关系

Now within TestConsoleApp, you can add using statements to access the nuget package used in TestConsoleApp2.现在在 TestConsoleApp 中,您可以添加 using 语句来访问 TestConsoleApp2 中使用的 nuget package。

eg;例如;

using System;
using Newtonsoft.Json;

namespace TestConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var output = JsonConvert.SerializeObject(new ExampleObject() { field = "value" });
            Console.WriteLine(output);
        }
    }

    public class ExampleObject
    {
        public string field;
    }

}

When run outputs {"field":"value"}运行时输出 {"field":"value"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在同一解决方案中将一个项目的照片文件用于另一个项目 - Use photo file from one project to another project in the same solution 在同一解决方案中使用另一个项目的引用 - Use reference from another project at the same solution 一个项目的class在同一个方案下如何在另一个项目中使用? - How to use a class of one project in another project under the same solution? 将服务引用从一个项目复制到同一解决方案中的另一个项目 - Copy service reference from one project to another project in same solution 在同一解决方案中从另一个项目中的一个项目打开xaml页面 - Open a xaml page from one project in another project in the same solution 将用户控件从一个项目复制到同一解决方案中的另一个项目 - Copy User Control from one project to another within same solution 如何在同一个解决方案中将一个项目的功能包含到另一个项目中? - How to include functionality from one project into another in the same solution? 绑定到同一解决方案中另一个项目的属性 - Bind to property from another project in same solution 解决方案中从一个项目到另一个项目的数据传输 - Data transfer from one to project to another in a Solution 在同一项目中使用另一种形式的方法? - Use a method from one form in another, in the same project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM