Ken Garrett
Ken Garrett

Reputation: 35

MSBuild Custom Task Failing to Load Dependency in Target Project

The Objective

I am writing a custom MSBuild task to handle Azure deployments locally (instead of Azure CLI, Azure Powershell, etc.). The task is using the Azure Resource Manager client library. Once the build is complete on a project, the task does authentication to Azure then uses reflection and performs the following:

  1. Load the output assembly of the target project.
  2. Finds the desired type (by a specific name) that implements the ARM deployment logic.
  3. Finds the desired methods on the type and creates delegates.
  4. Calls the delegates inside the task to run the deployment.

The Problem

When running the build on the target project, the task is throwing the following exception (I've excluded the entire stacktrace for brevity):

error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Azure.ResourceManager, Version=1.11.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8'. The system cannot find the file specified. [C:\Development\Services\Service.csproj]
error MSB4018: File name: 'Azure.ResourceManager, Version=1.11.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' [C:\Development\Services\Service.csproj]
error MSB4018:    at System.Delegate.BindToMethodInfo(Object target, IRuntimeMethodInfo method, RuntimeType methodType, DelegateBindingFlags flags) [C:\Development\Services\Service.csproj]
...

This exception is being thrown from task at the following line:

Setup setup = setupMethodInfo.CreateDelegate<Setup>(azDeployment) as Setup;

It looks as though when attempting to create the delegate, its failing to find the assembly even though the target project builds just fine with the necessary references (Azure.ResourceManager). It seems to be searching by filename as per the second line in the exception output. Here is the method in the target project that is being loaded and converted to a delegate in the task:

private void Setup(ArmClient client){}

The Question

Why can't the task find the assembly in the CreateDelegate method? Why does it seem to be searching for a file with a full assembly name instead of an actual filename?

Upvotes: 0

Views: 52

Answers (0)

Related Questions