Skip to content

Commit d83d929

Browse files
Add support for new dotnet .slnx format
Fixes: #11671
1 parent 754c5bc commit d83d929

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed

nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Discover/DiscoveryWorkerTests.cs

+121
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,127 @@ await TestDiscoveryAsync(
709709
);
710710
}
711711

712+
[Fact]
713+
public async Task TestRepo_DirectDiscovery_Slnx()
714+
{
715+
var solutionPath = "solution.slnx";
716+
await TestDiscoveryAsync(
717+
experimentsManager: new ExperimentsManager() { UseDirectDiscovery = true },
718+
packages:
719+
[
720+
MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net7.0"),
721+
],
722+
workspacePath: "",
723+
files: new[]
724+
{
725+
("src/project.csproj", """
726+
<Project Sdk="Microsoft.NET.Sdk">
727+
<PropertyGroup>
728+
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
729+
</PropertyGroup>
730+
731+
<ItemGroup>
732+
<PackageReference Include="Some.Package" />
733+
</ItemGroup>
734+
</Project>
735+
"""),
736+
("Directory.Build.props", "<Project />"),
737+
("Directory.Packages.props", """
738+
<Project>
739+
<PropertyGroup>
740+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
741+
<SomePackageVersion>9.0.1</SomePackageVersion>
742+
</PropertyGroup>
743+
744+
<ItemGroup>
745+
<PackageVersion Include="Some.Package" Version="$(SomePackageVersion)" />
746+
</ItemGroup>
747+
</Project>
748+
"""),
749+
(solutionPath, """
750+
<Solution>
751+
<Folder Name="/src/">
752+
<Project Path="src/project.csproj" />
753+
</Folder>
754+
</Solution>
755+
"""),
756+
("global.json", """
757+
{
758+
"sdk": {
759+
"version": "6.0.405",
760+
"rollForward": "latestPatch"
761+
},
762+
"msbuild-sdks": {
763+
"My.Custom.Sdk": "5.0.0",
764+
"My.Other.Sdk": "1.0.0-beta"
765+
}
766+
}
767+
"""),
768+
(".config/dotnet-tools.json", """
769+
{
770+
"version": 1,
771+
"isRoot": true,
772+
"tools": {
773+
"microsoft.botsay": {
774+
"version": "1.0.0",
775+
"commands": [
776+
"botsay"
777+
]
778+
},
779+
"dotnetsay": {
780+
"version": "2.1.3",
781+
"commands": [
782+
"dotnetsay"
783+
]
784+
}
785+
}
786+
}
787+
"""),
788+
},
789+
expectedResult: new()
790+
{
791+
Path = "",
792+
Projects = [
793+
new()
794+
{
795+
FilePath = "src/project.csproj",
796+
TargetFrameworks = ["net7.0", "net8.0"],
797+
Dependencies = [
798+
new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net7.0"], IsDirect: true),
799+
new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true),
800+
],
801+
Properties = [
802+
new("TargetFrameworks", "net7.0;net8.0", "src/project.csproj")
803+
],
804+
ReferencedProjectPaths = [],
805+
ImportedFiles = [
806+
"../Directory.Build.props",
807+
"../Directory.Packages.props",
808+
],
809+
AdditionalFiles = [],
810+
}
811+
],
812+
GlobalJson = new()
813+
{
814+
FilePath = "global.json",
815+
Dependencies = [
816+
new("Microsoft.NET.Sdk", "6.0.405", DependencyType.MSBuildSdk),
817+
new("My.Custom.Sdk", "5.0.0", DependencyType.MSBuildSdk),
818+
new("My.Other.Sdk", "1.0.0-beta", DependencyType.MSBuildSdk),
819+
]
820+
},
821+
DotNetToolsJson = new()
822+
{
823+
FilePath = ".config/dotnet-tools.json",
824+
Dependencies = [
825+
new("microsoft.botsay", "1.0.0", DependencyType.DotNetTool),
826+
new("dotnetsay", "2.1.3", DependencyType.DotNetTool),
827+
]
828+
}
829+
}
830+
);
831+
}
832+
712833
[Fact]
713834
public async Task TestRepo_SolutionFileCasingMismatchIsResolved()
714835
{

nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Discover/DiscoveryWorker.cs

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
using System;
12
using System.Collections.Immutable;
3+
using System.Linq;
24
using System.Text.Json;
35
using System.Text.Json.Serialization;
6+
using System.Xml.Linq;
47

58
using Microsoft.Build.Construction;
69
using Microsoft.Build.Definition;
@@ -201,6 +204,7 @@ private static ImmutableArray<string> FindEntryPoints(string workspacePath)
201204
switch (extension)
202205
{
203206
case ".sln":
207+
case ".slnx":
204208
case ".proj":
205209
case ".csproj":
206210
case ".fsproj":
@@ -232,6 +236,30 @@ private static ImmutableArray<string> ExpandEntryPointsIntoProjects(IEnumerable<
232236
filesToExpand.Push(project.AbsolutePath);
233237
}
234238
}
239+
else if (extension == ".slnx")
240+
{
241+
var projects = XElement
242+
.Load(candidateEntryPoint)
243+
.Descendants("Project")
244+
.Select(static x => x.Attribute("Path"))
245+
.Where(static x => x is not null)
246+
.Select(static x => (string)x!)
247+
.Where(static x =>
248+
x.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) ||
249+
x.EndsWith(".fsproj", StringComparison.OrdinalIgnoreCase) ||
250+
x.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase));
251+
252+
foreach (var project in projects)
253+
{
254+
// keep this project and check for references
255+
expandedProjects.Add(project);
256+
IEnumerable<string> referencedProjects = ExpandItemGroupFilesFromProject(project, "ProjectReference");
257+
foreach (string referencedProject in referencedProjects)
258+
{
259+
filesToExpand.Push(referencedProject);
260+
}
261+
}
262+
}
235263
else if (extension == ".proj")
236264
{
237265
IEnumerable<string> foundProjects = ExpandItemGroupFilesFromProject(candidateEntryPoint, "ProjectFile", "ProjectReference");

0 commit comments

Comments
 (0)