DEV Community

Cover image for How to Automatically Document C# Code in Rider
Peter
Peter

Posted on

How to Automatically Document C# Code in Rider

GhostDoc is all you need if you're using Visual Studio on a Windows machine.

But I use a Mac. The best IDE in the world is JetBrains Rider since Visual Studio for Mac is retired.

I couldn't find any good Rider plug-ins to do what GhostDoc does, so I used the top option code option from GitHub: dotnet-document.

Installation

Following their install instructions, you'll need to add it globally. It's not officially released on Nuget which is why you need to specify the version. I encourage you to make sure you're using the latest.. At the time of writing (March 2024), I had to run this in my terminal:

dotnet tool install --global dotnet-document --version 0.1.9-alpha
Enter fullscreen mode Exit fullscreen mode

Once it's installed, open Rider's settings and add an External Tool. Press ⌘Сmd , to open the IDE settings and then go to Tools | External Tools. Click the + button to bring up the Add modal.

Maybe you're here from the future and JetBrains changed something? Follow these instructions if my instructions didn't work.

External tool config to apply to a specific file

Above is my configuration for documenting a specific file.

  • Program: dotnet
  • Arguments: document apply $FileName$
  • Working directory: $FileDir$

Note: It's possible to document folders, supply project filename paths, solution filename paths, or just the current directory. You'll want to replace (or remove) the $FileName$ and explore the macros provided by Rider. Click the + button to the right of Arguments to see the argument variables JetBrains provide.

External tool config to apply to a folder

Above is the setup for documenting a folder.

Click OK to save your new tool and you're all set up! 🎉🎉

How to Run

It's simple: Tools menu | External Tools | dotnet-document (or whatever you named your command). Test it out and make sure it works. Don't forget to commit before you test so that you can roll back any problems. 😉

Add Keyboard Shortcuts

It's also possible to add keyboard shortcuts, but I found it flaky to set up when you've got multiple external tools. It doesn't name them properly in the Keymap list. Just be aware of the order that you have them in you menu.

My External Tools menu with two tools and a shortcut

Here's how my menu appears.

My Keymap setup showing the order matches the menu

And here's what it looks like in my Keymap.

Happy coding!


Cover by Alexander Sinn on Unsplash

Top comments (0)