.net 6 not resolving transitive nuget package dependencies

Dan Morris 0 Reputation points
2023-08-05T23:31:26.78+00:00

I'm trying to resolve an issue with a 'FileNotFound' after migrating from .net core 3.1 to .net 6. This is about the nuget package dependencies, not any of the base code.

I followed the example from MS - https://learn.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support

And that example works until I add a nuget package and try to use it. Then I get 'FileNotFound' on several packages that are dependencies to the parent package.

I've tried many different settings to the projects that are also mentioned in other MS Learn items and I'm still getting the 'FileNotFound'

Following the MS Learn linked above I make the following changes:

I add the "Microsoft.Identity.Web.DownstreamApi" package to the HelloPlugin and added these two lines of code to the HelloCommand.cs along with a using:

Using Microsoft.Extensions.Logging;

var tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();
tokenAcquirerFactory.SErvices.AddLogging(
(loggingBuilder) => loggingBuilder.SetMinimumLevel(LogLevel.Warning)
.AddConsole()
);

My personal project has the same problem and I can copy the files that it complains about missing into the plugin project's folder, but this sample doesn't work.

I created the plugin as a single console app and everything worked as expected.

I've checked many search engine results and tried many of their solutions including:

  • adding CopyLocalLockFileAssemblies to the *.csproj plugin file as well as the main console application calling the plugin dll.
  • adding EnableDynamicLoading
  • writing a resolver, but can't get that to load the nuget package dependencies
    • this includes the AssemblyDependencyResolver from the sample above that includes the AssemblyLoadContext.

All my code works fine in .net core 3.1 without any of these settings turned on using MEF with [ImportMany] and matching [Export(typeof(InterfaceName))]

I can provide code snippets, but this failure is happening from the Microsoft Learn example I linked above with the few changes pointed out explicitly.

Please help as I'd like to upgrade my project to .net 6 instead of writing new plugins in .net core 3.1 that is no longer supported.

Thank you in advance.

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,196 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Jiachen Li-MSFT 33,531 Reputation points Microsoft Vendor
    2023-08-07T02:19:34.25+00:00

    Hi @Dan Morris ,

    I use the following code based on your description, and it works well for me.

    Have you tried reinstalling the Microsoft.Identity.Web.DownstreamApi package or running the dotnet restore command in the NuGet Package Manager Console?

    using Microsoft.Extensions.Logging;
    using Microsoft.Identity.Web;
    using Microsoft.Extensions.DependencyInjection;
    
    namespace HelloPlugin
    {
        public class HelloCommand : PluginBase.ICommand
        {
    
            public string Name { get => "hello"; }
            public string Description { get => "Displays hello message."; }
    
            public int Execute()
            {
                var tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance();
    
                tokenAcquirerFactory.Services.AddLogging((loggingBuilder) => loggingBuilder.SetMinimumLevel(LogLevel.Warning).AddConsole());
    
                Console.WriteLine("Hello !!!");
                return 0;
            }
        }
    }
    

    enter image description here Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Dan Morris 0 Reputation points
    2025-02-03T02:39:52.0733333+00:00

    Update: no changes, still fails. Project still fails. Updating to .NET 8 continues to fail to load files.

    Started a brand new project trying Microsoft.VisualStudio.Composition: fails.

    Tried using Bing AI and Google Gemini - all examples fail.

    No examples from vs-mef github project from Microsoft except MAYBE the tests that are run but nothing really shows like an 'example' https://github.com/microsoft/vs-mef

    It would be awesome if there was a sample solution/project that would compile and run without error showing the MEF functionality for an interface based loading of multiple plugins that have nuget or just other dependencies that need to load with the plugin.

    Going to try the original tutorial I mentioned when this started since it seems to have been updated in 2024.


  3. Bruce (SqlWork.com) 71,591 Reputation points
    2025-02-03T16:49:30.9266667+00:00

    as transitive references are resolved by the application build, not library build, your plugin project will need to explicitly reference any transitive libraries it uses so they are included in its publish.

    note: It might be simpler to create a small console app project that builds with the plugin, then use the app publish to deploy the plugin.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.