Tuesday, April 28, 2020

Collapse Comments (v1.4) and expand them

Comments (in code) can be really helpful. But, at other times they can get in the way of the code you're working on.

It's for the times when I just want the comments to get out the way that I created the Collapse Comments extension for Visual Studio 2019. It adds a simple command to collapse all the comments in the open document that you can invoke by pressing Ctrl+M, Ctrl+C.

I've just released version 1.4 and this includes something new. It includes the ability to do exactly the opposite of what I specified above. It adds another command that will expand all comments and collapse everything else.
It's not a scenario I have to deal with a lot but came as a suggestion (thanks Morten) who frequently looks at the decompiled code (and comments) that Visual Studio can generate. The generated file lists method names with comments (which are automatically collapsed upon opening) and it's the comments that are most important here for understanding all the different overloads. For this reason, it makes sense to be able to quickly expand all the comments by pressing Ctrl+M, Ctrl+D.


There's an option to control whether to treat using (or imports) directives like comments, and it works with C#, VB.NET, and XML documents.


Get it now, for FREE, from the Visual Studio Marketplace.

Got thoughts about this? Why not leave a comment below? I promise not to hide it away ;)

Monday, April 20, 2020

How to use VSIXSignTool

Trying to be a good developer/publisher, I sign my Visual Studio extensions.


Signing VSIXs is optional but it sends a good signal. Plus I have a code-signing certificate because I had to get one to sign NuGet packages as they MUST be signed.

But knowing how to sign a VSIX isn't obvious.
When I first wanted to sign an extension I was using Visual Studio 2017 and found the Extensibility Tools for Visual Studio from Mads Kristensen. This includes a UI for signing the generated package.

This was all good until I moved to exclusively use Visual Studio 2019. Those extensibility tools aren't supported in VS2019 so I was stuck.

To unblock myself, I ported the signing functionality, from the above-referenced tools, into a separate package that works with VS2019. A few hundred other people have also used this so I guess they were in a similar situation to me.

Fast forward to a week or so ago and I came across the NuGet package Microsoft.VSSDK.Vsixsigntool

This looked very interesting but lacked instructions on how to use it.
There's a link to some release notes but they're for "Visual Studio 2015 Update 2".
The "Project Site" link goes to the general landing page for Visual Studio Extensibility. :(

After more searching than I thought should be necessary, I eventually found https://docs.microsoft.com/en-us/visualstudio/extensibility/signing-vsix-packages?view=vs-2019
This page should be helpful but only includes some vague descriptions of what to do. :(

To try and work out how to automatically sign my generated packages using this tool, I did what I often do to solve problems relating to extension development, I searched GitHub to work out how other people had done it. Eventually, I came to this solution.

I added the following to my project file.

  <PropertyGroup>
    <VsixSignTool>$(NuGetPackageRoot)Microsoft.VSSDK.Vsixsigntool\16.2.29116.78\tools\vssdk\vsixsigntool.exe</VsixSignTool>
    <VsixSignCommand>$(VsixSignTool) sign /f $(SIGN_CERTIFICATE) /p $(SIGN_PASSWORD) /sha1 $(SIGN_CERT_HASH) /fd sha256</VsixSignCommand>
  </PropertyGroup>
  <Target Name="AfterBuild" DependsOnTargets="CoreCompile" Condition="Exists('$(SIGN_CERTIFICATE)')">
    <Message Text="Signing $(TargetVsixContainer)" Condition="'$(Configuration)' == 'Release'" />
    <Exec Command="$(VsixSignCommand) $(MSBuildProjectDirectory)\$(TargetVsixContainer)" Condition="'$(Configuration)' == 'Release'" />
  </Target>

This relies on two things:

  1. The NuGet package is referenced in the project.
  2. Add environment variables for the relevant parameters.


Points of note:
  • This allows for the certificate to be in different places on different machines.
  • This means there is no need to check the certificate into the code repository.
  • The password doesn't get checked in with the source.
  • If the environment variables aren't specified the process is skipped. This is how I avoid any issue with running this on a public CI server. It only needs to be defined on the machine that builds the release version for publishing.
  • The certificate hash was found with the following command.
>certutil -p ****** -dump ./filename.pfx

I also learned that it's possible to reference environment variables in MSBuild files. However, it's necessary to restart Visual Studio for it to pick up any changes (or additions) to these.

With this all set up, every time I build a release version of my extensions they are automatically signed without me having to do anything else. This simplifies the process and avoids me needing to enter the certificate file path and password. Yay!

There are probably other solutions with online key vaults and other such things but this works for me. Maybe this will help you too.

Saturday, April 18, 2020

ConstVisualizer v1.2 released and out of preview

My Const Visualizer extension is now at version 1.2 and out of preview.

Version 1.0 was only released this week but it has allowed me to identify some use cases that I hadn't previously accounted for. This is why I originally released it with a preview tag.

Having previously seen an increasingly broad range of code-bases, I had a very strong suspicion that there might have been things I originally missed. Thanks to people who tried out the first version and gave me feedback, the less obvious cases (to me) are now covered and it should work for all use cases where the definition of the constant is in the same solution.

For anyone who needs (or wants) to see constants defined in other code-bases (such as in referenced libraries) I'll wait for them to raise an issue to request this. ;)

Tuesday, April 14, 2020

Comment Links v1.2

I've just released an update to my Comment Links extension.

Version 1.2 adds the ability to create links through new context menu options on the editor.


No more manually composing links yourself. Now you can just put the cursor where you want the link to go to and create it that way.
The formatted link is copied to the clipboard for you to paste wherever you want it.
Copied links are also listed in the Output Pane so you can also access them from there (and even navigate from there too.)

Thanks to Michael for the suggestion.

View constants where you use them in your C# code

When debugging or just trying to understand code, it can be useful to see the value of constants. Yes, you can try and remember the values but seeing them is often easier.

The above is enabled by a new extension, I've just published, called Const Visualizer.

Yes, there's a lot of similarity between this and String Resource Visualizer.


Const Visualizer is something I've been meaning to create for a while but I've done it now as a pre-cursor to adding new functionality in the String Resource Visualizer. It's forced me to learn how to integrate Roslyn code analysis into an extension and look at other ways of analyzing the contents of a solution.

Why not put all the functionality related to const values and string resources in one extension?
Two reasons. 1. Because I prefer lots of simple tools that each focus on a single task. These can then be combined and used as preferred.  and 2. Because the existing "String Resource Visualizer" name doesn't expand well to cover other functionality too.

Please install it, give it a try, and see what you think. Does it make your coding-life easier too?

Saturday, April 11, 2020

Have you heard about text fragment anchors?

There are always lots of exciting and interesting things happening in the world of web development. One I just heard about is an experimental feature in Chrome that allows you to create links to any point on a page.

If you want the technical details, see this project from the Web Incubator Community Group.

It will work like this.

You include the text you wish to link to at the end of the URL with the special new `#:~:text=` anchor indicator.


Then the first occurrence of that text is highlighted on the page.


This is still an experimental feature and only works in some browsers. You must enable it like this:
In Chrome:

Or in the new Chromium-based version of Microsoft Edge.

Once you've enabled it and restarted your browser: give it a try


FYI. This was brought to my attention because of a project I'm doing relating to inter-document linking.

Friday, April 10, 2020

Comment Links - v1.1

Version 1 only shipped yesterday but there's a new version already.

Version 1.1 includes three changes:


  • The ability to support file and path names containing spaces. (including if they're URL encoded)
  • Support for search terms that include spaces
  • Indicating when a file can't be found (in the status bar). This also includes line numbers that don't exist or search text that can't be found.


These changes are the result of issues submitted on GitHub. Please raise any other feature requests there ;)


  • There was also a bugfix relating to navigating to the line containing the search text.


Download and enjoy.

Stay safe.


Thursday, April 09, 2020

Navigate between files of different languages in Visual Studio

Visual Studio has great tooling for navigating within code when it is in the same (programming) language.
However, if your solution contains code in more than one language and you want a quick way to navigate between files you're out of luck. Until now!

Presenting: Comment Links
Yes, it's (another) new Visual Studio 2019 extension. This one lets you put links between files anywhere in your code. In theory, this could be anywhere in your code, but in comments makes the most sense. Just include the text `link:` (case-insensitive) followed by the file name.


A green button with an arrow on it will, when clicked, open the named file.

You can also have the file open on a specific line by including the line number after `#L` at the end of the file name.

// link:mapManager.js#L25

 Or you can jump to the first occurrence of a specific piece of text

// link:mapManager.js:UpdateLocalData

For compatibility with text fragment anchors you can also use `#:~:text=` after the file name to specify the text.

// link:mapManager.js#:~:text=UpdateLocalData


Version 1.0 is in preview and available from the Visual Studio Marketplace now.
Please give it a try and tell me what you think or suggest new features on GitHub.


This project was the result of a comment from one of my GitHub sponsors. If you join them I'm likely to take any suggestions you make more seriously. ;)

Thursday, April 02, 2020

Automatically collapse code comments when opening a document

I've just released a new version (1.2) of my Collapse Comments extension for Visual Studio.

Amongst the changes are two new configurable options.


Whether using (or imports in VB) directives are collapsed as well as comments is now configurable. This is the old behavior and so is enabled by default.

The other new option is the ability to automatically close comments whenever a new document is opened. This is off by default as it's a change in behavior.

Please let me know what you think of these changes, or, even better, leave a review :)