Fix for metadata generation failed exit code: 2147450750 loading wrong version of DLLs when building Azure Functions

The Problem Recently an Azure DevOps Pipeline for a .NET 6 based Azure Functions started to fail on some of our self-hosted build agents with the error ##[error]C:\Users\Administrator\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\4.0.1\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(37,5): Error : Metadata generation failed. Exit code: '-2147450750' Error: 'Failed to load the dll from [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.NETCore.App\3.1.32\hostpolicy.dll], HRESULT: 0x800700C1An error occurred while loading required library hostpolicy.dll from [C:\hostedtoolcache\windows\dotnet\shared\Microsoft.NETCore.App\3.1.32]' The pipeline it self was simple, just repeating the steps a developer would use locally - task: UseDotNet@2 displayName: "Use .NET 6" inputs: packageType: sdk version: 6.x performMultiLevelLookup: true - task: DotNetCoreCLI@2 displayName: "dotnet restore" inputs: command: restore projects: "$(Build.SourcesDirectory)/src/Api.sln" feedsToUse: "select" vstsFeed: "aaa33827-92e2-45a0-924a-925b0d6344677" # organisation-level feed - task: DotNetCoreCLI@2 displayName: ".NET Build" inputs: command: "build" arguments: > --configuration ${{ parameters.buildConfiguration }} --no-restore projects: "$(Build.SourcesDirectory)/src/Api.sln" The Cause The issue was that the dotnet build was picking up a .NET 3.1 version of the hostpolicy.dll from the cache. This was even though the pipeline was set to use .NET 6, and I could see both .NET 3.1 and .NET 6 SDKs in the cache folder. ...

July 19, 2023 · 3 min · Richard Fennell

Update on sending social media posts from Hugo based static site

Around a year ago I posted on ‘Social Media Posts after Migrating from WordPress to Hugo Static Pages’. Recently I have found that the Twitter functionality in my Logic App was failing. Turns out this was due to the changes in the Twitter Free API, with them moving from V1 to V2 which requires OAuth authentication as opposed to a Bearer token. In essence the core of the problem is that the built-in Logic Apps Twitter Connector only supports the V1 Twitter API. So the only option was to create my own custom solution. ...

July 13, 2023 · 1 min · Richard Fennell

How to run your own maintenance job on Azure DevOps pipelines

Updated: 19 Jul 2023 - Revised the post to use Az CLI Task as opposed to a PowerShell Task Updated: 29 Aug 2024 - Revised the PowerShell as original version was not working. Also see follow up post on using Workload Identity federation Background Azure DevOps Pipelines have a built in mechanism to run maintenance jobs on a schedule. This is great for cleaning out old temporary data, but what if you want to run your own maintenance job? ...

July 12, 2023 · 5 min · Richard Fennell

Bit rot is killing my pipelines

In a modern hybrid cloud world we have to accept constant change as the norm. You can’t just build something and forget about it. You have to keep it up to date as newer tools/libraries appear. This is to at least address security issues, even if you don’t want to adopt the new features. So I am expecting a degree of maintenance work on my Azure DevOps pipelines. However, this is becoming more awkward as many of the tasks used by Azure Pipelines, even ones from Microsoft, are themselves not being maintained. ...

April 26, 2023 · 2 min · Richard Fennell

Moving my Azure DevOps Pipeline generated social posts to Azure Logic Apps

I posted a while ago about how I had automated the generation of social media posts for my static Hugo based website using Azure Logic Apps. The other place I auto-generate social media posts is from releases via my project’s Azure DevOps Pipeline builds. These use a YAML Pipeline Template that calls a Marketplace task to post to Twitter and a PowerShell task to Invoke-WebRequest to post to Mastodon. Recently the Twitter task started to fail, and given the recent changes to the Twitter API with the move to the V2 API, I decided a new solution was required. ...

April 25, 2023 · 2 min · Richard Fennell

A more secure alternative to PAT tokens for accessing Azure DevOps Programmatically

Background When working with Azure DevOps, you may need to access the REST API if you wish to perform scripted tasks such as creating work items, or generating reports. Historically, you had to use a Personal Access Token (PAT) to do this. If you look in my repo of useful Azure DevOps PowerShell scripts you will find all the scripts make use of a function that creates an authenticated WebClient object using a passed in PAT token. ...

April 21, 2023 · 3 min · Richard Fennell

Downloading NuGet packages with 'System.Net.WebClient' from an Azure DevOps Artifact feed

Background We use Lability to build Windows Server images for our test labs. Lability makes use of Desired State Configuration (DSC) to build the VM images. Part of this process is for Lability to download DSC modules, as ZIP files, from a NuGet feed such as PowerShell Gallery to inject into the created VM image. Historically, we have stored our own private DSC modules on an internally hosted NuGet server. However, we wanted to move these modules to a private Azure DevOps Artifacts feed. The problem was that Lability does not support downloading of DSC modules from Azure DevOps Artifact feeds, whether they are public or private, because of the way the package URLs are constructed. ...

April 1, 2023 · 2 min · Richard Fennell

Pinning specific Azure DevOps task versions

I make every effort keep all my Azure DevOps Pipeline extensions reliable as I know they are used by many people, but mistakes happen. Yesterday I released an updated version of my ReleaseNotes task that introduced a bug if the pipeline produced no artifacts. I am pleased to say I have fixed the bug, and addressed this gap in my test coverage. However, this did mean for about 12 hours if you are using this task in a pipeline that did not produce artifacts, maybe one that just deployed consumed artifacts from other pipelines, you had a failing pipeline. ...

March 8, 2023 · 1 min · Richard Fennell

Getting x86 .NET 3.x tests running on the latest Azure Devops hosted agents

Background At Black Marble we have our own private build agents, but they are built using the same Packer process as the Microsoft hosted ones. I recently rebuilt our agents to match the latest version of the hosted agents, and I ran into an issue with some .NET 3.1 based x86 MSTests. The tests were failing with the following error: A total of 34 test files matched the specified pattern. ##[error]Testhost process exited with error: A fatal error occurred. The required library hostfxr.dll could not be found. ##[error]If this is a self-contained application, that library should exist in [E:\Agent\_work\1\s\src\Ux.Common.UnitTests\bin\x86\Release\netcoreapp3.1\]. ##[error]If this is a framework-dependent application, install the runtime in the global location [C:\Program Files (x86)\dotnet] or use the DOTNET_ROOT(x86) environment variable to specify the runtime location or register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]. When I checked the folder C:\Program Files (x86)\dotnet it was not there, .NET 3.1 x86 was no longer present on the agent. ...

March 6, 2023 · 2 min · Richard Fennell

Getting "cannot find path" error using Install-Package

Background I was recently trying to use PowerShelGet Install-Package to install a module from an Azure DevOps Artifacts hosted PowerShell Gallery using the following script # For authentication use a PAT as the password, UID can be anything $PATcreds = Get-Credential Register-PSRepository -Name BM -SourceLocation 'https://pkgs.dev.azure.com/<org>/_packaging/PowerShell/nuget/v2' -PublishLocation 'https://pkgs.dev.azure.com/<org>/_packaging/PowerShell/nuget/v2' -InstallationPolicy Trusted Install-Package BlackMarble.Package -Source BM -Credential $PATcreds The script did not work I was getting the error Install-Package : Cannot find the path ‘C:\Users<user>\AppData\Local\Temp\936930114\BlackMarble.Package\BlackMarble.Package.0.3.79\BlackMarble.Package.psd1’ because it does not exist. You could see a download progress bar that suggested the download had occurred, but no module was installed. ...

February 27, 2023 · 1 min · Richard Fennell