简体   繁体   中英

Using Namespaces in Other Projects

As the screenshot demonstrates, I have a project SampleApp that uses the namespaces EDAM and Thrift . I want to replicate the functionalities of SampleApp to another project.

Do I have to include the two projects ( EDAM and Thrift ) in my other project? Can I just copy the folders instead of including the actual project files? Can I just convert them to some sort of DLL or something?

在此输入图像描述

You definitely should add references to the EDAM and Thrift projects from the SampleApp project.

To do so, follow these steps:

  1. Right click the 'References' folder in the SampleApp project.

  2. Select 'Add Reference...'

  3. On the popup, go to the 'Solution' tab.

  4. Select the EDAM and Thrift projects.

Under no circumstances should you just copy the files.

Don't copy the folders, just add references to the projects. Even if the projects are class libraries you don't want to copy the DLLs, instead you should add references, just in case your DLLs are updated:

How to: Add or Remove References in Visual Studio

If the "other" project is in the same Solution, you should be able to reference EDAM, Thrift and even SampleApp from that project much in the same way you set the references up for SampleApp.

If this "other" project will be in a new solution...I'd have to do a little research and testing.

Visual Studio project references are equivalent to referencing an assembly directly, but it has a great advantage: when you build a project, Visual Studio take cares of building its dependent projects too.

In addition, Visual Studio will prevent circular references.

There're many other pros, but it's a good summary.

Copy-pasting the code files isn't importing a namespace: this is duplicating code! And referencing the assemblies directly is a waste of time and features!

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