CSharpRepl icon indicating copy to clipboard operation
CSharpRepl copied to clipboard

Load multiple projects and packages.

Open Luiz-Ossinho opened this issue 2 years ago • 5 comments

Feature Description

Lets say there is a solution like

├►MySolution.sln └┬►MyClassLibrary.csproj ▒├►MyConsoleApp.csproj ▒└┬►References: MyClassLibrary.csproj ▒▒└►References: "nuget: Newtonsoft.Json"

After executing:

#r "pathToSolution\MySolution.sln"

It should not load only one project, but load all projects contained in the solution. I think this is possible and should be compatible on all plataforms. As for loading packages, i believe it would be more troublesome, especially if youre aiming to make avaible on all plataforms, but it should still be possible.

Luiz-Ossinho avatar May 10 '22 21:05 Luiz-Ossinho

I wonder if changing CSharpRepl.Services.Roslyn.MetadataResolvers.ProjectFileMetadataResolver.cs to support multiple lines of the build output instead of just the last one will already solver one part of this issue. Once i figure out how to play test this on my machine i will make a PR right away.

Luiz-Ossinho avatar May 10 '22 22:05 Luiz-Ossinho

Lol, it wasnt that simple. It took me quite a while to realize that the NotSupportedException was caused by the default roslyn compiler, not me:

// CommonReferenceManager.Resolution.cs
if (references.Length > 1)
{
    // TODO: implement
    throw new NotSupportedException();
}

now im figuring out how to create reference from files, but the NugetMetadataResolver shines some light in the process.

Luiz-Ossinho avatar May 11 '22 03:05 Luiz-Ossinho

It took me quite a while to realize that the NotSupportedException was caused by the default roslyn compiler

Yeah, that took me quite some time to figure out as well! Thanks for the contribution.

waf avatar May 11 '22 13:05 waf

Just a brief description of the current state -- for the solution structure mentioned in the issue description:

├►MySolution.sln
└┬►MyClassLibrary.csproj
 ├►MyConsoleApp.csproj
 └┬►References: MyClassLibrary.csproj
  └►References: "nuget: Newtonsoft.Json"

Before #135, CSharpRepl would load only MyConsoleApp, which in turn could reference libraries and nuget packages. Any code in MyConsoleApp that called these referenced libraries and nuget packages would work just fine when executed from the REPL, because csharprepl would know how to resolve DLLs from the MyConsoleApp's bin directory.

However, these references couldn't be used directly from the REPL session, which is what #135 solved for project references. Now in the REPL session you can say using MyClassLibrary; which wouldn't previously work.

Similar story for nuget packages; code in MyConsoleApp or MyClassLibrary that uses nuget packages, when called from the REPL, will load and execute correctly; but you can't issue a top-level e.g. using Newtonsoft.Json from the prompt unless we reference those nuget packages.

waf avatar May 15 '22 04:05 waf

Once i have sometime i want to work on the nuget packages too. I think i figured it out by the nuget package reference resolver that the correct dependencies of any project are in the .deps.json file. This would effectively change almost every reference resolver to load 1 or more dependencies at once, except for the AssemblyResolver, of course, so it should take some good work.

Luiz-Ossinho avatar May 16 '22 12:05 Luiz-Ossinho