自定义 项目模版
c#:
step1:replace the parameter which need user customize using $parameter$
for example: In this baseline project we should customize the title and tiptext in resource file.so we user $...$
step2:export templete from baseline project.
step3:create wizard project to implement the wizard winows .
step4:build the wizard project and put dll in GAC,then modify custom templeta .vstemplete file
step1:replace the parameter which need user customize using $parameter$
for example: In this baseline project we should customize the title and tiptext in resource file.so we user $...$
step2:export templete from baseline project.
step3:create wizard project to implement the wizard winows .
Code
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TemplateWizard;
using System.Windows.Forms;
using EnvDTE;
namespace CustomWizard
{
public class IWizardImplementation:IWizard
{
private UserInputForm inputForm;
private string customMessage;
// This method is called before opening any item that
// has the OpenInEditor attribute.
public void BeforeOpeningFile(ProjectItem projectItem)
{
}
public void ProjectFinishedGenerating(Project project)
{
}
// This method is only called for item templates,
// not for project templates.
public void ProjectItemFinishedGenerating(ProjectItem
projectItem)
{
}
// This method is called after the project is created.
public void RunFinished()
{
}
public void RunStarted(object automationObject,
Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind, object[] customParams)
{
try
{
// Display a form to the user. The form collects
// input for the custom message.
inputForm = new UserInputForm();
inputForm.ShowDialog();
// Add custom parameters.
replacementsDictionary.Add("$DocPaneTipText$", WizardParameters.Instance.DocPaneTipText);
replacementsDictionary.Add("$DocPaneTitle$", WizardParameters.Instance.DocPaneTitle); }
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
// This method is only called for item templates,
// not for project templates.
public bool ShouldAddProjectItem(string filePath)
{
return true;
}
}
}
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TemplateWizard;
using System.Windows.Forms;
using EnvDTE;
namespace CustomWizard
{
public class IWizardImplementation:IWizard
{
private UserInputForm inputForm;
private string customMessage;
// This method is called before opening any item that
// has the OpenInEditor attribute.
public void BeforeOpeningFile(ProjectItem projectItem)
{
}
public void ProjectFinishedGenerating(Project project)
{
}
// This method is only called for item templates,
// not for project templates.
public void ProjectItemFinishedGenerating(ProjectItem
projectItem)
{
}
// This method is called after the project is created.
public void RunFinished()
{
}
public void RunStarted(object automationObject,
Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind, object[] customParams)
{
try
{
// Display a form to the user. The form collects
// input for the custom message.
inputForm = new UserInputForm();
inputForm.ShowDialog();
// Add custom parameters.
replacementsDictionary.Add("$DocPaneTipText$", WizardParameters.Instance.DocPaneTipText);
replacementsDictionary.Add("$DocPaneTitle$", WizardParameters.Instance.DocPaneTitle); }
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
// This method is only called for item templates,
// not for project templates.
public bool ShouldAddProjectItem(string filePath)
{
return true;
}
}
}
step4:build the wizard project and put dll in GAC,then modify custom templeta .vstemplete file
Code
<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>eCopy PaperWorks SDK Wizard</Name>
<Description>eCopy PaperWorks Connector Wizard</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>PaperWorksConnector</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="PaperWorksConnectorCS.csproj" File="PaperWorksConnectorCS.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="ConnectorResource.resx">ConnectorResource.resx</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="ConnectorResource.Designer.cs">ConnectorResource.Designer.cs</ProjectItem>
<!--<ProjectItem ReplaceParameters="true" TargetFileName="PaperWorksConnectorCS.cs">PaperWorksConnectorCS.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="PaperWorksStorageCS.cs">PaperWorksStorageCS.cs</ProjectItem>-->
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="ConnectorCS.snk">ConnectorCS.snk</ProjectItem>
</Folder>
<Folder Name="ReferenceDll" TargetFolderName="ReferenceDll">
<ProjectItem ReplaceParameters="false" TargetFileName="connectors.dll">connectors.dll</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="ecViewer.dll">ecViewer.dll</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="IBridge.dll">IBridge.dll</ProjectItem>
</Folder>
<ProjectItem ReplaceParameters="true" TargetFileName="RegistryOperation.cs">RegistryOperation.cs</ProjectItem>
<Folder Name="Resources" TargetFolderName="Resources">
<ProjectItem ReplaceParameters="false" TargetFileName="ButtonIcon.ico">ButtonIcon.ico</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Open.ico">Open.ico</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Project.ico">Project.ico</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Save.ico">Save.ico</ProjectItem>
</Folder>
<ProjectItem ReplaceParameters="true" TargetFileName="Win32Api.cs">Win32Api.cs</ProjectItem>
</Project>
</TemplateContent>
<WizardExtension>
<Assembly>
CustomWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=069e425962c50a4e
</Assembly>
<FullClassName>CustomWizard.IWizardImplementation</FullClassName>
</WizardExtension>
</VSTemplate>
<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>eCopy PaperWorks SDK Wizard</Name>
<Description>eCopy PaperWorks Connector Wizard</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>PaperWorksConnector</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="PaperWorksConnectorCS.csproj" File="PaperWorksConnectorCS.csproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true" TargetFileName="ConnectorResource.resx">ConnectorResource.resx</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="ConnectorResource.Designer.cs">ConnectorResource.Designer.cs</ProjectItem>
<!--<ProjectItem ReplaceParameters="true" TargetFileName="PaperWorksConnectorCS.cs">PaperWorksConnectorCS.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="PaperWorksStorageCS.cs">PaperWorksStorageCS.cs</ProjectItem>-->
<Folder Name="Properties" TargetFolderName="Properties">
<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="ConnectorCS.snk">ConnectorCS.snk</ProjectItem>
</Folder>
<Folder Name="ReferenceDll" TargetFolderName="ReferenceDll">
<ProjectItem ReplaceParameters="false" TargetFileName="connectors.dll">connectors.dll</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="ecViewer.dll">ecViewer.dll</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="IBridge.dll">IBridge.dll</ProjectItem>
</Folder>
<ProjectItem ReplaceParameters="true" TargetFileName="RegistryOperation.cs">RegistryOperation.cs</ProjectItem>
<Folder Name="Resources" TargetFolderName="Resources">
<ProjectItem ReplaceParameters="false" TargetFileName="ButtonIcon.ico">ButtonIcon.ico</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Open.ico">Open.ico</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Project.ico">Project.ico</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Save.ico">Save.ico</ProjectItem>
</Folder>
<ProjectItem ReplaceParameters="true" TargetFileName="Win32Api.cs">Win32Api.cs</ProjectItem>
</Project>
</TemplateContent>
<WizardExtension>
<Assembly>
CustomWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=069e425962c50a4e
</Assembly>
<FullClassName>CustomWizard.IWizardImplementation</FullClassName>
</WizardExtension>
</VSTemplate>