Skip to content

Commit

Permalink
Add support for new dotnet .slnx format
Browse files Browse the repository at this point in the history
  • Loading branch information
austindrenski committed Feb 28, 2025
1 parent 754c5bc commit 61e9d8c
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,127 @@ await TestDiscoveryAsync(
);
}

[Fact]
public async Task TestRepo_DirectDiscovery_Slnx()
{
var solutionPath = "solution.slnx";
await TestDiscoveryAsync(
experimentsManager: new ExperimentsManager() { UseDirectDiscovery = true },
packages:
[
MockNuGetPackage.CreateSimplePackage("Some.Package", "9.0.1", "net7.0"),
],
workspacePath: "",
files: new[]
{
("src/project.csproj", """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Package" />
</ItemGroup>
</Project>
"""),
("Directory.Build.props", "<Project />"),
("Directory.Packages.props", """
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<SomePackageVersion>9.0.1</SomePackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Some.Package" Version="$(SomePackageVersion)" />
</ItemGroup>
</Project>
"""),
(solutionPath, """
<Solution>
<Folder Name="/src/">
<Project Path="src/project.csproj" />
</Folder>
</Solution>
"""),
("global.json", """
{
"sdk": {
"version": "6.0.405",
"rollForward": "latestPatch"
},
"msbuild-sdks": {
"My.Custom.Sdk": "5.0.0",
"My.Other.Sdk": "1.0.0-beta"
}
}
"""),
(".config/dotnet-tools.json", """
{
"version": 1,
"isRoot": true,
"tools": {
"microsoft.botsay": {
"version": "1.0.0",
"commands": [
"botsay"
]
},
"dotnetsay": {
"version": "2.1.3",
"commands": [
"dotnetsay"
]
}
}
}
"""),
},
expectedResult: new()
{
Path = "",
Projects = [
new()
{
FilePath = "src/project.csproj",
TargetFrameworks = ["net7.0", "net8.0"],
Dependencies = [
new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net7.0"], IsDirect: true),
new("Some.Package", "9.0.1", DependencyType.PackageReference, TargetFrameworks: ["net8.0"], IsDirect: true),
],
Properties = [
new("TargetFrameworks", "net7.0;net8.0", "src/project.csproj")
],
ReferencedProjectPaths = [],
ImportedFiles = [
"../Directory.Build.props",
"../Directory.Packages.props",
],
AdditionalFiles = [],
}
],
GlobalJson = new()
{
FilePath = "global.json",
Dependencies = [
new("Microsoft.NET.Sdk", "6.0.405", DependencyType.MSBuildSdk),
new("My.Custom.Sdk", "5.0.0", DependencyType.MSBuildSdk),
new("My.Other.Sdk", "1.0.0-beta", DependencyType.MSBuildSdk),
]
},
DotNetToolsJson = new()
{
FilePath = ".config/dotnet-tools.json",
Dependencies = [
new("microsoft.botsay", "1.0.0", DependencyType.DotNetTool),
new("dotnetsay", "2.1.3", DependencyType.DotNetTool),
]
}
}
);
}

[Fact]
public async Task TestRepo_SolutionFileCasingMismatchIsResolved()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Linq;

using Microsoft.Build.Construction;
using Microsoft.Build.Definition;
Expand Down Expand Up @@ -201,6 +204,7 @@ private static ImmutableArray<string> FindEntryPoints(string workspacePath)
switch (extension)
{
case ".sln":
case ".slnx":
case ".proj":
case ".csproj":
case ".fsproj":
Expand Down Expand Up @@ -232,6 +236,30 @@ private static ImmutableArray<string> ExpandEntryPointsIntoProjects(IEnumerable<
filesToExpand.Push(project.AbsolutePath);
}
}
else if (extension == ".slnx")
{
var projects = XElement
.Load(candidateEntryPoint)
.Descendants("Project")
.Select(static x => x.Attribute("Path"))
.Where(static x => x is not null)
.Select(static x => (string)x!)
.Where(static x =>
x.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) ||
x.EndsWith(".fsproj", StringComparison.OrdinalIgnoreCase) ||
x.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase));

foreach (var project in projects)
{
// keep this project and check for references
expandedProjects.Add(project);
IEnumerable<string> referencedProjects = ExpandItemGroupFilesFromProject(project, "ProjectReference");
foreach (string referencedProject in referencedProjects)
{
filesToExpand.Push(referencedProject);
}
}
}
else if (extension == ".proj")
{
IEnumerable<string> foundProjects = ExpandItemGroupFilesFromProject(candidateEntryPoint, "ProjectFile", "ProjectReference");
Expand Down

0 comments on commit 61e9d8c

Please sign in to comment.