How to Automatically Document C# Code in Rider
Tags: csharp, rider, documentation, tooling
Published: 2024-03-22 10:43:45

[GhostDoc](https://submain.com/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](https://www.jetbrains.com/rider/) since [Visual Studio for Mac is retired](https://devblogs.microsoft.com/visualstudio/visual-studio-for-mac-retirement-announcement/).

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](https://github.com/p1va/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](https://github.com/p1va/dotnet-document).**. At the time of writing (March 2024), I had to run this in my terminal:

```bash
dotnet tool install --global dotnet-document --version 0.1.9-alpha
```

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](https://www.jetbrains.com/help/rider/Configuring_Third-Party_Tools.html#local-ext-tools) if my instructions didn't work.

![External tool config to apply to a specific file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l80lzfp4lg68vfgvfnha.png)

_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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmzfrsi851kq8rlu6xs9.png)

_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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ev953qe4pfmpm3saedb7.png)

_Here's how my menu appears._

![My Keymap setup showing the order matches the menu](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afki7n6uxd450uo1l1ch.png)

_And here's what it looks like in my Keymap._

Happy coding!

---

_Cover by <a href="https://unsplash.com/@swimstaralex?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Alexander Sinn</a> on <a href="https://unsplash.com/photos/a-heart-is-shown-on-a-computer-screen-KgLtFCgfC28?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Unsplash</a>_