Skip to content

Commit

Permalink
Fix issue reported by mail (#10)
Browse files Browse the repository at this point in the history
Fixes AB#12554
  • Loading branch information
MichielOda authored Nov 16, 2023
1 parent f1dc4df commit bbb1b00
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions Parsers.Common/VisualStudio/Projects/SdkStyleParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NuGet.Frameworks;

using Skyline.DataMiner.CICD.FileSystem;
using Skyline.DataMiner.CICD.Parsers.Common.Exceptions;

internal class SdkStyleParser : IProjectParser
{
Expand All @@ -18,8 +19,7 @@ internal class SdkStyleParser : IProjectParser

internal SdkStyleParser(XDocument document, string projectDir)
{
if(document == null) throw new ArgumentNullException(nameof(document));
this.document = document;
this.document = document ?? throw new ArgumentNullException(nameof(document));
this.projectDir = projectDir;
}

Expand Down Expand Up @@ -150,19 +150,35 @@ public IEnumerable<ProjectFile> GetCompileFiles()

public string GetTargetFrameworkMoniker()
{
var targetFrameworkElement = document
.Element("Project")
?.Element("PropertyGroup")
.Element("TargetFramework");
var propertyGroups = document
?.Element("Project")
?.Elements("PropertyGroup");

if (propertyGroups == null)
{
throw new ParserException("No PropertyGroup tags found in the csproj file!");
}

foreach (XElement propertyGroup in propertyGroups)
{
var targetFrameworkElement = propertyGroup.Element("TargetFramework");

// SDK style projects support multi-targeting. Return first item.
string tfms = targetFrameworkElement.Value;
if (targetFrameworkElement == null)
{
continue;
}

// https://learn.microsoft.com/en-us/dotnet/standard/frameworks
string sdkStyleTfm = tfms.Split(';')[0];
var tfm = NuGetFramework.ParseFolder(sdkStyleTfm);
// SDK style projects support multi-targeting. Return first item.
string tfms = targetFrameworkElement.Value;

// https://learn.microsoft.com/en-us/dotnet/standard/frameworks
string sdkStyleTfm = tfms.Split(';')[0];
var tfm = NuGetFramework.ParseFolder(sdkStyleTfm);

return tfm.DotNetFrameworkName;
}

return tfm.DotNetFrameworkName;
throw new ParserException("No TargetFramework tag found in the csproj file!");
}

public IEnumerable<ProjectFile> GetSharedProjectCompileFiles()
Expand Down

0 comments on commit bbb1b00

Please sign in to comment.