dotnet_install: Error: Could not find `.NET Core Runtime` with version = 5.0.11

So I thought I’d check out Bicep today. I had to create some ARM templates and I am not a huge fan of these… and with Bicep 0.3 released some time back maybe I could dip my toes into it? There’s an Ignite video demoing this so I am watching it to follow along.

I create a something.bicep file in VS Code and it throws up this error:

And I then spend the next 30 mins or so trying to fix this rather than learn Bicep. Eugh!

If you Google for this error the official answer is the to increase the timeout or specify the path to an existing dotnet install.

But this does not work!

A quick digression

In case you wondered what is that // @sync os=mac bit??

I use the Settings Sync extension by Shan Khan to keep my VS Code installs in sync. Yes VS Code has an official sync mechanism now, but I have been using this for ages and don’t want to switch over sync mechanisms and risk breaking anything. The Settings Sync is a damn useful extension and I’ve even contributed to the author for taking the time to create this.

Anyways, if you have multiple OSes the Settings Sync extension has a useful feature called Sync Pragmas. For instance, the path I put above is for macOS… but obviously I don’t want that being synced over to my Windows or Linux machines as I have different paths there. Or even within macOS my M1 Macs might have a different path to something compared to the Intel ones. This is where Sync Pragmas come in. If I have a setting and I add a “pragma” like above limiting it to os=mac then it will be ignored on all other OSes.

I don’t even have to exclude/ include by OSes. On my Linux laptop for instance the screen is small and I want a slightly larger font. But for all other machines I am happy with the font size (which is the same across all of them). So I have the following on this Linux laptop:

Now all other machines ignore these two settings from this laptop. So cool!

Check out the Sync Pragmas wiki for more examples. I can sync per OS, host, or environment.

And now back to the topic on hand

Anyways, the settings changes above didn’t make a difference. I definitely have the correct version of .NET installed:

But I re-installed it anyways, and also re-installed .NET Core just in case (coz that’s you do when you don’t want to spend time fixing a problem you are not interested in fixing… you do stupid things ☺️).

.NET gives me trouble with ARM templates too and the fix for that is similar… specify the path. And I have that as a setting already (which I restrict to macOS only):

Then I started digging into the extension that was generating the errors. It seemed to be running a script from /Users/rakhesh/.vscode/extensions/ms-dotnettools.vscode-dotnet-runtime-1.3.0. There wasn’t anything of interest there, but I learnt this is an extension that installs .NET for you. Interesting… so this wasn’t the Bicep extension but something that extension was calling.

Looking at the extension page in my VS Code install I saw that the default values of the settings are specified on a page.

Maybe the dotnetAcquisitionExtension.existingDotnetPath property has a typo? I tried changing it from an array to a regular property:

I didn’t bother saving this as VS Code complained straight away that it needs to be an array. Hmm. Ok, so it expects an array of extensions and the .NET path for that extension? Makes sense. This way you could have different .NET paths per extensions – I dunno why an extension would need that, but then I don’t know much about .NET so I’ll assume that’s something useful.

So… is msazurermtools.azurerm-vscode-tools the name of the Bicep extension?

Hah! It is not. So that’s the issue. Let’s add the Bicep extension too the list:

Close and re-open VS Code, open the Bicep file… and tada, all’s good!

Now I can finally go back to learning Bicep! But wait, I have to blog about this first… so now that I’ve reached the end of this post I can go back to learning Bicep. Yay!

Update: This is becoming a habit. I blog about this, go back to reading Bicep, and the very next page in the official docs has the above solution. 🤦‍♂️