How to include external files in multi-project .vstemplate?
I'm creating a VS2010 multi project template and I'm trying to make add a file (.hgignore) to the solution (not into a project) from the vstemplate.
I tried this but it doesn't work :
< VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="ProjectGroup">
< TemplateData>...< /TemplateData>
< TemplateContent >
< ProjectItem> .hgignore < /ProjectItem >
< ProjectCollection >
< ProjectTemplateLink ProjectName="$safeprojectname$.xxx">....< /ProjectTemplateLink>
< Pr开发者_StackOverflow社区ojectTemplateLink ProjectName="$safeprojectname$.xxx">....< /ProjectTemplateLink>
< /ProjectCollection>
< /TemplateContent>
< /VSTemplate>
Thank you very much
PS : I can't manage to make correct XML tag in the editor so I had to add white space...
There is no built-in way to do this. However, the VSTemplate wizard engine supports an extensibility model that lets you run custom logic during the solution/project creation process. You need to implement a class that implements the IWizard interface and then add a WizardExtension element in your .vstemplate file.
Check out Craig Skibo's answer on this MSDN forum question for the details on using the DTE automation API from your IWizard.RunFinished method to add a solution item.
It is possible to do this programmatically via IWizard.
Example Wizard, which copies Nuget.Config from VSIX(which is included via "Include in VSIX" property):
class AppCustomizationWizard : IWizard
{
private const string NugetConfig = "Nuget.Config";
private static string GetVsixFullPath(string filename)
{
var vsixDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (string.IsNullOrEmpty(vsixDir))
{
return null;
}
return Path.Combine(
vsixDir,
filename
);
}
private static void CopyNugetConfig(Dictionary<string, string> replacementsDictionary)
{
var solutionDir = replacementsDictionary["$solutiondirectory$"];
var vsixNugetConfig = GetVsixFullPath(NugetConfig);
if (solutionDir != null && vsixNugetConfig != null)
{
File.Copy(vsixNugetConfig, Path.Combine(solutionDir, NugetConfig));
}
}
public void BeforeOpeningFile(ProjectItem projectItem)
{
}
public void ProjectFinishedGenerating(Project project)
{
}
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{
}
public void RunFinished()
{
}
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary,
WizardRunKind runKind, object[] customParams)
{
XElement wizardInfo = XElement.Parse(replacementsDictionary["$wizarddata$"]);
XNamespace defaultNamespace = wizardInfo.GetDefaultNamespace();
string itemType = wizardInfo.Element(defaultNamespace + "Type").Value;
if (itemType == "Application")
{
CopyNugetConfig(replacementsDictionary);
}
}
public bool ShouldAddProjectItem(string filePath)
{
return true;
}
}
精彩评论