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

5
  • 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 Commented Aug 1, 2018 at 9:05
  • 2
    @w0051977 you are launching IIS Express, not the application. Your debug settings say "Launch IIS Express with /seed as an argument" Commented Aug 1, 2018 at 9:07
  • @ Panagiotis Kanavos, main is definitely called when I start debugging in Visual Studio - I added a breakpoint to check. Commented Aug 1, 2018 at 9: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? Commented Aug 1, 2018 at 9: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" Commented Aug 1, 2018 at 9:09

1 Answer 1

2

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

Project properties

Runtime

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.