Skip to content

Commit

Permalink
Merge pull request #198 from hvanbakel/projectguid-removal
Browse files Browse the repository at this point in the history
Fixes #194
  • Loading branch information
andrew-boyarshin committed Sep 8, 2018
2 parents e32f8e8 + 6e9e74b commit ef248b3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
1 change: 1 addition & 0 deletions Project2015To2017/Definition/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public sealed class Project
public FileInfo FilePath { get; set; }
public string CodeFileExtension { get; set; }
public DirectoryInfo ProjectFolder => this.FilePath.Directory;
public Guid? ProjectGuid { get; set; }

public bool HasMultipleAssemblyInfoFiles { get; set; }

Expand Down
13 changes: 13 additions & 0 deletions Project2015To2017/Reading/ProjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public Project Read(FileInfo projectFile)

this.projectCache.Add(filePath, projectDefinition);

projectDefinition.ProjectGuid = ReadProjectGuid(projectDefinition);
projectDefinition.AssemblyReferences = LoadAssemblyReferences(projectDefinition);
projectDefinition.ProjectReferences = LoadProjectReferences(projectDefinition);
projectDefinition.PackagesConfigFile = FindPackagesConfigFile(projectFile);
Expand All @@ -97,6 +98,18 @@ public Project Read(FileInfo projectFile)
return projectDefinition;
}

private Guid? ReadProjectGuid(Project projectDefinition)
{
var projectTypeNode = projectDefinition
.ProjectDocument
.Descendants(projectDefinition.XmlNamespace + "ProjectGuid")
.FirstOrDefault();

return projectTypeNode != null
? Guid.Parse(projectTypeNode.Value)
: default(Guid?);
}

private void HandleSpecialProjectTypes(Project project)
{
// get the MyType tag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Microsoft.Extensions.Logging;
using Project2015To2017.Definition;
using Project2015To2017.Reading;
using Project2015To2017.Reading.Conditionals;
Expand Down Expand Up @@ -182,10 +181,12 @@ public void Transform(Project definition)
case "RootNamespace" when IsDefaultProjectNameValued():
case "AssemblyName" when IsDefaultProjectNameValued():
case "TargetName" when IsDefaultProjectNameValued():
case "ProjectGuid" when ProjectGuidMatchesSolutionProjectGuid():
{
removeQueue.Add(child);
break;
}

}

if (parentConditionHasConfiguration || parentConditionHasPlatform)
Expand Down Expand Up @@ -300,6 +301,11 @@ bool ValidateSolutionDir()
{
child.Remove();
}

bool ProjectGuidMatchesSolutionProjectGuid()
{
return project.Solution != null && project.Solution.ProjectPaths.Any(x => x.ProjectName == project.ProjectName && x.ProjectGuid == project.ProjectGuid);
}
}

/// <summary>
Expand Down
28 changes: 28 additions & 0 deletions Project2015To2017Tests/ProjectPropertiesReadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,34 @@ public async Task ReadsUnknownConfigurations()
Assert.AreEqual(8, childrenReleaseCI.Length);
}

[TestMethod]
public async Task ReadsProjectGuid()
{
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>
<Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
<Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
<ProjectGuid>{D8141286-2A5C-4CC4-8502-8E651D35F371}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClassLibrary1</RootNamespace>
<AssemblyName>ClassLibrary1</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
</Project>";

var project = await ParseAndTransform(xml).ConfigureAwait(false);

Assert.AreEqual(Guid.Parse("D8141286-2A5C-4CC4-8502-8E651D35F371"), project.ProjectGuid);
}

private static async Task<Project> ParseAndTransform(
string xml,
[System.Runtime.CompilerServices.CallerMemberName]
Expand Down
44 changes: 44 additions & 0 deletions Project2015To2017Tests/PropertySimplificationTransformationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using static Project2015To2017.Extensions;
using Project2015To2017;
using System.Text;
using System;

namespace Project2015To2017Tests
{
Expand Down Expand Up @@ -280,6 +281,49 @@ public void HandlesUnknownConfigurationSimplifications()
childrenReleaseCI.First(x => x.Name.LocalName == "OutputPath").Value);
}

[TestMethod]
public void RemovesProjectGuidWhenMatchesSolution()
{
var guid = Guid.NewGuid();
var xml = @"
<Project DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0"">
<PropertyGroup>
<Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
<Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
<ProjectGuid>{" + guid.ToString() + @"}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ClassLibrary1</RootNamespace>
<AssemblyName>ClassLibrary1</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
</Project>";

var project = ParseAndTransform(xml, projectName: "Class1");
var name = "someproject";
project.ProjectName = name;
project.Solution = new Solution
{
ProjectPaths = new[]
{
new ProjectReference
{
ProjectName = name,
ProjectGuid = guid
}
}
};

new PropertySimplificationTransformation().Transform(project);

Assert.IsTrue(!project.ProjectDocument.Descendants().Any(x => x.Name.LocalName == "ProjectGuid"));
}

private static Project ParseAndTransform(
string xml,
[System.Runtime.CompilerServices.CallerMemberName]
Expand Down

0 comments on commit ef248b3

Please sign in to comment.