Skip to content

Commit b855dca

Browse files
Merge pull request #26 from endjin/feature/add-slnx-support
2 parents 0137371 + 8c027e7 commit b855dca

5 files changed

Lines changed: 24 additions & 18 deletions

File tree

src/Covenant.Core/Covenant.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>

src/Covenant.CycloneDx/Covenant.CycloneDx.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>

src/Covenant.Spdx/Covenant.Spdx.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>

src/Covenant/Analysis/Dotnet/DotnetAnalyzer.cs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Security.Cryptography;
2+
using System.Threading;
23
using Buildalyzer;
3-
using Microsoft.Build.Construction;
4+
using Microsoft.VisualStudio.SolutionPersistence;
5+
using Microsoft.VisualStudio.SolutionPersistence.Serializer;
46

57
namespace Covenant.Analysis.Dotnet;
68

@@ -16,9 +18,10 @@ internal class DotnetAnalyzer : Analyzer
1618
private readonly DotnetAssetFileReader _assetFileReader;
1719
private readonly AnalyzerManager _analyzerManager;
1820
private bool _enabled = true;
21+
private static readonly string[] _solutionExtensions = new[] { ".sln", ".slnx" };
1922

2023
public override bool Enabled => _enabled;
21-
public override string[] Patterns { get; } = new[] { "**/*.sln" };
24+
public override string[] Patterns { get; } = _solutionExtensions.Select(e => $"**/*{e}").ToArray();
2225

2326
public DotnetAnalyzer(
2427
IFileSystem fileSystem, IEnvironment environment, IGlobber globber)
@@ -53,9 +56,10 @@ public override bool ShouldTraverse(DirectoryPath path)
5356

5457
public override bool CanHandle(AnalysisContext context, FilePath path)
5558
{
56-
var isSolution = path.GetExtension()?.Equals(".sln", StringComparison.OrdinalIgnoreCase) ?? false;
57-
var isCsProject = path.GetExtension()?.Equals(".csproj", StringComparison.OrdinalIgnoreCase) ?? false;
58-
var isFsProject = path.GetExtension()?.Equals(".fsproj", StringComparison.OrdinalIgnoreCase) ?? false;
59+
var extension = path.GetExtension() ?? string.Empty;
60+
var isSolution = _solutionExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
61+
var isCsProject = extension.Equals(".csproj", StringComparison.OrdinalIgnoreCase);
62+
var isFsProject = extension.Equals(".fsproj", StringComparison.OrdinalIgnoreCase);
5963
return isSolution || isCsProject || isFsProject;
6064
}
6165

@@ -64,22 +68,23 @@ public override void Analyze(AnalysisContext context, FilePath path)
6468
path = path.MakeAbsolute(_environment);
6569
var extension = path.GetExtension() ?? string.Empty;
6670

67-
if (extension.Equals(".sln", StringComparison.OrdinalIgnoreCase))
71+
if (_solutionExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
6872
{
6973
// Analyze solution
70-
var solution = SolutionFile.Parse(path.FullPath);
74+
ISolutionSerializer? serializer = SolutionSerializers.GetSerializerByMoniker(path.FullPath);
75+
if (serializer is null)
76+
{
77+
return;
78+
}
7179

72-
// Collect all projects
73-
var projects = solution.ProjectsInOrder.Where(
74-
csproj => csproj.ProjectType != SolutionProjectType.SolutionFolder
75-
&& csproj.ProjectType != SolutionProjectType.Unknown);
80+
var solution = serializer.OpenAsync(path.FullPath, CancellationToken.None).Result;
7681

7782
// Add all components in all projects
7883
var assetFiles = new List<AssetFile>();
79-
foreach (var csproj in projects)
84+
foreach (var csproj in solution.SolutionProjects)
8085
{
81-
var (version, copyright, analyzerResult) = PerformDesignTimeBuild(context, csproj.AbsolutePath);
82-
var assetsFile = ReadAssetFile(context, csproj.AbsolutePath, analyzerResult);
86+
var (version, copyright, analyzerResult) = PerformDesignTimeBuild(context, csproj.FilePath);
87+
var assetsFile = ReadAssetFile(context, csproj.FilePath, analyzerResult);
8388
if (assetsFile != null)
8489
{
8590
assetFiles.Add(assetsFile);

src/Covenant/Covenant.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
5+
<TargetFrameworks>net8.0</TargetFrameworks>
66
<IsPackable>true</IsPackable>
77
<PackAsTool>true</PackAsTool>
88
<PackageId>Covenant</PackageId>
@@ -35,6 +35,7 @@
3535
<ItemGroup>
3636
<PackageReference Include="Buildalyzer" Version="6.0.4" />
3737
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
38+
<PackageReference Include="Microsoft.VisualStudio.SolutionPersistence" Version="1.0.52" />
3839
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3940
<PackageReference Include="NuGet.Packaging" Version="6.9.1" />
4041
<PackageReference Include="Rosetta" Version="0.5.0" />

0 commit comments

Comments
 (0)