Introduction
There are limitation with adding custom sharepoint element at verious scope. Which can be overcome hence this article is helpfull.
Scenario
I was working with Sharepoint(2013) Web Template, for which there is no default template in visual studio. Hence i have used Module for it. I was expecting it on Farm level and i faced problem. Module are not available to deploy to Farm level feature by default.
Which element fall into which scope?
There are 4 scopes, Web (Web site), Site (site collection), WebApplication (Web application) and Farm (farm). Below i have mentioned which elements fall under which scope by default.
[Reference below]
1] Web (Web site) :- Content Type, Content Type Binding, Control, Custom Action, Custom Action Group, Custom View, Event, Field, Hide Custom Action, List Instance, List Template, Module, Property Bag, Workflow Actions, Web Template.
2] Site (site collection) :- Content Type, Content Type Binding, Control, Custom Action, Custom Action Group, Event, Field, Hide Custom Action, List Instance, List Template, Module, Property Bag, Template Association, Workflow, Workflow Actions, Workflow Association.
3] WebApplication (Web application) :- Control, Custom Action, Custom Action Group, Document Converter, Hide Custom Action, Template Association, Web Template, Workflow Association.
4] Farm (farm) :- Control, Custom Action, Custom Action Group, Hide Custom Action, Template Association, Workflow Association.
So as above in farm scope we cant deploy module, but my requitment is to push Web Template via module using Farm scope.
Trick/Fix
1] Add module in your project and click on show all files option in solution explorer at upper right corner.
2] Now you can see your module which have sample.txt, element.xml, SharePointProjectItem.spdata.
Now you just have to update "SharePointProjectItem.spdata" file. I renamed sample.txt to one.xml and edited as per my requirment.
3] (Carefully) Open SharePointProjectItem.spdata file [Do not copy past this code, just update you attributes]
<ProjectItem Type="Microsoft.VisualStudio.SharePoint.Module" DefaultFile="Elements.xml" SupportedTrustLevels="All" SupportedDeploymentScopes="Web, Site" xmlns="http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel">
<Files>
<ProjectItemFile Source="Elements.xml" Target="ContentSubsiteTemplate\" Type="ElementManifest" />
<ProjectItemFile Source="onet.xml" Target="ContentSubsiteTemplate\" Type="ElementFile" />
</Files>
</ProjectItem>
Check few attributes of this file.
a) SupportedDeploymentScopes :- You can edit it to enable diffrent scope. I edited it as below :
SupportedDeploymentScopes="Web, Site"
To
SupportedDeploymentScopes="Web, Site, WebApplication, Farm, Package"
Now it is available for me to deploy at Farm scope.
b) Type :- This attribute indiate type of element template. To push my web template, so i edited it as below :
Type="Microsoft.VisualStudio.SharePoint.Module"
To
Type="Microsoft.VisualStudio.SharePoint.GenericElement"
Now, Go to your feature and check for this module it will be visible to deploy using your feature.
Points of Interest
This is an attribute change to make it available for other scopes. Here this module now available for all scopes. This trick only showcase stuff for module and do not cover how to create/deploy Web Template.
Thanks
Hope it help, I'm happy to help.
References
https://msdn.microsoft.com/en-us/library/office/ms454835(v=office.14).aspx