public void CreateProjectTemplate(IProjectTemplate template, string solutionFolder, string destFolder, bool copyFiles, CancellationToken ct) { if (template.IsProject) { var projectTemplateFile = new FileInfo(template.GetTemplateFileName(destFolder)); if (!projectTemplateFile.Directory.Exists) { projectTemplateFile.Directory.Create(); } //Copy icons template.CopyTemplateIconsTo(projectTemplateFile.DirectoryName); ct.ThrowIfCancellationRequested(); var projectFile = new FileInfo(Path.Combine(solutionFolder, template.ProjectFileName)); var projectFolder = projectFile.Directory.FullName; using var sw = new StreamWriter(projectTemplateFile.Create()); sw.WriteLine($"<VSTemplate Version=\"{VSTemplateVersion}\" xmlns=\"http://schemas.microsoft.com/developer/vstemplate/2005\" Type=\"Project\">"); sw.WriteLine(" <TemplateData>"); WriteTemplateData(sw, template); sw.WriteLine(" </TemplateData>"); sw.WriteLine(" <TemplateContent>"); sw.WriteLine($" <Project TargetFileName=\"{projectFile.Name}\" File=\"{projectFile.Name}\" ReplaceParameters=\"true\">"); var blackList = new List <string> { "bin", "obj", "TestResults", ".*", projectTemplateFile.Name, template.TemplateName + ".zip" }; WriteFileSystemInfo(sw, projectFile.Directory.FullName, 6, blackList, ct); if (copyFiles) { projectFolder.CopyDirectory(Path.Combine(destFolder, template.TemplateName), blackList, ct); } sw.WriteLine(" </Project>"); sw.WriteLine(" </TemplateContent>"); sw.WriteLine("</VSTemplate>"); } foreach (var child in template.Children) { CreateProjectTemplate(child, solutionFolder, destFolder, copyFiles, ct); } }
public void CreateProjectTemplate_ShouldBeSame() { ITemplateRepository templateGeneratorWriter = new TemplateRepository(); var templateFile = new FileInfo(@"..\..\..\TestData\Templates\RazorClassLibrary\RazorClassLibrary.vstemplate".GetAppPath()); Assert.IsTrue(templateFile.Exists); IProjectTemplate projectTemplate = templateGeneratorWriter.ReadProjectTemplate(templateFile.FullName); templateGeneratorWriter.CreateProjectTemplate(projectTemplate, templateFile.Directory.Parent.FullName, _outputDir, false, CancellationToken.None); var generatedTemplateFile = new FileInfo(projectTemplate.GetTemplateFileName(_outputDir)); IProjectTemplate projectTemplateWritten = templateGeneratorWriter.ReadProjectTemplate(generatedTemplateFile.FullName); TestHelper.AssertProjectTemplate(projectTemplate, projectTemplateWritten); }