Wednesday, March 30, 2011

Deploying solutions to a specific Web Application

SharePoint solutions (non-sandboxed) can be deployed at two scopes;
  • Globally
  • Web Application

SharePoint has the annoying habit of forcing you to deploy globally whenever possible. When you try to deploy a global solution to a specific url you get the following message:
- This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application.

In almost all cases I want to deploy my solution to a single web application. This makes creating reusable deployment scripts much easier. It also adds logic to your deployment scenario's and farm solution overview in Central Administration.

Update
Another important reason to deploy to a single web application is that upon deployment, retraction or updating of your solution you can avoid restarting all application pools. This limits downtime, especially when you are not alone in your farm:
Avoid creating a lot of global SharePoint Packages and try instead to provision as much as you can to specific Web Applications. Every time you touch a global SharePoint Package all Applications Pools will be stopped/recycled. Although there are some scenarios when you can’t avoid creating global SharePoint Packages, you should try to avoid them
An interesting post by Waldek on the subject.
/Update

The trick is fooling SharePoint into registering your solution as a web application scoped solution. SharePoint checks wether there are items which have to be deployed to a specific web application when your solution is added to the solution gallery. One of the elements that SharePoint checks for are safe control entries. These have to be merged into a web.config for a specific web application. The easiest way to force deployment to a specific web application is adding a dummy safe control entry to your package.

Here is how you do that:



1. Double click the package
2. Open the manifest
3. Edit the options
4. Add you dummy data. In my solution I added the following:

<Solution xmlns="http://schemas.microsoft.com/sharepoint/"> 
 <Assemblies>   
  <Assembly Location="SharePointProject1.dll" DeploymentTarget="GlobalAssemblyCache">     
   <SafeControls>       
   <SafeControl Assembly="SharePointProject1,Version=1.0.0.0, Culture=neutral, PublicKeyToken=****************" Namespace="SharePointProject1" TypeName="*" />     
   </SafeControls>   
  </Assembly> 
 </Assemblies>
</Solution>

That's all there is to it. This solution will now only deploy at the web application scope!


Note: For MOSS this works the same. How to add the entry is a bit different depending on your wsp packaging tool. With STSDEV you can add the entry to the SolutionConfig.xml.

21 comments:

  1. excellent post, very valuable info.. not many people divin deep into this topic with the rite answer, thanks.

    ReplyDelete
  2. Or you can just open the package, switch to Advanced, add an additional assembly (the solution for example) and mark Deployment Type "Web Application"

    ReplyDelete
  3. Thank you for a good and working advice :)

    ReplyDelete
  4. Check out the below link too.

    http://www.fewlines4biju.com/2012/05/this-solution-contains-no-resources.html

    ReplyDelete
  5. This broke my solution. Use with caution.

    ReplyDelete
  6. You could click in the solution explorer on your project you want to deploy. In the little properties window you can just change the Assembly Deployment Target from GlobalAssemblyCache to WebApplication and you will have the same effect.

    ReplyDelete
  7. Thanks a lot!!

    ReplyDelete
  8. Deployments to the /bin directory are no longer supported for Full Trust Assemblies... so non-GAC deployments may be a bad idea -- YMMV..

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. I really liked the way you highlighted some really important and significant points about Deploying solutions to a specific Web Application. I would love to know more about this so posting more would be appreciated.

    Best Pediatric Websites - Kids Website Design 4 Pediatricians in America.

    ReplyDelete
  14. but for me when i do this, am getting this error:

    Error 1 Error occurred in deployment step 'Add Solution': Error: Cannot find this file specified in the manifest file: DummySharePointProject1.dll
    0 0

    ReplyDelete
  15. this is not working for me in my SP 2013 full trust soln,
    please help , how to proceed.

    ReplyDelete
    Replies
    1. Hi. This is quite an old article, based on practices used in the SP2007 era.

      From an earlier anonymous comment:

      You could click in the solution explorer on your project you want to deploy. In the little properties window you can just change the Assembly Deployment Target from GlobalAssemblyCache to WebApplication and you will have the same effect.

      Delete
  16. It’s a very informative and helpful article, thank you for sharing!


    SEO Services

    ReplyDelete
  17. Madaalarqam offers Mobile Application development servicess for business websites to Application Developmentportals we design & develop web applications

    ReplyDelete
  18. I read this article. I think You put a lot of effort to create this article. I appreciate your work.
    thesis Writing Service

    ReplyDelete

Rating