Prevent SharePoint solutions from getting Deployed Globally

We must have noticed that for certain solution packages (.wsp), SharePoint only provides the option to Deploy it globally. This is a big drawback for applications that were meant to target certain Web Applications only.Due to the fact that the wsp is deployed globally, an IIS Pool recycle will be performed bringing down all the WebApplications, even though the current solution package (.wsp) was targeting only some of them (or even one of them).

To avoid this, simply follow the following steps:

=> In Visual Studio load your project.
=> Open Solution Explorer.
=> Double Click on the Package.package.
=> Once it’s opened, click on the Advanced option of this package
=> The Additional Assemblies screen will show up. Then, click the option, “Add Existing Assembly“. [Note: This option is valid only if your solution package does not depend on multiple assemblies and you can just add the current project’s dll. Otherwise, click on “Add Assembly from Project Output“.]

=> If you have selected the first option, “Add Existing Assembly” then, select the source path, of your current dll.
=> If you have selected the option, “Add Assembly from Project Output” then you have to select the source project instead of just a dll.
=> The location field will be automatically updated.
=> Leave the deployment target at GlobalAssemblyCache.
=> Copy the name of the dll from the Location field without “.dll” part.
=> Under SafeControls, Click to add a new item.
=> Double-Click the Namespace field and paste the item you just copied. Do the same for Assembly Name field.

=> Click OK to close the window.
=> You should now be able to see the following screen.

=> Select your project in Solution Explorer, press F4 and set “Include Assembly In Package” as False.

Finally, deploy your solution and check the same in Central Administration. You can now see that your wsp has been deployed to a given Web Application only.