I am creating a project that I will export as a Project Template, using this and this as guidance.
These are to be Sharepoint 2010 projects created using Visual Studio 2010.
What I would really like to have happen is that the user be prompted for several values (above and beyond just the solution name) when they start a new Project and select the Template I will create. I want to let them change the default names of the WebPart and the User Control from the outset, for example.
I am getting mixed signals, though, on whether this is really possible. The code below from here seems to indicate that the user/developer needs to add CustomParameters to the .vstemplate file, and then these values are what are read to replace those placeholder values. This is the "official" (MS example) code:
<TemplateContent>
...
<CustomParameters>
<CustomParameter Name="$MyParameter1$" Value="MyValue1"/>
<CustomParameter Name="$MyParameter2$" Value="MyValue2"/>
</CustomParameters>
</TemplateContent>
But if that's what really has to be done, I don't see any benefit over simply putting "TODOs" in the code, and having the users/developers do a global search & replace after opening the project.
So I'd like a "sanity check" from those in the know as to wheter this is what I need to do:
Is this what I have to do:
0) Create the project
1) Export it as a project template
2) Alter the .vstemplate file, adding something like the code above
?
That certainly seems to be the steps the "How To" is recommending. My main question is, will doing that prompt user developers of the Template for the replacement values (overwriting "MyValue1" and "MyValue2"), or will the user developers have to modify the *.vstemplate file to add the replacement vaues directly? If the latter, I don't see the benefit - locating and altering the *.vstemplate file prior to creating a new project based on the template seems far kludgier than adding "TODO" messages in the code to replace this and that value.
IOW, does the user/developer have to open the *.vstemplate file, replacing both the "Name"s and "Value"s with what he wants, such as changing something like this:
<CustomParameters>
<CustomParameter Name="$title$" Value="Replace this placeholder title"/>
<CustomParameter Name="$description$" Value="Replace this placeholder description"/>
</CustomParameters>
...to something like this:
<CustomParameters>
<CustomParameter Name="$title$" Value="A Connecticut Yankee in King Arthur's Court"/>
<CustomParameter Name="$description$" Value="Hammerin' Hank Morgan Le Fay Vincent Van Gogh Fly a Kite Runner"/>
</CustomParameters>
(assuming the template as saved by the original developer (me) has added replaceable params in the project named "$title$" and "$description$"?
For the curious who do not want to export a project as a template to see what such a *.vstemplate file might contain, here is a pretty generic one, in full:
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>SPWFTemplate</Name>
<Description>This is for starting projects to create WebForms based on existing PDFs</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>SPWFTemplate</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="SPWFTemplate.csproj" File="SPWFTemplate.csproj" ReplaceParameters="true">
<Folder Name="Features" TargetFolderName="Features">
<Folder Name="Feature1" TargetFolderName="Feature1">
<ProjectItem ReplaceParameters="false" TargetFileName="Feature1.feature">Feature1.feature</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Feature1.Template.xml">Feature1.Template.xml</ProjectItem>
</Folder>
</Folder>
<Folder Name="Package" TargetFolderName="Package">
<ProjectItem ReplaceParameters="false" TargetFileName="Package.package">Package.package</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Package.Template.xml">Package.Template.xml</ProjectItem>
</Folder>
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="key.snk">key.snk</ProjectItem>
</Folder>
<Folder Name="SPWFTemplateVisualWebPart" TargetFolderName="SPWFTemplateVisualWebPart">
<ProjectItem ReplaceParameters="true" TargetFileName="Elements.xml">Elements.xml</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="SharePointProjectItem.spdata">SharePointProjectItem.spdata</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="SPWFTemplateVisualWebPart.cs">SPWFTemplateVisualWebPart.cs</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="SPWFTemplateVisualWebPart.webpart">SPWFTemplateVisualWebPart.webpart</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="SPWFTemplateVisualWebPartUserControl.ascx">SPWFTemplateVisualWebPartUserControl.ascx</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="SPWFTemplateVisualWebPartUserControl.ascx.cs">SPWFTemplateVisualWebPartUserControl.ascx.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="SPWFTemplateVisualWebPartUserControl.ascx.designer.cs">SPWFTemplateVisualWebPartUserControl.ascx.designer.cs</ProjectItem>
</Folder>
</Project>
</TemplateContent>
</VSTemplate>