Visual Studio 2013: TODO Comments and Custom Tokens in the Task List
NOTE: This is an older feature I’ve updated the information for VS2013
Ever been writing some code and you want to leave a reminder to yourself to do something on a particular line or area? Did you know about the "to do" comment feature or custom tokens? They seriously rock if you have never used them and, because they go in source code, everyone can have access to the information when you check-in the code!
So here's how TODO comments work:
In VB you just put any comment in that begins with the letters "todo" (case doesn't matter):
C# and C++
In C# and C++, it's pretty much the same thing (again, case doesn't matter):
In C++ you have to explicitly turn this feature on. Go to Tools | Options | Text Editor | C/C++ | View and change Enumerate Comment Tasks to True:
Regardless which language you use the result is an entry in your Task List:
Note: You can Double Click any entry to automatically have the editor go to the respective line in your source.
If you don’t see the entries, make sure you have set the task list to see comments:
We actually have several tokens you can use in addition to TODO. To see all the existing tokens go to Tools | Options | Environment | Task List:
HACK and UNDONE
You are welcome to use HACK and UNDONE as well. The MSDN documentation is horrifically bad when it comes to describing these tokens and I don’t agree with the description of use necessarily. Here is what it says:
“Items labeled TODO, HACK, and UNDONE in the Task List window indicate code problems that do not keep the project from compiling, but that do cause run-time errors. You should correct these errors before running the project.”
Also, be aware that the number of entries that appear in the Task List changes depending on the type of project you are working on. With VB and C# projects, the Task List displays all of the comments in the project whether the file is open or not. With C++ projects, the Task List displays only the comments that are found in the files currently opened for edit.
Creating Custom Tokens
Feel free to create your own tokens for your use. Creating your own tokens is very simple, just pick a name for your token and type it in the Name textbox:
Note: UnresolvedMergeConflict looks like an error but isn’t it is an actual token that will make a high priority item in the Task List.
Next choose a priority level:
Then click the Add button to make it an active token:
You will see it in your list:
Now you can use the token in your comments:
Sharing Custom Tokens
Be aware that any tokens you create ARE NOT SHARED with other developers so you may want to come up with a standard set of tokens for everyone to use if you intend to leverage this feature company-wide then export them (http://blogs.msdn.com/b/zainnab/archive/2010/07/14/exporting-your-environment-settings-vstipenv0021.aspx) and have folks import them (http://blogs.msdn.com/b/zainnab/archive/2010/07/15/importing-or-changing-your-environment-settings-vstipenv0022.aspx).
Tokens are a pretty nice feature to keep track of places in your code you need to revisit. I don’t suggest them over, say, tasks in Team Foundation Server but they are a great short-term reminder for things that need to get attention. If you decide you would like to create Task List items programmatically you can do that as well. Here is a link to some guidance to get you started: