summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.BuildTasks/DiscoverProjectTemplates.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-11-15 08:45:57 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2009-11-15 08:45:57 -0800
commit9dffdc07431232ffffde0d34f1a1c2bd0aa9ca4e (patch)
tree175856bda741110c31b0908d09a62a8a945f6dba /src/DotNetOpenAuth.BuildTasks/DiscoverProjectTemplates.cs
parente778892f1d9bf964c30ba6a10e50aedf12c2e857 (diff)
downloadDotNetOpenAuth-9dffdc07431232ffffde0d34f1a1c2bd0aa9ca4e.zip
DotNetOpenAuth-9dffdc07431232ffffde0d34f1a1c2bd0aa9ca4e.tar.gz
DotNetOpenAuth-9dffdc07431232ffffde0d34f1a1c2bd0aa9ca4e.tar.bz2
.vstemplates are now partially generated to remove the need to keep them in sync with their associated project files.
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/DiscoverProjectTemplates.cs')
-rw-r--r--src/DotNetOpenAuth.BuildTasks/DiscoverProjectTemplates.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/DiscoverProjectTemplates.cs b/src/DotNetOpenAuth.BuildTasks/DiscoverProjectTemplates.cs
new file mode 100644
index 0000000..0162c16
--- /dev/null
+++ b/src/DotNetOpenAuth.BuildTasks/DiscoverProjectTemplates.cs
@@ -0,0 +1,63 @@
+//-----------------------------------------------------------------------
+// <copyright file="DiscoverProjectTemplates.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.BuildTasks {
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using System.Linq;
+ using System.Text;
+ using System.Xml.Linq;
+ using Microsoft.Build.Framework;
+ using Microsoft.Build.Utilities;
+
+ public class DiscoverProjectTemplates : Task {
+ public ITaskItem[] TopLevelTemplates { get; set; }
+
+ [Output]
+ public ITaskItem[] ProjectTemplates { get; set; }
+
+ [Output]
+ public ITaskItem[] ProjectTemplateContents { get; set; }
+
+ /// <summary>
+ /// Executes this instance.
+ /// </summary>
+ public override bool Execute() {
+ List<ITaskItem> projectTemplates = new List<ITaskItem>();
+ List<ITaskItem> projectTemplateContents = new List<ITaskItem>();
+ foreach (ITaskItem topLevelTemplate in this.TopLevelTemplates) {
+ var vsTemplate = XElement.Load(topLevelTemplate.ItemSpec);
+ var templateContent = vsTemplate.Element(XName.Get("TemplateContent", MergeProjectWithVSTemplate.VSTemplateNamespace));
+ var projectCollection = templateContent.Element(XName.Get("ProjectCollection", MergeProjectWithVSTemplate.VSTemplateNamespace));
+ var links = projectCollection.Elements(XName.Get("ProjectTemplateLink", MergeProjectWithVSTemplate.VSTemplateNamespace));
+ var subTemplates = links.Select(
+ link => (ITaskItem)new TaskItem(
+ link.Value,
+ new Dictionary<string, string> {
+ { "TopLevelTemplate", topLevelTemplate.ItemSpec },
+ { "TopLevelTemplateFileName", Path.GetFileNameWithoutExtension(topLevelTemplate.ItemSpec) },
+ }));
+ projectTemplates.AddRange(subTemplates);
+
+ foreach (var link in links.Select(link => link.Value)) {
+ string[] files = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(topLevelTemplate.ItemSpec), Path.GetDirectoryName(link)), "*.*", SearchOption.AllDirectories);
+ projectTemplateContents.AddRange(files.Select(file => (ITaskItem)new TaskItem(
+ file,
+ new Dictionary<string, string> {
+ { "TopLevelTemplate", topLevelTemplate.ItemSpec },
+ { "TopLevelTemplateFileName", Path.GetFileNameWithoutExtension(topLevelTemplate.ItemSpec) },
+ })));
+ }
+ }
+
+ this.ProjectTemplates = projectTemplates.ToArray();
+ this.ProjectTemplateContents = projectTemplateContents.ToArray();
+
+ return !this.Log.HasLoggedErrors;
+ }
+ }
+}