views:

54

answers:

1

Dear Stackoverflow,

I have written quite a bit of code of the past few years. I've been using the Visual Studio Development Environment for my C# code, but I wouldn't call myself an advanced user of Visual Studio. I can create projects, create source code, and build/debug the project. I don't use many of the advanced features of the IDE, so perhaps there is a simple way to do what I'd like.

My code is often reused - especially thing like filter tools, custom controls (plots/etc) and some communications code (COM/USB/etc). Every time I create a new project, I end up importing a lot of code that I'll need. This code is copied to the new project directory. If I end up editing that code in some way, I then need to update all of the other versions of that file in my others projects. I'm always having to verify that the code that I am importing is the 'latest and greatest'.

I know it is possible to add code to your project by link, and then you'll update the source file, but I'm curious if there is a better way. My example of a 'better way' is the Allegro Lisp compiler. When you start up Allegro, all of your code is loaded into Allegro, and is instantly available. Then you can start hacking around on anything you'd like, and have access to all of your previous code. When you edit something, and compile it, it is instantly usable in the rest of your projects as well. (Usually even if the program is open!) Perhaps this is something fairly unique to Allegro Lisp?

Are there any ways to do something like this in C#? I'd like to still be able to keep separate projects, but I'd like to share source between them and not have to worry about versions getting out of sync. What does everyone else do when they would like to recycle code?

Thanks,

Giawa

+2  A: 

Take some time, work through the code and create different projects, for the likes of filters, plots. Give meaningful namespaces to these assemblies, put the code under source control, use external references to these repos in the source control of your main project, or only import the generated assemblies.

Copying code will lead to errors due to not correcting an error in one place, but correcting it another. Use source control, it's gold.

Femaref
When I end up creating these projects (for the plotter, filtertools, etc) what do they compile to? Will I end up compiling them to a managed dll and then including them in my future projects? How do I share this code with my new projects?
Giawa
they will compile to class libraries - dlls. They will be ending up as managed dlls, and those can be referenced in new projects. The key is not to share the code (because that isn't necessary, only the dll is needed) but the assembly; Never ever have code for one class in two places, one time you will miss an edit and it messes everything up. Keep the code in one place and only use the compiled assemblies.
Femaref
Ok fair enough. The only thing I worry about is having a bunch of dlls that my program has to link to. Can the C# compiler take what is needed out of the managed dll and provide a stand-alone application?
Giawa
No, that's not possible. Just distribute the assembly with the program, it won't hurt (unless you are constrained by hdd).
Femaref