weikio / PluginFramework

Everything is a Plugin in .NET
MIT License
538 stars 101 forks source link

NugetFeedPlugInCatalog & nuget dependency resolution issue.. #62

Open PaybackMan opened 2 years ago

PaybackMan commented 2 years ago

Hi All,

On .net 6 and I'm having some trouble getting a NugetFeedPlugInCatalog configured properly.

Setting up the web service, within ConfigureDevelopmentServices

   var packageFolder = @"C:\PlugInStaging\EasyPost";
   var feedDetails   = new NuGetFeed("PlugIn Staging", packageFolder);
   var pluginCatalog = new NugetFeedPluginCatalog(feedDetails);

   services.AddPluginFramework()
               .AddPluginCatalog(pluginCatalog)
               .AddPluginType<IPlugIn>();

Resulting in

MINIMAL - MINIMAL - Attempting to gather dependency information for package 'Acme.EasyPost.1.0.19' with respect to project 'C:\Users\t\AppData\Local\Temp\NugetFeedPluginCatalog\4mqidyxh.v5a', targeting 'net6.0' DEBUG - Total number of results gathered : 15 MINIMAL - Gathering dependency information took 60 ms DEBUG - Summary of time taken to gather dependencies per source : DEBUG - C:\Users\t\AppData\Local\Temp\NugetFeedPluginCatalog\4mqidyxh.v5a - 56 ms DEBUG - C:\PlugInStaging\EasyPost - 75 ms MINIMAL - Attempting to resolve dependencies for package 'Acme.EasyPost.1.0.19' with DependencyBehavior 'Lowest' fail: Weikio.PluginFramework.AspNetCore.PluginFrameworkInitializer[0] Failed to initialize Weikio.PluginFramework.Catalogs.NugetFeedPluginCatalog System.InvalidOperationException: Unable to resolve dependency 'Acme.Support'.

I think that this throws when DI resolution kicks in, from a component that requires the catalog. Maybe a Packaging issue so I included a .nuspec which should force all dependencies into the .net6 nuget folder (based on this => https://josef.codes/dotnet-pack-include-referenced-projects/) I copied the package to the package folder. When unzipped, the package does contain the required dependencies.

After retest, same issue. The framework is very elegant IMHO. Excited to use this! I'm just not getting my proof of concept locked down just yet. Any suggestions to get there?

Thanks, Travis

mikoskinen commented 2 years ago

Thank you for posting this. Under the covers the Plugin Framework's Nuget support uses the standard (Microsoft provided) Nuget.Client when downloading the packages and in our apps we've noticed that it best to avoid fighting it when it comes to package dependencies :)

In one app we wanted to release just one project into Nuget.org and tried to add the other dependencies through the Nuspec but still encountered issues with a simple dotnet restore. Since then we've just published all the projects into the feed.

In your scenario I think this means that it would be easier if you could publish all the dependencies (Acme.Support and others) into the same feed.

The custom feed adds a little compilation as currently the NugetFeedPluginCatalog tries to use only the custom feed when resolving the dependencies. If a package in the custom feed depends on some package which is available from Nuget.org, I think currently resolving the dependencies fails. NugetPackagePluginCatalog recently added a new option "IncludeSystemFeedsAsSecondary" which allows the NugetPackagePluginCatalog to use custom feeds together with Nuget.org and other feeds. But NugetFeedPluginCatalog doesn't expose this flag so it is set to 'false' by default.

PaybackMan commented 2 years ago

Really appreciate your feedback. I'll try moving all plugin dependencies into the same feed they are pulled from. Will let you know how it turns out. Again, thanks..

PaybackMan commented 2 years ago

Hey Mikoskinen,

I took your advise and got past the errors I had previously. Now I'm down to this

DEBUG - C:\Users\travi\AppData\Local\Temp\NugetFeedPluginCatalog\ondhxcck.mjw - 2 ms MINIMAL - Attempting to resolve dependencies for package 'AutoMapper.11.0.1' with DependencyBehavior 'Lowest' fail: Weikio.PluginFramework.AspNetCore.PluginFrameworkInitializer[0] Failed to initialize Weikio.PluginFramework.Catalogs.NugetFeedPluginCatalog System.InvalidOperationException: Unable to resolve dependency 'Microsoft.CSharp'.

Looks like Automap requires Microsoft.CSharp... I'll keep working with it...