Marty
Marty

Reputation: 39466

How do I recycle code in Visual Studio with XNA?

I'm relatively new to both C# and Visual Studio, using XNA Game Studio. All I want to do is take some folders from a current project which contain .cs files and utilise those files in a new project, but it's proving to be a little trickier than I am used to with Flash/ActionScript.

At the moment it seems like I need to use this process over and over until all the files I want are part of the current project:

enter image description here

Upvotes: 1

Views: 81

Answers (1)

dodexahedron
dodexahedron

Reputation: 4657

There are a couple ways to do what you are asking. One would be to compile the classes you want to reuse into a class library project and then add a reference to that class library in your new project.

Another way, if you just want copies of the files themselves in your new project, is to use Add > Existing Item, in the menu you have above. Then, find the files you wish to add to your project in the dialog that comes up, and you'll be all set.

I would suggest, if these are going to be common classes that do not get modified on a per-project basis, that you use the class library option, rather than just copying your code files.

Edit:

To make it clear, in Visual Studio > File Menu > Add Project > Class Library Project name it Common. Then create a class say MartysHelper for example and put a method in this calass called Public String HelloWorld() and compile. Then right click the Gamer1 Project and select Add Reference > Projects > choose the Common project. Now in Game1 and/or any other project(s) you can re-use the Common.MartysHelper class.

Upvotes: 2

Related Questions