Skip to content

Commit

Permalink
Merge branch '4.1-rc'
Browse files Browse the repository at this point in the history
Fix #254
  • Loading branch information
andrew-boyarshin committed Jul 22, 2019
2 parents ff1c66c + 734f05f commit add5b13
Show file tree
Hide file tree
Showing 65 changed files with 1,290 additions and 738 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Copyright>Copyright Hans van Bakel</Copyright>
<Description>Tool for converting a MSBuild project file to VS2017 format and beyond.</Description>
<PackageTags>dotnet csproj fsproj vbproj msbuild conversion vs2015 vs14 vs15 vs2017</PackageTags>
<Version>4.1.0-beta.4</Version>
<Version>4.1.0-beta.5</Version>
<AssemblyVersion>4.1.0.0</AssemblyVersion>

<!-- SourceLink -->
Expand Down
30 changes: 30 additions & 0 deletions Project2015To2017.Core/Definition/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,35 @@ public DirectoryInfo NuGetPackagesPath
public IReadOnlyList<XElement> AssemblyAttributeProperties { get; set; } = Array.Empty<XElement>();

public IReadOnlyList<string> IntermediateOutputPaths { get; set; }

private sealed class ProjectNameFilePathEqualityComparer : IEqualityComparer<Project>
{
public bool Equals(Project x, Project y)
{
if (ReferenceEquals(x, y)) return true;
if (x is null) return false;
if (y is null) return false;
if (x.GetType() != y.GetType()) return false;
return string.Equals(x.ProjectName, y.ProjectName, StringComparison.InvariantCultureIgnoreCase) &&
string.Equals(x.FilePath.FullName, y.FilePath.FullName,
StringComparison.InvariantCultureIgnoreCase);
}

public int GetHashCode(Project obj)
{
var a = obj.ProjectName != null
? StringComparer.InvariantCultureIgnoreCase.GetHashCode(obj.ProjectName)
: 0;
var b = obj.FilePath != null
? StringComparer.InvariantCultureIgnoreCase.GetHashCode(obj.FilePath.FullName)
: 0;
unchecked
{
return (a * 397) ^ b;
}
}
}

public static IEqualityComparer<Project> ProjectNameFilePathComparer { get; } = new ProjectNameFilePathEqualityComparer();
}
}
20 changes: 20 additions & 0 deletions Project2015To2017.Core/Definition/Solution.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 NuGet.Configuration;
Expand Down Expand Up @@ -31,5 +32,24 @@ public DirectoryInfo NuGetPackagesPath
return new DirectoryInfo(Extensions.MaybeAdjustFilePath(path, solutionFolder));
}
}

private sealed class FilePathEqualityComparer : IEqualityComparer<Solution>
{
public bool Equals(Solution x, Solution y)
{
if (ReferenceEquals(x, y)) return true;
if (x is null) return false;
if (y is null) return false;
if (x.GetType() != y.GetType()) return false;
return string.Equals(x.FilePath.FullName, y.FilePath.FullName, StringComparison.InvariantCultureIgnoreCase);
}

public int GetHashCode(Solution obj)
{
return (obj.FilePath != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(obj.FilePath.FullName) : 0);
}
}

public static IEqualityComparer<Solution> FilePathComparer { get; } = new FilePathEqualityComparer();
}
}
5 changes: 0 additions & 5 deletions Project2015To2017.Core/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
using Microsoft.Extensions.Logging;
using Project2015To2017.Transforms;

namespace Project2015To2017
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.Logging;

namespace Project2015To2017.Transforms
Expand All @@ -22,6 +21,7 @@ public IReadOnlyCollection<ITransformation> Transformations(
{
new PropertyDeduplicationTransformation(),
new PropertySimplificationTransformation(targetVisualStudioVersion),
new ServiceFilterTransformation(targetVisualStudioVersion),
new PrimaryProjectPropertiesUpdateTransformation(),
new EmptyGroupRemoveTransformation(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@

namespace Project2015To2017.Transforms
{
public sealed class PropertySimplificationTransformation : ILegacyOnlyProjectTransformation
public sealed class PropertySimplificationTransformation : ITransformation
{
private static readonly string[] IgnoreProjectNameValues =
{
"$(MSBuildProjectName)",
"$(ProjectName)"
};

private static readonly string[] KnownTestFrameworkIds =
{
"Microsoft.NET.Test.Sdk",
"xUnit.Core",
"xUnit",
"NUnit",
};

private readonly Version targetVisualStudioVersion;
private static readonly Version Vs15TestServiceFixVersion = new Version(15, 7);

public PropertySimplificationTransformation(Version targetVisualStudioVersion = null)
{
Expand Down Expand Up @@ -196,7 +187,6 @@ when ValidateDefaultValue("{fae04ec0-301f-11d3-bf4b-00c04f79efbc}"):
case "AssemblyName" when IsDefaultProjectNameValued():
case "TargetName" when IsDefaultProjectNameValued():
case "ProjectGuid" when ProjectGuidMatchesSolutionProjectGuid():
case "Service" when IncludeMatchesSpecificGuid():
{
removeQueue.Add(child);
break;
Expand Down Expand Up @@ -273,24 +263,6 @@ bool IsDefaultProjectNameValued()
IgnoreProjectNameValues.Contains(child.Value)
);
}

bool IncludeMatchesSpecificGuid()
{
// This is not required as of VS15.7 and above, but we might target VS15.0
if (targetVisualStudioVersion < Vs15TestServiceFixVersion)
if (!project.PackageReferences.Any(IsKnownTestProvider))
return false;

return child.Attribute("Include")?.Value == "{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}";

bool IsKnownTestProvider(PackageReference x)
{
// In theory, we should be checking versions of these test frameworks
// to see, if they have the fix included.

return KnownTestFrameworkIds.Contains(x.Id);
}
}
}

// we cannot remove elements correctly while iterating through elements, 2nd pass is needed
Expand Down
58 changes: 58 additions & 0 deletions Project2015To2017.Core/Transforms/ServiceFilterTransformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Linq;
using System.Xml.Linq;
using Project2015To2017.Definition;

namespace Project2015To2017.Transforms
{
public sealed class ServiceFilterTransformation : ITransformation
{
private static readonly string[] KnownTestFrameworkIds =
{
"Microsoft.NET.Test.Sdk",
"xUnit.Core",
"xUnit",
"NUnit",
};

private static readonly Version Vs15TestServiceFixVersion = new Version(15, 7);

private readonly Version targetVisualStudioVersion;

public ServiceFilterTransformation(Version targetVisualStudioVersion)
{
this.targetVisualStudioVersion = targetVisualStudioVersion ?? throw new ArgumentNullException(nameof(targetVisualStudioVersion));
}

public void Transform(Project definition)
{
var removeQueue = definition.ItemGroups.ElementsAnyNamespace("Service").Where(IncludeMatchesSpecificGuid).ToArray();

foreach (var element in removeQueue)
{
element.Remove();
}

bool IncludeMatchesSpecificGuid(XElement child)
{
if (string.Equals(child.Attribute("Include")?.Value, "{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}",
StringComparison.InvariantCultureIgnoreCase))
{
// Fix is included with VS15.7 and above, but we might target VS15.0
// All known test providers also have a fix included
return targetVisualStudioVersion >= Vs15TestServiceFixVersion || definition.PackageReferences.Any(IsKnownTestProvider);
}

return false;
}
}

private static bool IsKnownTestProvider(PackageReference x)
{
// In theory, we should be checking versions of these test frameworks
// to see, if they have the fix included.

return KnownTestFrameworkIds.Contains(x.Id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Project2015To2017.Migrate2017.Transforms
{
public sealed class FrameworkReferencesTransformation : ILegacyOnlyProjectTransformation
{
private const string SdkExtrasVersion = "MSBuild.Sdk.Extras/1.6.65";
private const string SdkExtrasVersion = "MSBuild.Sdk.Extras/1.6.68";
private static readonly Guid XamarinAndroid = Guid.ParseExact("EFBA0AD7-5A72-4C68-AF49-83D382785DCF", "D");
private static readonly Guid XamarinIos = Guid.ParseExact("6BC8ED88-2882-458C-8E55-DFD12B67127B", "D");
private static readonly Guid Uap = Guid.ParseExact("A5A43C5B-DE2A-4C0C-9213-0A381AF9435A", "D");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using Project2015To2017.Definition;
using Project2015To2017.Transforms;
Expand All @@ -10,10 +9,10 @@ public sealed class UpgradeTestServiceTransformation : ITransformation
{
public void Transform(Project definition)
{
var removeQueue = definition.PropertyGroups
var removeQueue = definition.ItemGroups
.ElementsAnyNamespace("Service")
.Where(x => !string.IsNullOrEmpty(x.Value) && string.Equals(x.Value, "{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}", StringComparison.OrdinalIgnoreCase))
.ToImmutableArray();
.ToArray();

foreach (var element in removeQueue)
{
Expand Down
Loading

0 comments on commit add5b13

Please sign in to comment.