简体   繁体   中英

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. What I want is to use the same functions in the second project, 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"?

Use a project reference.

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. Say, Newtonsoft.Json Add a project reference from your second project to the first

Dependencies should now look like so; 依赖关系

Now within TestConsoleApp, you can add using statements to access the nuget package used in TestConsoleApp2.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM