How to enable dotnet watch in Jetbrains Raider

coolgoose

Alexandru Bucur

Posted on March 10, 2018

How to enable dotnet watch in Jetbrains Raider

Hi guys, while working on my pet API project in C# and .NET Core I realized that I miss having the debugger 'watch' for file changes.

The standard way of doing this in .NET Core 2.0 is to setup dotnet-watch . It seems that starting with .NET Core 2.1 this step isn't going to be necessary, so one less step to do.
Until then you can follow the official tutorial for setting up dotnet-watch.

In order to make it work in Rider, you need to do some simple steps.

  1. Under Run/Debug Configurations, click the plus sign and pick Run external tool
    Run/Debug Configurations

  2. Set dotnet-watch, and make sure to set the proper Working Directory macro $ProjectFileDir$
    External tool

Update
Since there's no implicit way of setting up the ASPNETCORE_ENVIRONMENT in Rider before running the command, here's a quick way of adding a parameter to your program to enable the switch.

Modify Program.cs

        public static IWebHost BuildWebHost(string[] args)
        {
            var config = new ConfigurationBuilder().AddCommandLine(args).Build();
            var enviroment = config["environment"] ?? "Development";

            return WebHost.CreateDefaultBuilder(args)
                          .UseEnvironment(enviroment)
                          .UseStartup<Startup>()
                          .Build();
        }
Enter fullscreen mode Exit fullscreen mode

Now you can run

dotnet watch run --environment="Development"

(or any other environment variable) and have the specific environment setup depending on your run configuration.

💖 💪 🙅 🚩
coolgoose
Alexandru Bucur

Posted on March 10, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related