Visual Studio equivalent Delphi "search path"

I created the C # class defined in the .cs file that I use in an existing project. Let me call it the magic class defined in Magic.cs.

Now I am working on a new project, and I would like to create an instance of this class in my new project.

How can I refer to this class in my new project without actually copying the file to the new project directory?

In Delphi, the answer will be "add the location of the class definition to your search path." This is a clumsy stupid question, but I can't find a good answer anywhere.

Here is what I tried:

1 - Project-> Properties-> Reference Paths-> Add the location of my class (class references have not yet been resolved)

2 - Right-click on the project โ†’ "Add existing item" โ†’ select a class (creates a new separate copy in the project folder)

3 - Right-click on the project โ†’ โ€œAdd Linkโ€ โ†’ make sure that it is expecting a compiled target, such as a DLL.

see also

+4
source share
4 answers

You are in a whole new world. There is no equivalent.

If you want to share a class without copying it, you create a class library and create your own class in this library. Then you refer to this built library from your project.

You can add a class library to your solution and a link to the project during development. Class libraries act like BPLs if you have ever used them.

Once you have a class library, you can share the library between your solutions. There are two ways to do this: by creating a library and sharing a binary file - or by including a class library project in your solution. At first, you probably want to go with the last method until you get it, but as soon as the situation is big enough and your general code goes down, it is better to refer to a pre-built binary.

There is a learning curve here, but at the end of the day you will feel better.

Good luck.

+7
source

Joseph, Visual Studio does not provide this function, so it must reference each class manually. In any case, to avoid creating a copy of your class every time it is included in a new project, you should use the Add existing item option by selecting add as link .

alt text

+4
source

Sorry, but you canโ€™t do this, itโ€™s good to know that Delphi provides such a tool, but Visual Studio may not do this, because at the end of the day it can lead to a mess of related files. Visual studio likes to organize related files in one project or solution.

If you want your previous class to be accessible as described above, you have only two options.

1) Just copy the existing .cs file to the project directory (by right-clicking on the project โ†’ โ€œAdd existing itemโ€ โ†’ select a class)

2) Add the project to your solution (right-click on the Solution โ†’ Add โ†’ Add Existing Project ... โ†’ Select the project file from the file browser), and then add the refrence class (right-click on the project โ†’ โ€œAdd Linkโ€ โ†’ Projects tab Select your project). It will automatically make a link to the .dll.

3) And the last option is to compile your class into a .dll, and then add a link to it in Project.

Luck

+2
source

You want to reference either the compiled .Net assembly (dll in this case) or another project that is part of your solution. If you have a source, you add the library project to your solution. Then add the library project as a reference to the project that uses it. When it compiles, it will copy the dll to your build directory. Using this method is good because you can execute code in the library when using the debugger.

+1
source

Source: https://habr.com/ru/post/1336249/


All Articles