question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supporting netcoreapp3.0 with McMaster.Extensions.Hosting.CommandLine

See original GitHub issue

I am trying to use this library with netcoreapp3.0. I get a failure whenever I try to launch the app.

'Method 'UseServiceProviderFactory' in type 'Microsoft.Extensions.Hosting.HostBuilder' from assembly 'Microsoft.Extensions.Hosting, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'

I think this is because McMaster.Extensions.Hosting.CommandLine.csproj refers to Microsoft.Extensions.Hosting@2.1.0.

My main method looks like

  private static async Task<int> Main(string[] args)
        {
            return await new HostBuilder()
                 .ConfigureAppConfiguration((hostContext, configApp) =>
                 {
                     var tokenProvider = new AzureServiceTokenProvider();
                     var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(tokenProvider.KeyVaultTokenCallback));

                     configApp.SetBasePath(Directory.GetCurrentDirectory());
                     configApp.AddJsonFile("appsettings.json", optional: true);
                     configApp.AddJsonFile(
                         $"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json",
                         optional: true);
                     configApp.AddCommandLine(args);

                     configApp.AddAzureKeyVault(
                       $"https://{configApp.Build().GetValue<string>("Vault")}.vault.azure.net/",
                       kv,
                       new DefaultKeyVaultSecretManager());
                 })

               .ConfigureServices((context, services) =>
               {
                   var provider = services.BuildServiceProvider();                 

                   services.RegisterDbContext();
               })

           .RunCommandLineApplicationAsync<Program>(args);
        }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
natemcmastercommented, Oct 30, 2019

I’m currently favoring solution (3) - see draft commit in https://github.com/natemcmaster/CommandLineUtils/commit/494bbc848b0c020ffa13062838b98e13052ba243. The advantage is that it maximizes compatibility. CommandLineUtils would not need to multi-target to support both 2.1 and 3.0. (It also fits with my philosophy on dependencies is that class libraries — that is, class libraries should minimize dependencies and use the lowest version possible to maximize compatibility.) The disadvantage is that it’s a packaging breaking change; anyone using CommandLineUtils doesn’t explicitly depend on Microsoft.Extensions.Hosting would need to add a new package reference.

Thoughts?

0reactions
natemcmastercommented, Oct 31, 2019

I’m hesitant on option 1 because it seems odd to me that the version of the dependency should vary based on target framework. Microsoft.Extensions.Hosting and CommandLineUtils are both netstandard2.0 libraries. If we go with option 1, netcoreapp3.0 users are forced into a higher version of Hosting, even if they were trying to use Hosting 2.1 on netcorapp3.0 (a perfectly valid use case, btw.)

I think I’d like to wait on this one (so, do option 2), and revisit this for the next major version of CommandLineUtils.

Read more comments on GitHub >

github_iconTop Results From Across the Web

McMaster.Extensions.Hosting.CommandLine 4.0.2
Provides command-line parsing API integration with the generic host API (Microsoft.Extensions.Hosting). Product, Versions Compatible and additional computed ...
Read more >
McMaster.Extensions.CommandLineUtils 3.0.0
Command-line parsing API and utilities for console applications. Commonly used types: McMaster.Extensions.CommandLineUtils.
Read more >
Upgrading to CommandLineUtils 3.0
CommandLineUtils 3.0.0 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package McMaster.Extensions.CommandLineUtils 3.1.0 supports: error ...
Read more >
Build a Command Line Interface(CLI) Program with .NET ...
The host is responsible for app startup and lifetime management. A very good document about the Generic Host here. Install-Package Microsoft.Extensions.Hosting
Read more >
Integration with Generic Host
Hosting.CommandLine package provides support for integrating command line parsing with .NET's generic host. Get started. To get started, install the McMaster.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found