From 4a3491e5b8883af340b52e321e6dbd1f61695d21 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sat, 25 Jan 2014 04:36:58 -0800 Subject: [PATCH] Made project generation more robust so that it handles more cases. --- build/_k-generate-projects.shade | 61 ++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/build/_k-generate-projects.shade b/build/_k-generate-projects.shade index 01af0cd018..0100462e15 100644 --- a/build/_k-generate-projects.shade +++ b/build/_k-generate-projects.shade @@ -149,7 +149,7 @@ functions var d = serializer.DeserializeObject(jsonText) as IDictionary; var configs = GetObject(d, "configurations"); - var references = GetObject(d, "dependencies") ?? new Dictionary(); + var dependencies = GetObject(d, "dependencies") ?? new Dictionary(); // Get the list of files var filesString = String.Join(Environment.NewLine, @@ -159,33 +159,48 @@ functions .Select(p => String.Format( @"", p))); - // Add the config file if it's there - if (File.Exists(Path.Combine(projectDir, "packages.config"))) - { - filesString += ""; - } + var packageReferences = dependencies.Where(r => !projectMapping.ContainsKey(r.Key)) + .ToDictionary(k => k.Key, k => (string)k.Value); - var packageReferences = references.Where(r => !String.IsNullOrEmpty((string)r.Value)) - .ToDictionary(k => k.Key, k => (string)k.Value); - - var projectReferences = references.Where(r => String.IsNullOrEmpty((string)r.Value)) - .Select(r => r.Key) - .ToArray(); + var projectReferences = dependencies.Where(r => projectMapping.ContainsKey(r.Key)) + .Select(r => r.Key) + .ToList(); // HACK: Assume the packages folder is 2 up from the projectDir string packagesDir = Path.GetFullPath(Path.Combine(projectDir, "..", "..", "packages")); - foreach (var targetFramework in configs.Keys) + foreach (var pair in configs) { + var targetFramework = pair.Key; + var props = (IDictionary)pair.Value; + string id = (string)GetObject(projectMapping, projectName)[targetFramework]; + var specificDependencies = GetObject(props, "dependencies") ?? new Dictionary(); + var gacReferences = new List(); + + foreach(var dep in specificDependencies) + { + if (!projectMapping.ContainsKey(dep.Key)) + { + if(String.IsNullOrEmpty((string)dep.Value)) + { + gacReferences.Add(dep.Key); + } + } + else + { + projectReferences.Add(dep.Key); + } + } + var template = templates[targetFramework] .Replace("{ProjectGuid}", id) .Replace("{Name}", projectName) .Replace("{Files}", filesString) .Replace("{ProjectReferences}", BuildProjectReferences(projectReferences, targetFramework, projectMapping)) - .Replace("{References}", BuildReferences(packageReferences, packagesDir, targetFramework, GetCandidates(targetFramework))); + .Replace("{References}", BuildReferences(packageReferences, gacReferences, packagesDir, targetFramework, GetCandidates(targetFramework))); if (targetFramework.StartsWith("k")) { @@ -221,9 +236,9 @@ functions return projectName + "." + config + ".csproj"; } - private static string BuildProjectReferences(string[] projectReferences, string config, IDictionary projectMapping) + private static string BuildProjectReferences(IList projectReferences, string config, IDictionary projectMapping) { - if (projectReferences.Length == 0) + if (projectReferences.Count == 0) { return ""; } @@ -262,17 +277,19 @@ functions return new[] { config }; } - private static string BuildReferences(IDictionary references, string packagesDir, string configName, string[] candidates) + private static string BuildReferences(IDictionary references, List gacReferences, string packagesDir, string configName, string[] candidates) { - if (references.Count == 0) - { - return ""; - } - Log("Building package references for {0}", configName); var sb = new StringBuilder(); + foreach(var gacRef in gacReferences) + { + sb.AppendFormat(@" + +", gacRef); + } + foreach (var reference in references) { var version = (string)reference.Value;