diff --git a/Project2015To2017.Console/Program.cs b/Project2015To2017.Console/Program.cs index 3416e5e..ab5ac72 100644 --- a/Project2015To2017.Console/Program.cs +++ b/Project2015To2017.Console/Program.cs @@ -15,6 +15,11 @@ static void Main(string[] args) var writer = new Project2015To2017.Writing.ProjectWriter(); foreach (var definition in ProjectConverter.Convert(args[0], new Progress(System.Console.WriteLine))) { + if (definition == null) + { + continue; + } + writer.Write(definition); } } diff --git a/Project2015To2017/Definition/Project.cs b/Project2015To2017/Definition/Project.cs index 3c5f8d7..c1351dc 100644 --- a/Project2015To2017/Definition/Project.cs +++ b/Project2015To2017/Definition/Project.cs @@ -16,6 +16,7 @@ public sealed class Project public IReadOnlyList Imports { get; internal set; } public IReadOnlyList Targets { get; internal set; } public IReadOnlyList BuildEvents { get; internal set; } + public IReadOnlyList Configurations { get; internal set; } public IReadOnlyList TargetFrameworks { get; internal set; } public ApplicationType Type { get; internal set; } diff --git a/Project2015To2017/ProjectPropertiesTransformation.cs b/Project2015To2017/ProjectPropertiesTransformation.cs index 7f5ba13..4b6b4ef 100644 --- a/Project2015To2017/ProjectPropertiesTransformation.cs +++ b/Project2015To2017/ProjectPropertiesTransformation.cs @@ -51,6 +51,16 @@ public Task TransformAsync(XDocument projectFile, DirectoryInfo projectFolder, P } } + // yuk... but hey it works... + definition.Configurations = propertyGroups + .Where(x => x.Attribute("Condition") != null) + .Select(x => x.Attribute("Condition").Value) + .Where(x => x.Contains("'$(Configuration)|$(Platform)'")) + .Select(x => x.Split('\'').Skip(3).FirstOrDefault()) + .Where(x => x != null) + .Select(x => x.Split('|')[0]) + .ToArray(); + definition.BuildEvents = propertyGroups.Elements().Where(x => x.Name == nsSys + "PostBuildEvent" || x.Name == nsSys + "PreBuildEvent").ToArray(); definition.AdditionalPropertyGroups = ReadAdditionalPropertyGroups(propertyGroups); definition.Imports = projectFile.Element(nsSys + "Project").Elements(nsSys + "Import").Where(x => diff --git a/Project2015To2017/Writing/ProjectWriter.cs b/Project2015To2017/Writing/ProjectWriter.cs index 5e40b1e..40640f1 100644 --- a/Project2015To2017/Writing/ProjectWriter.cs +++ b/Project2015To2017/Writing/ProjectWriter.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -176,7 +177,8 @@ private XElement GetMainPropertyGroup(Project project, FileInfo outputFile) AddTargetFrameworks(mainPropertyGroup, project.TargetFrameworks); - AddIfNotNull(mainPropertyGroup, "Optimize", project.Optimize ? "true" : null); + AddIfNotNull(mainPropertyGroup, "Configurations", string.Join(";", project.Configurations ?? Array.Empty())); + AddIfNotNull(mainPropertyGroup, "Optimize", project.Optimize ? "true" : null); AddIfNotNull(mainPropertyGroup, "TreatWarningsAsErrors", project.TreatWarningsAsErrors ? "true" : null); AddIfNotNull(mainPropertyGroup, "RootNamespace", project.RootNamespace != Path.GetFileNameWithoutExtension(outputFile.Name) ? project.RootNamespace : null); AddIfNotNull(mainPropertyGroup, "AssemblyName", project.AssemblyName != Path.GetFileNameWithoutExtension(outputFile.Name) ? project.AssemblyName : null); diff --git a/Project2015To2017Tests/ProjectPropertiesTransformationTest.cs b/Project2015To2017Tests/ProjectPropertiesTransformationTest.cs index 3fa694e..5c38dd3 100644 --- a/Project2015To2017Tests/ProjectPropertiesTransformationTest.cs +++ b/Project2015To2017Tests/ProjectPropertiesTransformationTest.cs @@ -470,6 +470,79 @@ public async Task MaintainsPrePostBuildEvent() Assert.AreEqual(1, project.BuildEvents.Count); } + [TestMethod] + public async Task ReadsConfigurations() + { + var xml = @" + + + + 15.0 + 14.0 + ..\SDK\v15.0\MSBuild\DSLTools + v4.6.1 + 15.0 + + + Debug + AnyCPU + {87161453-D71B-4ABB-BADB-1D0E621E8EA0} + Library + Properties + Class1 + Class1 + v4.7 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + AnyCPU + false + bin\Debug\Class1.xml + false + ..\FxCop.Rules.ruleset + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + AnyCPU + false + bin\Release\Class1.xml + true + ..\FxCop.Rules.ruleset + + + bin\Release_CI\ + TRACE + true + pdbonly + AnyCPU + prompt + ..\FxCop.Rules.ruleset + bin\Release_CI\Class1.xml + true + true + + "; + + var project = await ParseAndTransformAsync(xml).ConfigureAwait(false); + + Assert.AreEqual(3, project.Configurations.Count); + Assert.AreEqual(1, project.Configurations.Count(x => x == "Debug")); + Assert.AreEqual(1, project.Configurations.Count(x => x == "Release_CI")); + } + private static async Task ParseAndTransformAsync(string xml) { var document = XDocument.Parse(xml);