Reload DNX whenever a file changes

Dec 17, 2015 · Follow on Twitter and Mastodon archive

I’m currently developing a console app in .NET Core on my Mac. It’s a rather nice experience, although I miss a lot of stuff from Visual Studio, e.g. build triggers. Let’s make DNX reload whenever a file changes.

One problem I have with the Visual Studio Code and .NET Core setup, is that I find it tedious to write a bunch of code, then have to leave Visual Studio Code to run dnx run from the terminal to verify that my code compiles, then run dnx test to verify that my unit tests still pass etc.

Luckily, there is a tool called dnx-watch, that will reload dnx as soon as any file in your project changes.

To install dnx-watch, make sure that you have updated your stack with the latest versions, using dnvm, then install dnx-watch with this command:

dnu commands install Microsoft.Dnx.Watcher 1.0.0

In my console app, I have a console app project and a test project. Since the test project runs code from the app project, I just have to run dnx-watch test in the test project’s root folder. dnx-watch will then fire as soon as I change a file in either the app or the test project.

I can now stay in Visual Studio Code, write a bunch of code and see my tests run each time I save a file in either project.

Discussions & More

Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying on Twitter or Mastodon..

If you found this text interesting, make sure to follow me on Twitter and Mastodon for more content like this, and to be notified when new content is published.

If you like & want to support my work, please consider sponsoring me on GitHub Sponsors.