Skip to main content
GameDev.net gamedev.net
🔒 Locked

HELP! - Common Code for Multiple Projects in .Net

Started by Telamon Dec 30, 2003 at 2:46 PM 7 replies 250+ views
Original Post
Telamon
Telamon
HELP! I am writing a client/server game in C# where the client and the server are different projects within the same solution (so I can easily swap back and forth between them). The problem is that the two projects have a certain amount of common code (for dealing with things like network packet formats and other game constants) that I don''t want to have separate copies of in both projects. How can I have one copy of these common files and have both projects reference it? I''ve looked in the help that comes with Visual Studio, but this kind of thing is hard to look up. ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Coding: http://www.stanford.edu/~jjshed/coding Miscellany: http://www.stanford.edu/~jjshed
antareus
antareus
Yeah make a class library project that has the shared code in it, then add references to it from other projects.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Promit
Promit
Why can''t you just have the same source file in both projects?

I don''t get the problem...(although to be fair, I haven''t used VS.NET in months).
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Xai
Xai
sharing common code is the primary reason why libraries exist in the first place ... simply create a library project ... but the reason this eludes some, is that microsoft REMOVED the library project wizard from the Standard version of the compilers ... so it says in "Beggining visual C#" anyway ... I don''t know cause I don''t have that version ...

the other reason to sue libraries is simply to significant chunks of your code into related sections, so you don''t have to load, compile, or be bothered with your "rendering engine" code, when youre writing your "game", or your "sound engine" code. Using libraries you compile and debug the seperate modules seperately ... and then just "use" them where needed.
Telamon
Telamon
Make a library?! YUCK!

Look. I just want to share some .cs files between projects.

I don''t want to make two copies of the same files because then I will have to make any changes to both of them.

I don''t want to spend a lot of effort on this. Is a class library really the best I can do?

When you''re using MSVC++ you can have multiple projects in the same solution reference the same set of files. Why can''t I do this in C#?


----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------

Coding:
http://www.stanford.edu/~jjshed/coding

Miscellany:
http://www.stanford.edu/~jjshed
antareus
antareus
Whats wrong with a library? From a physical organization standpoint it makes far more sense over referencing files in other folders. That is to say, when I see "Server.cs" in the project explorer, I think "that file is going to be in the project folder''s root." When I need to hunt down the Server.cs file (say, for backup purposes) and it isn''t there, I''ll be left scratching my head.

Note: I just tried adding a file from one project into another and it works just fine so I don''t know what your problem is anyway.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Arild Fines
Arild Fines
When adding the file to the project, click the little arrow next to the Open button.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Telamon
Telamon
Hey, Arild Fines to the rescue again! Thank you very much! That''s exactly what I wanted!

Class Libraries == Yuck because I don''t know anything about them, don''t have reference material, and am more interested in writing a game than writing super structured code. Maybe they are transparently easy to work with. I don''t know. I played with them for five minutes and it looked like there were going to be some problems. Booooooo.


----------------------------------------
Let be be finale of seem, seems to me.
----------------------------------------

Coding:
http://www.stanford.edu/~jjshed/coding

Miscellany:
http://www.stanford.edu/~jjshed
Arild Fines
Arild Fines
quote:
Original post by Telamon
Hey, Arild Fines to the rescue again!

Again?

I have to concur with the majority here, though: Spend the time required to learn about libraries. It will pay out in the end.

--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.