views:

488

answers:

4

I have a few 'helper' style extension methods I use quite regularly now (they are mostly quite simple, intuitive, and work for good not evil, so please don't have this descend into a discussion around whether or not I should use them). They are largely extending core .NET CLR classes.

Currently, I have to copy the 'ExtensionMethods.cs' file that holds my extension methods to each new project within a solution to be able to use them in multiple projects.

Is it possible to define an extension to work over multiple projects within a solution, or wrap them in an 'extensions' dll, or are they confined to the scope of project?

EDIT Whilst the 'dedicated project' answers are perfectly valid, I chose marxidad's as I prefer the approach he gives. Thanks for all the answers so far, and I have upmodded them all, as they were all good answers

+3  A: 

The best approach is to put them all in a single project and create a DLL. You can then include that project as a project reference or include the DLL as a binary reference (probably the better choice).

Scott Dorman
+2  A: 

You could put your extensions in a separate project, and include that project to every new solution you're making.

Just be careful about versioning, e.g., when other applications try to make changes to your extension project then all the projects that use that method should be retested.

Scott Dorman is correct in his post too: if you don't want them changed you can compile them as a DLL library which you include in your new projects (as opposed to including an uncompiled project).

Jon Limjap
+1  A: 

Create a project for your extensions to the .NET platform, and reference that one project in each of your application projects. It goes without saying: any and all platform stuff, and only platform stuff, goes in that one project; application stuff goes in your application projects.

You might also look into various platform libraries out there, such as Umbrella, which offer suites of extensions to the base platform.

Justice
+8  A: 

If you don't want to create a whole project just for the extension methods, you can link the same file into separate projects without copying the file:

  1. In Solution Explorer, select the target project.
  2. Select the Project menu.
  3. Select Add Existing Item.
  4. In the Add Existing Item dialog box, select the item you want to link.
  5. From the Open button drop-down list, select Add As Link.
Mark Cidade
I've been doing that as well for years, save me a lot of trouble compare to using a shared assembly
faulty