Anyone know the best way to reference functions in a solution to be used for any/all other solutions (web parts, application pages, timer jobs, etc)?

I have several small modules of code that I've copied to multiple solutions that I'd prefer to maintain in one solution that can be called from other solutions.

I don't know the best way to do this.

Please provide step-by-step instructions or a link that has that.


What I've discovered so far...

Option 1: I found instructions on how to Creating a Custom ASP.NET (ASMX) Web Service in SharePoint 2010, but I've been told that's not the most efficient way to reference functions in another solution and that there's a performance hit for that.

Option 2: I also found instructions on Working with Assemblies in the GAC, but I don't know if that's the most efficient way to do this either.

I know Option 1 works. I've tried it. I like this option because I ONLY have to redeploy the web service after making updates to it, NOT the calling solutions. I just don't think it's the most efficient method.


The best way is to create a class library project and add that project as references to other solutions.

Now you just need to change/add the common project in a single place.

Another option is to have a single visual studio solution which has multiple SharePoint projects. Also add the class library project into the same solution. This way you need to only open on Visual Studio instance.

  • SharePoint 2010 doesn't have a class library project sir. My code uses SharePoint libraries. The only class library project i see is under Windows. Would that work? Do you have references? Link to show how to?
    – jpollar
    Mar 19 '15 at 13:50
  • Yes. It will produce a DLL, which you can refer in your SharePoint projects. Mar 19 '15 at 13:50
  • If I update the code in the class library, will I need to re-deploy all of my solutions? I'm guessing yes, which would uber suck!
    – jpollar
    Mar 19 '15 at 14:09
  • How is that any different from any other 3rd party DLL or Javascript library like jQuery? If they update the code and you upgrade to it, there is the potential your code breaks as a result. You need to think about breaking changes and things like that in your library or introduce methods with different signatures so you don't break your other projects. Mar 19 '15 at 14:52
  • Maybe this isn't the best way to go about doing it then. Would a deployed web service that can be called from other solutions work better? Is that even possible?
    – jpollar
    Mar 19 '15 at 15:07

If you want to add a custom library into a sharepoint project, you have to add the reference into the package.package, click on the Advanced tab and add your Existing assembly. After that add the reference to the solution, and deploy


  • Marco...thanks...but I'm going to need someone to send me step by step instructions. I don't even think I'm creating the class library and deploying it correctly. Even a simple "hello world" would be good at this point.
    – jpollar
    Mar 19 '15 at 16:25
  • creating an example, just give me some time :p
    – Marco
    Mar 19 '15 at 17:59

I do what Amal has mentioned above. I have a SharePoint solution called common which has my common class library project as as a reference and is also setup as an additional assembly under the advanced tab of the package.

So if I update the common code I ONLY need to deploy the common solution, all of the other solutions will automatically use the new code after the common solution is deployed without having to deploy all of the other solutions.


Here are some links to help you get around in visual studio regarding solutions, projects and managed references:

  • How are you referencing "common" in your other solutions? I don't know how to do that.
    – jpollar
    Mar 19 '15 at 16:14
  • It's in it's own project, so in my other solution I add the project to the solution and then add that project as a reference. I'm not trying to be rude but this is like coding in visual studio 101. Mar 19 '15 at 18:47
  • I've added some links to my answer that should help you out in visual studio. Mar 19 '15 at 18:50
  • Steve...it's fine. I can be an absolute ass sometimes...trust me. So...how is your suggested method in any way better than putting all of my modules in a web service? If I needed to update what those modules return, I'd only have to redeploy the web service. Is one way better than the other?
    – jpollar
    Mar 19 '15 at 19:05
  • i assume you are calling the webservice server side, if so, then there will be a performance penalty because of the remote call. Mar 19 '15 at 19:46

You have to answer two main question here:

  1. How frequently you plan to modify Common part?
  2. Will it be shared with other(ppbly remote) developers?

What we do in our development (example):

  1. CommonProject
  2. BusinessProject1
  3. BusinessProject2
  4. BusinessProject3

Each BusinessProject[i] a single solution that includes CommonProject.dll (cause business projects development speed can vary and we don't wanna support new features in old releases - so not project reference but rather external library reference.

CommonProject is based on an "Empty SP farm solution" project template, cause we not only have common server-side code, but also client-side (javascript), resources (14 hive images, resx-files, css, ...). It also include some 3d-party dependency assemblies that we wanna put in GAC.

  • 1. Hardly ever 2. No I know how to reference 3rd party DLLs. I do it all the time. What I don't know how to do is create my own and reference them. I can never seem to be able to call the functions in a DLL that I create.
    – jpollar
    Apr 2 '15 at 14:41
  • When you try, what exceptions do you see?
    – dbardakov
    Apr 2 '15 at 14:44
  • None. I'm not able to reference the classes at all. I don't bother building knowing that it can't see the variables or functions I'm trying to reference.
    – jpollar
    Apr 2 '15 at 14:57
  • This is why I asked for step-by-step instructions. I don't know what F I'm doing.
    – jpollar
    Apr 2 '15 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.