Search code examples
c#.net-coredotnet-clidotnet-watch

How to use dotnet watch with release configuration and arguments passed to the application?


Let's use the following code for simulating the problem.

class Program
{
    static void Main(string[] args)
    {
        foreach (var arg in args)
        {
            Console.WriteLine(arg);
        }
    }
}

I want to use dotnet watch -c release -- hello world but the output is:

-c
release
hello
world

The expected output:

hello
world

What is the correct syntax?


Solution

  • dotnet watch does not have -c|--configuration switch/option (docs), dotnet run has (docs).

    dotnet watch allows to specify the command to be watched (dotnet watch run) though passing -c has not worked for me (i.e. dotnet watch run -c release -- hello world) but passing the MSBuild property directly with --property:Configuration=RELEASE did:

    dotnet watch run --property:Configuration=RELEASE -- hello world
    

    Sample program used for tests:

    #if DEBUG
    Console.WriteLine("Hello, World DEBUG!");
    #else
    Console.WriteLine("Hello, World NOT_DEBUG!");
    #endif
    foreach (var arg in args)
    {
        Console.WriteLine(arg);
    }