Roger Johansson
Roger Johansson

Reputation: 23214

Ship Dependencies or Nuget references with custom MsBuild task Nuget

I'm trying to ship a custom MSBuild task that makes use of 3rd party Nugets. I could either reference those Nugets or just copy their assemblies to a folder, But the question remains: How do I get those dependencies into my MsBuild task Nuget?

For "normal" Nugets, it's not an issue to just reference external Nugets. but.. MsBuild tasks require the assemblies to be present in order to execute.

The MsBuild task currently fails with an assembly load exception on the 3rd party assemblies.

What are my options here?

Upvotes: 1

Views: 237

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100741

You need to construct your task package so that the external dependencies are next to the task assembly for MSBuild to resolve them correctly. Do make sure that your resulting NuGet package does not reference these dependencies as well (so consuming projects don‘t get that dependency transitively only because your task needs them)

Recent versions of MSBuild 16 also use AssemblyLoadContext versions on .NET Core so there should be less risk of assembly conflicts with in-box / SDK assemblies.

Upvotes: 2

Related Questions