views:

49

answers:

3

I wrote some classes that I use with many different projects. For example, I use Library.Controls.FlatButton.cs almost in every project. The problem is when I add this as an "existing item"; the class gets created/copied in my soultion folder everytime. And each time I edit/update the contents of that class, I have to update all the Library.Controls.FlatButton.cs files in every project folder.

I need to be able to edit a single source of FlatButton class and when I compile/build a project (that uses the class file) gets updated to the new version of that class. Question 1: Is there a way to do this?

I know that I can gather all these classes in a library project (Library.Controls) and add it to each application solution as a dependency. Question 2: Is this the only way to work from a single source of common library files? And if I do; will all the classes in the Library.Controls namespace get compiled with every application, even if I've only used this FlatButton class in the project?

Hope this is clear for you.. thanks

+3  A: 

I'd rather go with the approach of the shared library and add them as references to your client project.

If you don't want to do this. You could add the file as "Link". In Add existing item, select Add as Link instead.

pdiddy
Thanks,, just learned that.. I like to use shared libraries but if all the unused classes get compiled for each project; it doesn't seem very efficient I guess.. In this case; add as a link is better.
radgar
+1  A: 

Alternative way is to add FlatButton.cs file "As Link": alt text

Regent
thanks. didn't know that..
radgar
+1  A: 

Yes, a class library is the way to go and yes, since the whole class library will be referenced from your applications, all the classes will be available to it.

However, the fact that all the classes are available is not a bad thing, since they're in a separate class library it won't make your applications harder to understand (since the amount of code in those applications will stay the same), it might just be that you use up a little bit more hard drive space, though if you really worry about that you could put the class library in the GAC so that all apps reference the same copy of the library, though you'd better research this first to make sure that it's suitable for you.

ho1
thanks a lot. you mean all classes will be available at design-time; and even after I compile the project; those unused classes will still be compiled.
radgar
@radgar: Yes, but they're not compiled into your application, they're just compiled into the DLL that's referenced from your app.
ho1
yes I meant that. ok then. thanks.
radgar