Skip to content

Commit

Permalink
Fixes #71
Browse files Browse the repository at this point in the history
  • Loading branch information
hvanbakel committed Apr 5, 2018
1 parent e9a2fdb commit 863ee93
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Project2015To2017.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(System.Console.WriteLine)))
{
if (definition == null)
{
continue;
}

writer.Write(definition);
}
}
Expand Down
1 change: 1 addition & 0 deletions Project2015To2017/Definition/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class Project
public IReadOnlyList<XElement> Imports { get; internal set; }
public IReadOnlyList<XElement> Targets { get; internal set; }
public IReadOnlyList<XElement> BuildEvents { get; internal set; }
public IReadOnlyList<string> Configurations { get; internal set; }

public IReadOnlyList<string> TargetFrameworks { get; internal set; }
public ApplicationType Type { get; internal set; }
Expand Down
10 changes: 10 additions & 0 deletions Project2015To2017/ProjectPropertiesTransformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
4 changes: 3 additions & 1 deletion Project2015To2017/Writing/ProjectWriter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -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<string>()));
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);
Expand Down
73 changes: 73 additions & 0 deletions Project2015To2017Tests/ProjectPropertiesTransformationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,79 @@ public async Task MaintainsPrePostBuildEvent()
Assert.AreEqual(1, project.BuildEvents.Count);
}

[TestMethod]
public async Task ReadsConfigurations()
{
var xml = @"
<Project DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
<Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
<PropertyGroup>
<VisualStudioVersion Condition=""'$(VisualStudioVersion)' == ''"">15.0</VisualStudioVersion>
<OldToolsVersion>14.0</OldToolsVersion>
<DslTargetsPath>..\SDK\v15.0\MSBuild\DSLTools</DslTargetsPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
</PropertyGroup>
<PropertyGroup>
<Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
<Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
<ProjectGuid>{87161453-D71B-4ABB-BADB-1D0E621E8EA0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Class1</RootNamespace>
<AssemblyName>Class1</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DocumentationFile>bin\Debug\Class1.xml</DocumentationFile>
<RunCodeAnalysis>false</RunCodeAnalysis>
<CodeAnalysisRuleSet>..\FxCop.Rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DocumentationFile>bin\Release\Class1.xml</DocumentationFile>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRuleSet>..\FxCop.Rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=""'$(Configuration)|$(Platform)' == 'Release_CI|AnyCPU'"">
<OutputPath>bin\Release_CI\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>..\FxCop.Rules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Release_CI\Class1.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
</Project>";

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<Project> ParseAndTransformAsync(string xml)
{
var document = XDocument.Parse(xml);
Expand Down

0 comments on commit 863ee93

Please sign in to comment.