Skip to content

Commit d807e61

Browse files
authored
Merge pull request #450 from gteijeiro/codex/add-slnx-support
Add support for .slnx solution references
2 parents 295de58 + a594e30 commit d807e61

5 files changed

Lines changed: 22 additions & 4 deletions

File tree

CSharpRepl.Services/Roslyn/MetadataResolvers/SolutionFileMetadataResolver.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public SolutionFileMetadataResolver(DotnetBuilder builder, IConsoleEx console)
2828
public override bool CanResolve(string reference) =>
2929
reference.EndsWith(".sln", StringComparison.OrdinalIgnoreCase) ||
3030
reference.EndsWith(".sln\"", StringComparison.OrdinalIgnoreCase) ||
31+
reference.EndsWith(".slnx", StringComparison.OrdinalIgnoreCase) ||
32+
reference.EndsWith(".slnx\"", StringComparison.OrdinalIgnoreCase) ||
3133
reference.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) ||
3234
reference.EndsWith(".csproj\"", StringComparison.OrdinalIgnoreCase);
3335

@@ -57,7 +59,7 @@ private async Task<ImmutableArray<PortableExecutableReference>> GetMetadataRefer
5759
var projects = Path.GetExtension(solutionOrProject) switch
5860
{
5961
".csproj" => [await workspace.OpenProjectAsync(solutionOrProject, cancellationToken: cancellationToken)],
60-
".sln" => (await workspace.OpenSolutionAsync(solutionOrProject, cancellationToken: cancellationToken)).Projects,
62+
".sln" or ".slnx" => (await workspace.OpenSolutionAsync(solutionOrProject, cancellationToken: cancellationToken)).Projects,
6163
_ => throw new ArgumentException("Unexpected filetype for file " + solutionOrProject)
6264
};
6365

@@ -78,4 +80,4 @@ private async Task<ImmutableArray<PortableExecutableReference>> GetMetadataRefer
7880
.Distinct()
7981
.ToImmutableArray();
8082
}
81-
}
83+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Solution>
2+
<Project Path="DemoSolution.DemoProject1/DemoSolution.DemoProject1.csproj" />
3+
<Project Path="DemoSolution.DemoProject2/DemoSolution.DemoProject2.csproj" />
4+
</Solution>

CSharpRepl.Tests/EvaluationTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,18 @@ public async Task Evaluate_SolutionReference_ReferencesAllProjects()
156156
Assert.IsType<EvaluationResult.Success>(importProject2Result);
157157
}
158158

159+
[Fact]
160+
public async Task Evaluate_SolutionReference_ReferencesAllProjects_FromSlnx()
161+
{
162+
var referenceResult = await services.EvaluateAsync(@"#r ""./Data/DemoSolution/DemoSolution.slnx""");
163+
var importProject1Result = await services.EvaluateAsync(@"using DemoSolution.DemoProject1;");
164+
var importProject2Result = await services.EvaluateAsync(@"using DemoSolution.DemoProject2;");
165+
166+
Assert.IsType<EvaluationResult.Success>(referenceResult);
167+
Assert.IsType<EvaluationResult.Success>(importProject1Result);
168+
Assert.IsType<EvaluationResult.Success>(importProject2Result);
169+
}
170+
159171
[Fact]
160172
public async Task Evaluate_SolutionReference_ReferencesMultipleTargetFrameworks()
161173
{

CSharpRepl/ReadEvalPrintLoop.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ [underline]Adding References[/]
167167
Use the {Reference()} command to add reference to:
168168
- assembly ({Reference("AssemblyName")} or {Reference("path/to/assembly.dll")}),
169169
- NuGet package ({Reference("nuget: PackageName")} or {Reference("nuget: PackageName, version")}),
170-
- project ({Reference("path/to/my.csproj")} or {Reference("path/to/my.sln")}).
170+
- project ({Reference("path/to/my.csproj")}, {Reference("path/to/my.sln")}, or {Reference("path/to/my.slnx")}).
171171
172172
Use {Preprocessor("#load", "path-to-file")} to evaluate C# stored in files (e.g. csx files). This can
173173
be useful, for example, to build a [{ToColor("string")}].profile.csx[/] that includes libraries you want

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ When you're done with your session, you can type `exit` or press <kbd>Ctrl+D</kb
107107
Use the `#r` command to add assembly or nuget references.
108108

109109
- For assembly references, run `#r "AssemblyName"` or `#r "path/to/assembly.dll"`
110-
- For project references, run `#r "path/to/project.csproj"`. Solution files (.sln) can also be referenced.
110+
- For project references, run `#r "path/to/project.csproj"`. Solution files (`.sln` and `.slnx`) can also be referenced.
111111
- For nuget references, run `#r "nuget: PackageName"` to install the latest version of a package, or `#r "nuget: PackageName, 13.0.5"` to install a specific version (13.0.5 in this case).
112112

113113
<p align="center">

0 commit comments

Comments
 (0)