2

Say I have some code like this from an ASP.NET MVC Core app:

public static void Main(string[] args)
{
    Console.Title = "IdentityServerWithAspNetIdentity";

    var seed = args.Any(x => x == "/seed");
    if (seed) args = args.Except(new[] { "/seed" }).ToArray();

    var host = BuildWebHost(args);

    if (seed)
    {
        SeedData.EnsureSeedData(host.Services);
        return;
    }

    host.Run();
}

How do I pass an arguement of "/seed" to this method (to seed the data)? So far I have tried:

1) This:

enter image description here

No arguement is passed to Main.

2) Looked here (amongst other places):

Pass command-line arguments to Startup class in ASP Core

Liam
  • 27,717
  • 28
  • 128
  • 190
w0051977
  • 15,099
  • 32
  • 152
  • 329
  • 1
    @Liam this is about using the command line parameters in configuration. The OP is asking why there are no parameters to begin with. Not suprising, since the web site is *not* launched from the command line – Panagiotis Kanavos Aug 01 '18 at 09:05
  • 2
    @w0051977 you are launching IIS Express, not the application. Your debug settings say "Launch IIS Express with `/seed` as an argument" – Panagiotis Kanavos Aug 01 '18 at 09:07
  • @ Panagiotis Kanavos, main is definitely called when I start debugging in Visual Studio - I added a breakpoint to check. – w0051977 Aug 01 '18 at 09:07
  • @w0051977 yes, but you are passing the arguments to IIS, not the application. You are launching IIS Express, which then launches the application. Have you tried changing the `Launch` setting? – Panagiotis Kanavos Aug 01 '18 at 09:08
  • @Panagiotis Kanavos, many thanks that was it. Changing "Launch" to "Project" solved it. Please post an answer so that I can give credit. +1 for: "you are launching IIS Express, not the application" – w0051977 Aug 01 '18 at 09:09

1 Answers1

2

You need to enclose the argument into quotation marks like "/seed"

Project properties

Runtime

marko982
  • 156
  • 6