Skip to content

Commit 584cbb8

Browse files
committed
update slnx
1 parent 7860d1c commit 584cbb8

4 files changed

Lines changed: 65 additions & 55 deletions

File tree

.github/workflows/cicd.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,9 @@ foreach ($SolutionProjectPath in $SolutionProjectPaths) {
450450
Copy-FilesRecursively -SourceDirectory "$PublishDirectory" -DestinationDirectory "$RepoPublishDirectory" -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true
451451
}
452452
}
453-
Copy-FilesRecursively -SourceDirectory "$RepoPublishDirectory" -DestinationDirectory (Get-Path -Paths @($RepositoryDropRootPath,$GitRepositoryName,$ChannelVersionRelativePath)) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
454-
Copy-FilesRecursively -SourceDirectory "$RepoPublishDirectory" -DestinationDirectory (Get-Path -Paths @($RepositoryDropRootPath,$GitRepositoryName,$ChannelLatestRelativePath)) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
455-
Copy-FilesRecursively -SourceDirectory "$RepoPublishDirectory" -DestinationDirectory (Get-Path -Paths @($RepositoryDropRootPath,$GitRepositoryName,"distributed")) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
453+
Sync-DirectoryTreeLockSafe -SourcePath "$RepoPublishDirectory" -DestinationPath (Get-Path -Paths @($RepositoryDropRootPath,$GitRepositoryName,$ChannelVersionRelativePath))
454+
Sync-DirectoryTreeLockSafe -SourcePath "$RepoPublishDirectory" -DestinationPath (Get-Path -Paths @($RepositoryDropRootPath,$GitRepositoryName,$ChannelLatestRelativePath))
455+
Sync-DirectoryTreeLockSafe -SourcePath "$RepoPublishDirectory" -DestinationPath (Get-Path -Paths @($RepositoryDropRootPath,$GitRepositoryName,"distributed"))
456456
$nugetFilePart1 = Join-Text -InputObject @("$($GitRepositoryName)","$($GeneratedVersion.VersionFull)") -Separator '.' -Normalization Trim
457457
$nugetFileEmulation = Join-Text -InputObject @("$nugetFilePart1","$($BranchDeploymentConfig.Affix.Label)") -Separator '-' -Normalization Trim
458458
Compress-Directory -SourceDirectory "$RepoPublishDirectory" -DestinationFile "$(Get-Path -Paths @($RepositoryDropRootPath,$GitRepositoryName,"zipped","$nugetFileEmulation.zip"))"
@@ -467,9 +467,9 @@ foreach ($SolutionProjectPath in $SolutionProjectPaths) {
467467
$PublishDirectory = New-Directory -Paths @($PublishRootPath,$SolutionFileInfo.BaseName,$ProjectFileInfo.BaseName,$ChannelVersionRelativePath)
468468
Copy-FilesRecursively -SourceDirectory "$PublishDirectory" -DestinationDirectory "$SolutionPublishDirectory" -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true
469469
}
470-
Copy-FilesRecursively -SourceDirectory "$SolutionPublishDirectory" -DestinationDirectory (Get-Path -Paths @($SolutionsDropRootPath,$SolutionFileInfo.BaseName,$ChannelVersionRelativePath)) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
471-
Copy-FilesRecursively -SourceDirectory "$SolutionPublishDirectory" -DestinationDirectory (Get-Path -Paths @($SolutionsDropRootPath,$SolutionFileInfo.BaseName,$ChannelLatestRelativePath)) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
472-
Copy-FilesRecursively -SourceDirectory "$SolutionPublishDirectory" -DestinationDirectory (Get-Path -Paths @($SolutionsDropRootPath,$SolutionFileInfo.BaseName,"distributed")) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
470+
Sync-DirectoryTreeLockSafe -SourcePath "$SolutionPublishDirectory" -DestinationPath (Get-Path -Paths @($SolutionsDropRootPath,$SolutionFileInfo.BaseName,$ChannelVersionRelativePath))
471+
Sync-DirectoryTreeLockSafe -SourcePath "$SolutionPublishDirectory" -DestinationPath (Get-Path -Paths @($SolutionsDropRootPath,$SolutionFileInfo.BaseName,$ChannelLatestRelativePath))
472+
Sync-DirectoryTreeLockSafe -SourcePath "$SolutionPublishDirectory" -DestinationPath (Get-Path -Paths @($SolutionsDropRootPath,$SolutionFileInfo.BaseName,"distributed"))
473473
$nugetFilePart1 = Join-Text -InputObject @("$($SolutionFileInfo.BaseName)","$($GeneratedVersion.VersionFull)") -Separator '.' -Normalization Trim
474474
$nugetFileEmulation = Join-Text -InputObject @("$nugetFilePart1","$($BranchDeploymentConfig.Affix.Label)") -Separator '-' -Normalization Trim
475475
Compress-Directory -SourceDirectory "$SolutionPublishDirectory" -DestinationFile "$(Get-Path -Paths @($SolutionsDropRootPath,$SolutionFileInfo.BaseName,"zipped","$nugetFileEmulation.zip"))"
@@ -482,9 +482,9 @@ foreach ($SolutionProjectPath in $SolutionProjectPaths) {
482482
$PublishDirectory = New-Directory -Paths @($PublishRootPath,$SolutionFileInfo.BaseName,$ProjectFileInfo.BaseName,$ChannelVersionRelativePath)
483483
$ProjPublishDirectory = New-Directory -Paths @($ProjPublishRootPath,$ProjectFileInfo.BaseName,$ChannelVersionRelativePath)
484484
Copy-FilesRecursively -SourceDirectory "$PublishDirectory" -DestinationDirectory "$ProjPublishDirectory" -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true
485-
Copy-FilesRecursively -SourceDirectory "$ProjPublishDirectory" -DestinationDirectory (Get-Path -Paths @($ProjectsDropRootPath,$ProjectFileInfo.BaseName,$ChannelVersionRelativePath)) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
486-
Copy-FilesRecursively -SourceDirectory "$ProjPublishDirectory" -DestinationDirectory (Get-Path -Paths @($ProjectsDropRootPath,$ProjectFileInfo.BaseName,$ChannelLatestRelativePath)) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
487-
Copy-FilesRecursively -SourceDirectory "$ProjPublishDirectory" -DestinationDirectory (Get-Path -Paths @($ProjectsDropRootPath,$ProjectFileInfo.BaseName,"distributed")) -Filter "*" -CopyEmptyDirs $false -ForceOverwrite $true -CleanDestination MirrorTree
485+
Sync-DirectoryTreeLockSafe -SourcePath "$ProjPublishDirectory" -DestinationPath (Get-Path -Paths @($ProjectsDropRootPath,$ProjectFileInfo.BaseName,$ChannelVersionRelativePath))
486+
Sync-DirectoryTreeLockSafe -SourcePath "$ProjPublishDirectory" -DestinationPath (Get-Path -Paths @($ProjectsDropRootPath,$ProjectFileInfo.BaseName,$ChannelLatestRelativePath))
487+
Sync-DirectoryTreeLockSafe -SourcePath "$ProjPublishDirectory" -DestinationPath (Get-Path -Paths @($ProjectsDropRootPath,$ProjectFileInfo.BaseName,"distributed"))
488488
$nugetFilePart1 = Join-Text -InputObject @("$($ProjectFileInfo.BaseName)","$($GeneratedVersion.VersionFull)") -Separator '.' -Normalization Trim
489489
$nugetFileEmulation = Join-Text -InputObject @("$nugetFilePart1","$($BranchDeploymentConfig.Affix.Label)") -Separator '-' -Normalization Trim
490490
Compress-Directory -SourceDirectory "$ProjPublishDirectory" -DestinationFile "$(Get-Path -Paths @($ProjectsDropRootPath,$ProjectFileInfo.BaseName,"zipped","$nugetFileEmulation.zip"))"

source/Eigenverft.Distributed.Drydock/ProjectItems/Eigenverft.Distributed.Drydock/CommandDeclaration/SlnCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static SlnCommand()
1818
{
1919
Location = new("--location")
2020
{
21-
Description = "Full path to the target solution file (.sln).",
21+
Description = "Full path to the target solution file (.sln or .slnx).",
2222
Required = true,
2323
};
2424

source/Eigenverft.Distributed.Drydock/ProjectItems/Eigenverft.Distributed.Drydock/Eigenverft.Distributed.Drydock.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PropertyGroup>
1010
<OutputType>Exe</OutputType>
1111
<TargetFramework>net8.0</TargetFramework>
12-
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
12+
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0</TargetFrameworks>
1313
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
1414
<CheckEolTargetFramework>false</CheckEolTargetFramework>
1515
<InvariantGlobalization>true</InvariantGlobalization>
@@ -121,6 +121,7 @@
121121
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
122122
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
123123
<PackageReference Include="System.CommandLine" Version="2.0.0-beta5.25306.1" />
124+
<PackageReference Include="Microsoft.VisualStudio.SolutionPersistence" Version="1.0.52" />
124125
</ItemGroup>
125126

126127
</Project>

source/Eigenverft.Distributed.Drydock/ProjectItems/Eigenverft.Distributed.Drydock/Services/SolutionProjectService.cs

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -8,6 +9,8 @@
89

910
using Microsoft.Build.Construction;
1011
using Microsoft.Extensions.Logging;
12+
using Microsoft.VisualStudio.SolutionPersistence.Model;
13+
using Microsoft.VisualStudio.SolutionPersistence.Serializer;
1114

1215
namespace Eigenverft.Distributed.Drydock.Services
1316
{
@@ -52,87 +55,93 @@ public SolutionProjectService(ILogger<SolutionProjectService> logger)
5255
public async Task<List<string>> GetCsProjAbsolutPathsFromSolutions(string solutionLocation, CancellationToken cancellationToken)
5356
{
5457
List<string> retval = new List<string>();
58+
5559
try
5660
{
57-
List<ProjectInSolution> sln = SolutionFile.Parse(solutionLocation).ProjectsInOrder.Where(e => e.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat).ToList();
58-
List<ProjectRootElement> projects = new List<ProjectRootElement>();
61+
// Load solution (.sln OR .slnx)
62+
var serializer = SolutionSerializers.GetSerializerByMoniker(solutionLocation);
63+
if (serializer is null)
64+
{
65+
_logger.LogError("Unsupported solution file type: {SolutionLocation}", solutionLocation);
66+
return null;
67+
}
5968

60-
// Load each project file.
61-
foreach (var item in sln)
69+
SolutionModel solution;
70+
try
6271
{
63-
try
64-
{
65-
ProjectRootElement projectRoot = ProjectRootElement.Open(item.AbsolutePath);
72+
solution = await serializer.OpenAsync(solutionLocation, cancellationToken);
73+
}
74+
catch (SolutionException ex)
75+
{
76+
_logger.LogError(ex, "Failed to parse solution file: {SolutionLocation}", solutionLocation);
77+
return null;
78+
}
6679

67-
var globalProperties = new Dictionary<string, string>
68-
{
69-
["Configuration"] = "Debug",
70-
["Platform"] = "AnyCPU",
71-
//["MSBuildRuntimeType"] = "Core"
72-
};
80+
string solutionDir = Path.GetDirectoryName(Path.GetFullPath(solutionLocation)) ?? Directory.GetCurrentDirectory();
7381

74-
//var projectload = new Project(item.AbsolutePath, globalProperties, null);
82+
// Keep it simple: only take csproj entries
83+
var csprojPaths = solution.SolutionProjects
84+
.Select(p => p.FilePath)
85+
.Where(p => p.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
86+
.Select(p => Path.GetFullPath(Path.Combine(solutionDir, p)))
87+
.ToList();
7588

89+
if (csprojPaths.Count == 0)
90+
{
91+
_logger.LogWarning("Solution contained no C# projects: {SolutionLocation}", solutionLocation);
92+
return null;
93+
}
94+
95+
// Load each project file (your existing logic)
96+
List<ProjectRootElement> projects = new List<ProjectRootElement>();
97+
foreach (var projectPath in csprojPaths)
98+
{
99+
try
100+
{
101+
ProjectRootElement projectRoot = ProjectRootElement.Open(projectPath);
76102
projects.Add(projectRoot);
77103
}
78104
catch (Exception ex)
79105
{
80-
_logger.LogError(ex, "Failed to open project file: {ProjectLocation}", item.AbsolutePath);
106+
_logger.LogError(ex, "Failed to open project file: {ProjectLocation}", projectPath);
81107
return null;
82108
}
83109
}
84110

85-
// Sort projects so that any project that has a PackageReference with Include="Microsoft.NET.Test.Sdk" appears first.
86-
// Test projects: projects with any PackageReference that has Include "Microsoft.NET.Test.Sdk".
111+
// Your existing sorting logic (unchanged)
87112
var testProjects = projects.Where(project =>
88113
project.Items.Any(item =>
89114
item.ElementName == "PackageReference" &&
90115
string.Equals(item.Include, "Microsoft.NET.Test.Sdk", StringComparison.OrdinalIgnoreCase)
91116
)
92117
).ToList();
93118

94-
// Non-test projects: projects that do NOT have any PackageReference with Include "Microsoft.NET.Test.Sdk".
95119
var nonTestProjects = projects.Where(project =>
96120
!project.Items.Any(item =>
97121
item.ElementName == "PackageReference" &&
98122
string.Equals(item.Include, "Microsoft.NET.Test.Sdk", StringComparison.OrdinalIgnoreCase)
99123
)
100124
).ToList();
101125

102-
nonTestProjects = nonTestProjects.OrderBy(
103-
i => i.Items.Any(f => f.ElementName.Contains("ProjectReference"))
104-
).ToList();
126+
nonTestProjects = nonTestProjects
127+
.OrderBy(i => i.Items.Any(f => f.ElementName.Contains("ProjectReference")))
128+
.ToList();
105129

106-
foreach (var item in testProjects)
107-
{
108-
retval.Add(item.FullPath);
109-
}
130+
foreach (var item in testProjects) retval.Add(item.FullPath);
131+
foreach (var item in nonTestProjects) retval.Add(item.FullPath);
110132

111-
foreach (var item in nonTestProjects)
112-
{
113-
retval.Add(item.FullPath);
114-
}
115-
116-
//projects.Items.where // dont' know here items ElementName == "PackageReference" and on this if there is an Include == "Microsoft.NET.Test.Sdk" this project should be sorted first.
117-
//projects.OrderBy(e => e.Items == "PackageReference");
118-
119-
if (retval.Count == 0)
120-
{
121-
_logger.LogWarning("No csproj files were found in the solution: {SolutionLocation}", solutionLocation);
122-
return null;
123-
}
124-
else
125-
{
126-
//_logger.LogDebug("Found {Count} csproj files in the solution: {SolutionLocation}", retval.Count, solutionLocation);
127-
}
133+
return retval.Count == 0 ? null : retval;
134+
}
135+
catch (OperationCanceledException)
136+
{
137+
_logger.LogWarning("Solution parsing canceled: {SolutionLocation}", solutionLocation);
138+
return null;
128139
}
129140
catch (Exception ex)
130141
{
131142
_logger.LogError(ex, "Error while parsing the solution file: {SolutionLocation}", solutionLocation);
132143
throw;
133144
}
134-
135-
return retval;
136145
}
137146

138147
public async Task<string?> GetProjectProperty(string projectLocation, string? propertyName, CsProjCommand.ElementScope? scopeType, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)