Tuesday, May 19, 2020

Highlights from BUILD 2020 (so far)

I'm missing being in Seattle for the BUILD conference this year. :(
It's normally one of my favorite events and a highlight of my year.

However, like most events this year, it's gone virtual. Anyone can watch online and there are likely to be many more things that are announced.
This is what's caught my attention initially.
  • Project Reunion - Unifying and evolving the Windows development platform.
  • WinUI 3 preview - The future approach to building native Windows apps.
  • WinGet - The new Windows Package Manager can change how we distribute and install apps.
  • MAUI - Xamarin.Forms is evolving and getting a new name.  github.com/dotnet/maui

more to come....

Wednesday, May 13, 2020

More fun with comments

This is probably the least interesting screenshot I've ever shared
and this one is only slightly more remarkable
Yes, it's the same method from the same file.
But, did you spot the difference?

It's only small.
Look at the left margin.
There are more of the little outlining boxes with minus signs in them in the second image.

The first image is the default behavior. It shows something I hadn't noticed before.
By default, in a method, only multi-line comments starting with a triple-slash can be collapsed.

And the second screenshot?
Well, it turns out that as I wrote a Visual Studio extension that works with comments, these are the kind of things I learn.
As such the second screenshot shows a minor feature of the latest version (1.8) of that extension. It now lets Visual Studio know how to collapse (and expand)  multi-line comments within method blocks. (That's not a piece of code I ever imagined writing!)

Additionally, it also:
- fixes a bug in how it identifies which block to expand and collapse.
- fixes a bug that affects anyone who uses tabs instead of spaces.

Now go: download, install and review the extension for yourself.

Sunday, May 10, 2020

Spaces beats tabs (by a factor of a thousand!)


Yes, there are reasonable arguments for each approach. I know that the accessibility argument for tabs is very strong. But I use spaces. It seems that so many people also do that I'm surprised that this is still an issue.

How many more? (Well, if the title wasn't a give-away) a thousand times more!!!

I have a Visual Studio extension for manipulating comments. It recently passed a thousand installs.
I also recently had a bug filed against it. The bug only affected code that used tabs instead of spaces.

Based on this single, unscientific data-point, it looks like there are at least one thousand people using spaces for each one using tabs.

Yes:
- this isn't scientific.
- this is me twisting the statistics to make a point.
- others may have encountered this but not reported a problem.
- installs and actuals use aren't the same things.

Why is this worth blogging about?
- This number is MUCH bigger than I was expecting.
- This debate is usually based on arbitrary preference and not on data. (I have data because I'm doing something that involves code manipulation and parsing.)


I'm not bothered about which you use (as long as it's not a mixture of the two--now that's barbaric!)

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.