CSharpRepl
CSharpRepl copied to clipboard
Load multiple projects and packages.
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.
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.
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.
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.
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.
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.