Junior Programmer
Junior Programmer

Reputation: 379

Confusion with Visual Studio 2010 Directives

I have two Visual Studio 2010 projects named OldProject and NewProject, both full of .cs files.

I want to use OldProject's OldFile.cs file in NewProject's NewFile.cs file.

At the top of NewFile.cs, I wrote using OldFileNamespace; to no avail. I tried setting reference paths to no avail. I tried copying OldFile.cs into NewProject to no avail, since there are many using directives in OldFile.cs which NewProject does not recognize.

What else can I do?

Upvotes: 0

Views: 61

Answers (2)

phadaphunk
phadaphunk

Reputation: 13313

You simply need to refer the project to your new project.

If for some reason it doesn't work (it should work), create a new class library, add the .cs class in it and refer to it. It does not change anything. But if the classes are only used to be refered to another project, this is a good practice.

myClassLibrary.dll

Don't forget to include it with the using keyword once you added the reference.

Create the class library

enter image description here

Once you build it, find where you .dll is.

enter image description here

Add the reference to your project

enter image description here

Don't forget the using statement

enter image description here

Upvotes: 3

David L
David L

Reputation: 33873

You most likely need to include the reference to OldProject as a PROJECT level reference.

Right click your project and click "Add Reference".

Use browse and browse to the file location of OldProject.dll. Add it.

You should now be able to include and access the namespace for OldProject.

Upvotes: 1

Related Questions