views:

383

answers:

3

This may be a ridiculous question for you C# pros but here I go. I'm a Flash developer getting started in Silverlight and I'm trying to figure out how to create a "codebase" (a reusable set of classes) for animation. I'd like to store it in a single location and reuse it across a bunch of different projects. Normally in Flash I would add a "project path" reference and then start using the code. My question is, how do I add a folder to visual studio so that I can "use" those classes in my project. I tried "Add > Existing Item" but that copied the files into my project directory.

+4  A: 

The easiest way would to create a new ClassLibrary project and build it. This will output a .dll file in a folder you can specify in the project settings menus, which you reference from every project that needs it.

Also, you can copy this .dll into the /bin/ folder of your project - this will do the same thing for this specific project, but when you start the next one you can change some details in the codebase library without breaking the first project.

Tomas Lycken
Ah, I have to compile it first!
Typeoneerror
Should I use the .dll that gets create in /Bin/Debug or is there a different one I should use?
Typeoneerror
No, the one you get in /Bin/Debug is fine. However, I'd recommend copying it to somewhere else before referencing it, to avoid version issues if you change something in the codebase project.
Tomas Lycken
+1  A: 

In Solution Explorer, right-click on the project node and click Add Reference.

In the Add Reference dialog box, select the tab indicating the type of component you want to reference. (for instance for a class library a dll)

Select the components you want to reference, then click OK.

AJM
+2  A: 

The solution described by Tomas (adding a reference to a dll binary) is the correct solution to this problem; better than referencing the source code and compiling it into each project.

But just for extra information, if you ever do need to add a source code file to your Visual Studio project without having it make a copy of the file you can use the following steps:

  1. Right click on your project in Solution Explorer and select Add -> Existing Item.
  2. Navigate to the location of the source code file and select it.
  3. On the "Add" button in the dialog window there is a drop down arrow. Click this and select "Add as Link".

This will allow you to use this source code file in your project without having VS make a copy of the file.

KeithMahoney
Thanks, Keith. Sounds like I have everything I need now. Cheers!
Typeoneerror