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!
TODO Comments
So here's how TODO comments work:
VB
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:
Custom Tokens
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.”
https://msdn.microsoft.com/en-us/library/aa652344(v=VS.71).aspx
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 (https://blogs.msdn.com/b/zainnab/archive/2010/07/14/exporting-your-environment-settings-vstipenv0021.aspx) and have folks import them (https://blogs.msdn.com/b/zainnab/archive/2010/07/15/importing-or-changing-your-environment-settings-vstipenv0022.aspx).
Finally
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:
https://msdn.microsoft.com/en-US/library/envdte.tasklist.defaultcommenttoken(v=vs.80).aspx
Comments
Anonymous
August 15, 2013
Note for others: In VS 2012, it appears that the tokens are a) case-sensitive, and b) require a colon following them for them to be detected. Not sure if that's changed in VS 2013 but if you're trying it based on the screenshots above and it's not working, that might explain things :)Anonymous
August 15, 2013
Thanks Jon :) If you are using VS2010 or older you can see my original post on this here as well: blogs.msdn.com/.../todo-comments-in-the-task-list-vstiptool0029.aspx blogs.msdn.com/.../create-custom-tokens-for-the-task-list-vstiptool0032.aspx ZAnonymous
August 15, 2013
For remote code reviews, when code needs to be annotated by the reviewer, we use a custom token of CODEREVIEW. Its a poor man's code review system, using these tags and sharing a task branch back and forth through the review process.Anonymous
August 16, 2013
thanks a lot , i didn't know about it before :) .Anonymous
August 16, 2013
The comment has been removedAnonymous
August 16, 2013
Yann :) Yeah I have to agree with you on that one. This feature hasn't really gotten a lot of love from the team but it gets the job done. ZAnonymous
November 12, 2013
The comment has been removedAnonymous
December 10, 2013
This only seems to work in .cs files. Doesn't work in .js files :(Anonymous
February 21, 2014
The comment: "With C++ projects, the Task List displays only the comments that are found in the files currently opened for edit." needs some precisifying. When he says "files opened for edit", he means the currently viewable file. Which renders it pretty well useless for C++. Otherwise, this is a nice concise write up.Anonymous
May 06, 2014
I do not know why, but I continuously loose the token defined by myself... can you give me an hint about a possible reason (I am using vs2013)Anonymous
May 06, 2014
Hey Martina :) The only way I know that might happen consistently is your .SUO file has been marked read-only or is being overwritten in some way. ZAnonymous
June 10, 2014
i think it's to hard for me to creating the hacking programAnonymous
September 24, 2014
We use "@todo" in our code. VS doesn't allow us to add "@" as a part of custom token. Is there a way to handle this?Anonymous
October 13, 2014
Sam, you have 2 options. Option1 - stay with your @todo sintax. Option2 - Use code Editor feature Find -Replace, to replace @todo with 'todo Yann Duran, it took me a while as well to unlock the Interface of adding custom keywords, but this is not the major issue as there are many other more important issues to fix in VS, I support MS in this case to leave it as it is.Anonymous
November 13, 2014
Martina, I was having the issue you mentioned as well (with VS 2013) where new task list items I'd added were lost each time VS was restarted. Solution I found was to run VS in normal user mode (not admin mode), and make and save your changes there. Then, when you restart in admin mode, they're availableAnonymous
January 29, 2015
<script>window.alert(“test”)</script>Anonymous
February 21, 2015
Is there a way to make Visual Studio pick up on TODOs that I've inserted into JS files?Anonymous
October 15, 2015
To piggy back on Colins comment: Is there a way to select which file types are included. I'd like to see TODOs listed for .cshtml pages as well.Anonymous
October 15, 2015
Tried Mike B's solution for the new token disappearing after closing visual studio. I've looked at the Settings file and the value is persisting, but not displaying when I open VS again. Anyone else have this issue and find a resolution? I'm using ReSharper in VS as well, but I'd bet that's so common anymore that I'd be very surprised if it were at the root of the issue.