In Visual Studio, how do I change the default XML summary comment snippet from three lines to one line?
Currently it provides this snippet when I type ///:
/// <summary>
///
/// </summary>
I would like this shorter snippet:
///<summary></summary>
My summaries are often brief and the extra 2 line are unnecessary.
Is there a configuration setting for this or some customizable code/custom addon to fix this.
This is an older question, but I liked Jason Williams's suggestion of creating a snippet for this, so I did. Not very complicated, but copy-and-paste is even easier :)
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Single line summary</Title>
<Shortcut>summary</Shortcut>
</Header>
<Snippet>
<Code Language="csharp">
<![CDATA[/// <summary>$end$</summary>]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
You can change the shortcut by (probably obviously) changing the <Shortcut> value.
Paste that into a new file named SingleLineSummary.snippet and save it in the folder %USERPROFILE%\Documents\Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets (modify to fit your version of Windows and Visual Studio).
If you're not familiar with snippets, to use this just put the cursor above a method/property/etc, start typing summary, and then hit TAB a couple of times.
Personally, I think this should be part of the VS editor itself. I know it's been requested in the past. In the meantime, the snippet idea is a good one, but the behavior is slightly different. If you want to keep the same behavior and if you are willing to purchase a 3rd party add-on, then SubMain has a product called "GhostDoc Pro" that, with a little bit of effort, will do this for you. (Note that they have a free, non-"pro" version, "GhostDoc", but I don't think it will work.)
If you want to go this route, here's how it works.
After installing GhostDoc Pro, go to your Tools menu. At the top will be a new fly-out submenu, "GhostDoc Pro".
Go to Tools -> GhostDoc Pro -> Options -> Rules
You will need to edit the T4 template for EACH type that you want this to take effect on.
Click on the rule and then hit "Edit"
At the top, modify
/// <summary>
///<# GenerateSummaryText(); #>
/// </summary>
to be just
/// <summary><# GenerateSummaryText(); #></summary>
In the method GenerateSummaryText, modify each this.WriteLine to be just this.Write
Hit OK to save, move on to the next template.
Before closing the options page, head up to "General" (from "Rules") and check the "Highlight auto-generated summary when Document This". This will cause the newly inserted auto-text to be selected off the bat so if you don't like it, you can just start typing. Of course, if you prefer to have the text just not generated at all, then you can do that, too, but you will have to modify the T4 templates a bit more. Specifically, you'll need to have GenerateSummaryText just use a single line,
this.Write(Context.ExecMacro("$(End)"));
This will have it not generate any text, but will put the cursor between the 2 <summary> tags.
Side Note:
If anyone knows of a way to get ReSharper or other add-on tools to do this, I'd be interested in seeing that solution as well--if for no other reason than just curiosity.
You can manually format the comment however you like it, as long as it remains valid xml.
The cheapest approach might be to disable the automatic comment-building action in Visual Studio (Tools > Options > Text Editor > C# > Generate XML Documentation comments for ///) and use a code snippet to insert /// <summary></summary>.
If you want the default format to be a single line, and/or help to keep the format tidy and readable, my addin Atomineer Pro Documentation may also be of interest. Among the many options is one to use a compact 1-line format for any comment that is short enough to fit on a single line. It is specifically designed to do this, so it may work better for your needs.
A final suggestion is that there are several other add-ins (Resharper, etc) that can generate simple boilerplate xml doc-comments - I believe some of these addins can be configured to use a particular text snippet. If you already have such an addin, it may be that yours can be adjusted to provide the one-line format you require, in a slightly more advanced manner than is possible with the basic Visual Studio tweak suggested above.
I was trying to do this today. I couldn't find a way to change it to happen automatically, so I figured I could do it afterward with find and replace and regex. It isn't a good answer to this question, but it doesn't appear there is a good answer and all the answers are workarounds. This is a good work around.
VS with Regex
Find: (/// <summary>)\r\n\s*///\s*(.*)\r\n\s*///\s*(</summary>)
Replace: $1$2$3
Notepad++ with regex
Find: (/// <summary>)\r\n\s*///\s*(.*)\r\n\s*///\s*(</summary>)
Replace: \1\2\3
Related
If I create an item template with default name foo.txt, Visual Studio by default offers the name foo1.txt in the add new dialog, even if there is no foo.txt in the folder.
This is normally fine, but I would need to create an item template, that does not offer a "1" suffix for the file name by default, exactly like the App.config template behaves.
I have checked the App.vstemplate file in the VS2019 installation, but I don't see any special setting that would cause this behavior.
Sample:
<?xml version="1.0" encoding="utf-8"?>
<VSTemplate Version="3.0.0" Type="Item" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<DefaultName>foo.txt</DefaultName>
<Name>Foo.txt file</Name>
<Description>A foo.txt.</Description>
<ProjectType>CSharp</ProjectType>
</TemplateData>
<TemplateContent>
<ProjectItem>foo.txt</ProjectItem>
</TemplateContent>
</VSTemplate>
Shows in the add new dialog as:
Sorry but I'm afraid the answer would be negative. I think this
behavior is by design and can't be controlled by any Element in the
.vstemplate.
I've reproduced this issue in my side. And one interesting thing I found is if we change the file extensions to .manifest and this issue goes away.
For example:
If the Item template I want to create is something like a foo.manifest instead of foo.txt, then when I add this item in new project it won't display the 1 suffix. You can easily confirm this point by change all your foo.txt content to foo.manifest.
I agree with Will that they're special casing some of the templates. And to be more specific, this behavior is special for the file extensions of the Item we created. I haven't done anything differently when creating xxx.manifest Item, but it just makes a difference from the xxx.txt Item. So I would think there is a invisible and unknown rule to control this behavior, and this behavior may not be changed or controlled in custom extension. It would be something like a rule designed by the Product Team I believe.
In my opinion, it's not supported by current VS SDK to control the behavior to let VS won't display '1' suffix for item whose file extension is .txt. And if you do want this feature, go Developer Community to share your great idea there. Actually after your reminder, it would be better if this feature comes then we can really control the Default Name, so if you decide to post your idea, share the link in your question and members interested in it would help vote for it.
Hope it helps and if i misunderstand anything, feel free to let me know:)
I am using MS Visual Studio 2015 and I am trying to do some documentation and description of methods I made. I use the /// comment and would like to highlight exception class names in IntelliSense popup. So I would like to get result like ... does fancy things and sometimes blows with DivideByZeroException, because you are not Chuck. with DivideByZeroException being with the same color as classes usually are in the body of summary text. Seen the picture below.
How this can be reproduced, please? I tried to look into MSDN database, but I didn´t managed to find a way (if it can be done).
Preface: I am the asker of this question, so this is the reason of "me-style" answer :-)
I had recently looked into this and it seems as it cannot be done as I was hoping. According to this post on SO, and this MSDN documntation, the behaviour I was hoping to reproduce in the bulk of summary text is a speciality of exception documentation tag:
<exception cref="DivideByZeroException">Thou' are not Chuck</exception>
what might do the trick is <c> or <code> tags. Unfortunately, they do not seem to do anything in my VS2015 Express IntelliSense, so I cannot verify this.
Maybe you can do it like below.
/// <summary>
/// ... does fancy things and sometimes blows with DivideByZeroException, because you are not Chuck.
/// </summary>
/// <exception cref="DivideByZeroException" />
I am using VS2015 community edition.
I am using Visual Studio 2015, and I want to add https://appsforoffice.microsoft.com/lib/1/hosted/office.js as an IntelliSense reference. So I did the following:
But the IntelliSense still does not work:
Could anyone help?
Getting the basics of JavaScript IntelliSense working is pretty straightforward – all you need to do is, in your JavaScript file, have a triple slash reference to the CDN location, as follows:
/// <reference path="
https://appsforoffice.microsoft.com/lib/1/hosted/office.js" />
In projects created with the Office Add ins template, the reference is already built in, in the Scripts/_reference.js file. The Scripts/_references.js file is a special file that acts as a "global" JS reference for the project, so that you don't need to include the /// <reference path="..." /> on every file. For more information on the _references.js file, see this excellent blog post by Mads Kristensen, creator of the “Visual Studio Web Essentials” extension: http://madskristensen.net/post/the-story-behind-_referencesjs.
Note that the above location is for the “prod” version of the CDN. For the beta endpoint, use "https://appsforoffice.microsoft.com/lib/beta/hosted/office.js", and for a local installation of Office.js point to the Office.js file (typically under "Scripts/Office/1/office.js).
TIP: Every once in a while, I've come across cases when the IntelliSense file appears stale. For example, while I know for a fact that the Excel Range object contains a “.merge()” method, IntelliSense was refusing to show it to me one day.
In these cases, you can refresh the JavaScript references by via the menu, by going to Edit -> IntelliSense -> Refresh Remote References, or via the VS Quick Launch box.
Is there any way to make visual studio dim or hide/show on demand logging lines of my code?
We use a lot of logging in our project and it's harder to read code like this.
I would like it to be like this, for example:
Unobtrusive Code extension worked for me for Visual Studio 2019. It dims the opacity of log lines (and comments, which I disabled - I enjoy reading my comments). He did a quick update for the nuget package, and it works great.
https://marketplace.visualstudio.com/items?itemName=niklaskallander.UnobtrusiveCode
I use this. Hoping one day they will add color customization and line selection regex options as well:
https://marketplace.visualstudio.com/items?itemName=ElmarXCV.GrayLogLines
There is no way to do this from the standard Visual Studio IDE. In order to do this you would need to define a custom extension which recognized lines like this, tagged them with a specific format and have that format be colored a lighter color in the IDE
a "hackier" way would be to wrap all logging in a preprocessor directive like
#if DEBUG
Log.Info(........)
#endif
Visual-Studio will "dim" the code inside.
and have some kind of config header where you
#define DEBUG 0
Not the prettiest but its nice if you don't want debug code compiled into your Release binary
why don't you put your section within #region tag.
E.G:
#region Put some region name here for your reference
Your Code / Comment / Whatever
#endregion
If I am editing a .js file in Sublime Text 2 that makes use of a library defined in a separate .js file, is there a way to support tab completion of objects/functions defined in the external library file?
Something analogous to the following from Visual Studio:
/// <reference path="/js/some-library.min.js" />
which enables IntelliSense over the library/plugin code.
I haven't tried it myself yet, but there's SublimeCodeIntel: https://github.com/Kronuz/SublimeCodeIntel#readme
The OP in this thread: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=5319 seems to be complaining that it's pulling suggestions from outside the current file, which may mean it's doing what you want.
I was looking for the exact same thing, and I can confirm that SublimeCodeIntel works well. However, Sublime Text seems slightly less responsive when using SublimeCodeIntel, which is a drawback.
Another cool thing coming from a Visual Studio environment is the support for "Go to definition" in this plugin.
Another option is TernJS:
http://emmet.io/blog/sublime-tern/
I haven't yet used it, but it looks promising. Editor slowdown seems to be an issue with any code completion plugin; sounds like authors are still working out kinks in scraping and caching related files for code completion. The TernJS page addresses this issue and offers some config options for managing how it handles related files.