Friday, August 6, 2010

Packing and Deploying Custom Templates in Visual Studio.

Packing and Deploying Custom Templates in Visual Studio.

Once you have created your own template (Creating project templates for Visual Studio) its time for its distribution.
To make the template appear into the “New Project” window it is important to place the zip file of the template to correct location. This can be done manually and through .vsi (Visual Studio Installer) file. Also .vsi file will be helpful for distribution of your template to different community or users.

To create the .vsi file for your template follow the below steps
1)Create a file in the project folder with .vscontent extension having the below code

[sourcecode language="html"]

<VSContent xmlns="http://schemas.microsoft.com/developer/vscontent/2005">
<Content>
<FileName>MyFirstWebProjectTemplate.zip</FileName>
<DisplayName>My First Web Project Template</DisplayName>
<Description>A project template created for this example.</Description>
<FileContentType>VSTemplate</FileContentType>
<ContentVersion>1.0</ContentVersion>
<Attributes>
<Attribute name="ProjectType" value="Visual C#"/>
<Attribute name="ProjectSubType" value="CSharp"/>
<Attribute name="TemplateType" value="Project"/>
</Attributes>
</Content>
</VSContent>

[/sourcecode]

File Name: Name of the file that needs to be deployed. Here it is our custom template zip file.

DisplayName: Name that appears in the deployment wizard

Description: Small description regarding the component that is being deployed. It appears as tooltip for the Display Name

FileContentType: Type of the file being deployed. It can be Toolbox Control, Code Snippet, VSTemplate etc.

ContentVersion: Version of the content being deployed. Let be 1.0

ProjectType: Type of the project. It can be Visual Basic, Visaul C#, Visual J# etc

ProjectSubType: Type of subcategory to which the template would be placed. It can be CSharp, JSharp, Visual Basic etc

TemplateType: Type of the template that is being deployed. It can be Project, Item.

2)Select all the files to be included in your template (including the .vscontent file) and compress it to prepare a standard zip file. In above case it will produce MyFirstWebProjectTemplate.zip.

3)Rename the extension of the .zip file to .vsi.

Alternate Approach

1)Select all the files to be included in your template (including the .vstemplate file) and compress it to prepare a standard zip file.

2)Create a file in the project folder with .vscontent extension as shown in the above scenario

3)Select the zip file created in step 1 and .vscontent file created in step 2. Right click and click “Add to archive”. In the Archive name give MyTemplate.vsi and zip it. It will create a new MyTemplate.vsi file.

That’s it distribute the .vsi file.

Note: In order to avoid the “No Signature Found” warning and to display the publisher information into the .vsi package you must sign your .vsi file

[sourcecode language="html"]

<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>ASP.NET AJAX Control Project</Name>
<Description>Create new ASP.NET AJAX Control Extenders and Behaviors</Description>
<ProjectType>CSharp</ProjectType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>AjaxControlExtender</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<CustomParameters>
<CustomParameter Name="$baseitemname$" Value="$safeprojectname$"/>
<CustomParameter Name="$rootnamespace$" Value="$safeprojectname$"/>
</CustomParameters>
<Project TargetFileName="AjaxControlExtender.csproj" File="AjaxControlExtender.csproj" ReplaceParameters="true">
<ProjectItem TargetFileName="$safeprojectname$Behavior.js" ReplaceParameters="true">Behavior.js</ProjectItem>
<ProjectItem TargetFileName="$safeprojectname$Extender.cs" ReplaceParameters="true">Extender.cs</ProjectItem>
<ProjectItem TargetFileName="$safeprojectname$Designer.cs" ReplaceParameters="true">Designer.cs</ProjectItem>
<Folder Name="bin" TargetFolderName="bin">
<ProjectItem>AjaxControlToolkit.dll</ProjectItem>
</Folder>
</Project>
</TemplateContent>
</VSTemplate>

<VSTemplate Version="2.0.0" Type="Project" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>MyFirstWebProjectTemplate</Name>
<Description>A simple Web template</Description>
<Icon>icon.ico</Icon>
<ProjectType>Web</ProjectType>
<ProjectSubType>CSharp</ProjectSubType>
<DefaultName>WebSite</DefaultName>
</TemplateData>
<TemplateContent>
<Project File="MyFirstWebProjectTemplate.webproj" TargetFileName="MyFirstWebProjectTemplate.webproj">
<ProjectItem>web.config</ProjectItem>
<ProjectItem OpenInEditor="true">Default.aspx</ProjectItem>
<ProjectItem>Default.aspx.cs</ProjectItem>
<Folder Name="App_Code" TargetFolderName="App_Code">
<Folder Name="BAL" TargetFolderName="BAL">
</Folder>
<Folder Name="DAL" TargetFolderName="DAL">
<ProjectItem>DataAccess.cs</ProjectItem>
</Folder>
</Folder>
<Folder Name="App_Data" TargetFolderName="App_Data">
</Folder>
</Project>
</TemplateContent>
</VSTemplate>

[/sourcecode]

2 comments:

Creating project templates for Visual Studio « Dhaval Upadhyaya said...

[...] Packing and Deploying Custom Templates in Visual Studio. [...]

aşk büyüsü said...

Thanks for admin wonderfull information..