Skip to content

Commit

Permalink
Fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
hvanbakel committed Jul 8, 2017
1 parent af01522 commit 2a784ba
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project2015To2017/Definition/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Project2015To2017.Definition
internal sealed class Project
{
public IReadOnlyList<string> AssemblyReferences { get; internal set; }
public IReadOnlyList<string> ProjectReferences { get; internal set; }
public IReadOnlyList<ProjectReference> ProjectReferences { get; internal set; }
public IReadOnlyList<PackageReference> PackageReferences { get; internal set; }
public IReadOnlyList<XElement> ItemsToInclude { get; internal set; }
public PackageConfiguration PackageConfiguration { get; internal set; }
Expand Down
14 changes: 14 additions & 0 deletions Project2015To2017/Definition/ProjectReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project2015To2017.Definition
{
public class ProjectReference
{
public string Include { get; set; }
public string Aliases { get; set; }
}
}
10 changes: 9 additions & 1 deletion Project2015To2017/ProjectReferenceTransformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ public Task TransformAsync(XDocument projectFile, DirectoryInfo projectFolder, P

// TODO Project references are now transitive so we might be able to flatten later..

definition.ProjectReferences = projectFile.Element(nsSys + "Project").Elements(nsSys + "ItemGroup").Elements(nsSys + "ProjectReference").Select(x => x.Attribute("Include").Value).ToArray();
definition.ProjectReferences = projectFile
.Element(nsSys + "Project")
.Elements(nsSys + "ItemGroup")
.Elements(nsSys + "ProjectReference")
.Select(x => new ProjectReference
{
Include = x.Attribute("Include").Value,
Aliases = x.Element(nsSys + "Aliases")?.Value
}).ToArray();
return Task.CompletedTask;
}
}
Expand Down
10 changes: 9 additions & 1 deletion Project2015To2017/Writing/ProjectWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ public void Write(Project project, FileInfo outputFile)
var itemGroup = new XElement("ItemGroup");
foreach (var projectReference in project.ProjectReferences)
{
itemGroup.Add(new XElement("ProjectReference", new XAttribute("Include", projectReference)));
var projectReferenceElement = new XElement("ProjectReference",
new XAttribute("Include", projectReference.Include));

if (!string.IsNullOrWhiteSpace(projectReference.Aliases) && projectReference.Aliases != "global")
{
projectReferenceElement.Add(new XElement("Aliases", projectReference.Aliases));
}

itemGroup.Add(projectReferenceElement);
}

projectNode.Add(itemGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task TransformsProjectReferencesAsync()
await transformation.TransformAsync(doc, directoryInfo, project).ConfigureAwait(false);

Assert.AreEqual(2, project.ProjectReferences.Count);
Assert.IsTrue(project.ProjectReferences.Contains(@"..\SomeOtherProject\SomeOtherProject.csproj"));
Assert.IsTrue(project.ProjectReferences.Any(x => x.Include == @"..\SomeOtherProject\SomeOtherProject.csproj" && x.Aliases == "global,one"));
}
}
}
2 changes: 2 additions & 0 deletions Project2015To2017Tests/TestFiles/net46console.testcsproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@
<ProjectReference Include="..\SomeOtherProject\SomeOtherProject.csproj">
<Project>{E5D98CC4-93A3-450D-B33E-F9CAD02BBD8C}</Project>
<Name>SomeOtherProject</Name>
<Aliases>global,one</Aliases>
</ProjectReference>
<ProjectReference Include="..\YetAnotherProject\YetAnotherProject.csproj">
<Project>{E5D98CC5-93A3-450D-B33E-F9CAD02BBD8C}</Project>
<Name>YetAnotherProject</Name>
<Aliases>global</Aliases>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down

0 comments on commit 2a784ba

Please sign in to comment.