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.