Skip to content

Commit

Permalink
Uses VS toolchain for SDK .NET Framework projects (resolves #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Oct 24, 2017
1 parent e17e820 commit 8ccd90e
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Buildalyzer/PathHelperFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,24 @@ public static IPathHelper GetPathHelper(string projectPath, XDocument projectDoc
XElement projectElement = projectDocument.GetDescendants("Project").FirstOrDefault();
if (projectElement != null)
{
// Use .NET Core SDK if a SDK attribute
if (projectElement.GetAttributeValue("Sdk") != null)
// Does this project use the SDK?
// Check for an SDK attribute on the project element
// If no <Project> attribute, check for a SDK import (see https://github.com/Microsoft/msbuild/issues/1493)
if (projectElement.GetAttributeValue("Sdk") != null
|| projectElement.GetDescendants("Import").Any(x => x.GetAttributeValue("Sdk") != null))
{
// Use the Framework tools if this project targets .NET Framework ("net" followed by a digit)
// https://docs.microsoft.com/en-us/dotnet/standard/frameworks
string targetFramework = projectElement.GetDescendants("TargetFramework").FirstOrDefault()?.Value;
if(targetFramework != null
&& targetFramework.StartsWith("net", StringComparison.OrdinalIgnoreCase)
&& targetFramework.Length > 3
&& char.IsDigit(targetFramework[4]))
{
return new FrameworkPathHelper();
}

// Otherwise use the .NET Core SDK
return new CorePathHelper(projectPath);
}

Expand All @@ -33,13 +48,6 @@ public static IPathHelper GetPathHelper(string projectPath, XDocument projectDoc
{
return new FrameworkPathHelper();
}

// If no <Project> attribute, check for a SDK import
// See https://github.com/Microsoft/msbuild/issues/1493
if (projectElement.GetDescendants("Import").Any(x => x.GetAttributeValue("Sdk") != null))
{
return new CorePathHelper(projectPath);
}
}

throw new InvalidOperationException("Unrecognized project file format");
Expand Down

0 comments on commit 8ccd90e

Please sign in to comment.