question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet msbuild can't load custom task dependencies

See original GitHub issue

Steps to reproduce

git clone https://github.com/ADFCommunity/Adfc.Msbuild
cd Adfc.Msbuild
git checkout feature/crossplat
msbuild /t:restore,build Adfc.Msbuild.sln
msbuild samples\OneConfig
dotnet msbuild samples\OneConfig

This repo is a msbuild task for a custom project type. I tried to get it to run cross platform, but the dotnet cli doesn’t appear to be able to load my task’s dependencies (which are in the same directory as my task’s dependencies).

If you want to reproduce this bug without cloning my repo, create an assembly that targets net46 and netstandard1.5. Add Newtonsoft.Json as a dependency (or any other nuget package), and the relevant Microsoft.Build packages needed to create a task. Edit the csproj to set the property CopyLocalLockFileAssemblies to true, so dependencies are in the same bin\debug\TFM directory as your assembly. Write a MSBuild task that uses the nuget package, in any minimal way. Create a separate msbuild proj file that uses the task from your assembly. Run it using the Windows msbuild.exe, and the build will succeed. Run it using dotnet msbuild and the dependency assembly will fail to load.

Expected behavior

dotnet msbuild samples\OneConfig should be successful, just as msbuild.exe samples\OneConfig was.

Actual behavior

The .NET Core MSBuild task crashes, unable to load Newtonsoft.Json.dll, while the MSBuild.exe run completes successfully.

C:\git\Adfc.Msbuild\src\Adfc.Msbuild\bin\Debug\Adfc.Msbuild.targets(23,5): error : exception trying to load file System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)\r [C:\git\Adfc.Msbuild\samples\OneConfig\OneConfig.proj]
C:\git\Adfc.Msbuild\src\Adfc.Msbuild\bin\Debug\Adfc.Msbuild.targets(23,5): error : File name: 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'\r [C:\git\Adfc.Msbuild\samples\OneConfig\OneConfig.proj]
C:\git\Adfc.Msbuild\src\Adfc.Msbuild\bin\Debug\Adfc.Msbuild.targets(23,5): error :    at Adfc.Msbuild.JsonFileLoader.Parse(String text, String identity)\r [C:\git\Adfc.Msbuild\samples\OneConfig\OneConfig.proj]
C:\git\Adfc.Msbuild\src\Adfc.Msbuild\bin\Debug\Adfc.Msbuild.targets(23,5): error :    at Adfc.Msbuild.AdfcBuild.<LoadJsonFiles>d__10.MoveNext() in C:\git\Adfc.Msbuild\src\Adfc.Msbuild\AdfcBuild.cs:line 69\r [C:\git\Adfc.Msbuild\samples\OneConfig\OneConfig.proj]
C:\git\Adfc.Msbuild\src\Adfc.Msbuild\bin\Debug\Adfc.Msbuild.targets(23,5): error : \r [C:\git\Adfc.Msbuild\samples\OneConfig\OneConfig.proj]
C:\git\Adfc.Msbuild\src\Adfc.Msbuild\bin\Debug\Adfc.Msbuild.targets(23,5): error :  [C:\git\Adfc.Msbuild\samples\OneConfig\OneConfig.proj]

Environment data

.NET Command Line Tools (2.0.0)

Product Information:
 Version:            2.0.0
 Commit SHA-1 hash:  cdcd1928c9

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16273
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
rmsuttoncommented, Apr 28, 2018

I am running into a similar issue here. Is there a solution for this?

2reactions
rainersigwaldcommented, Oct 18, 2019

The biggest step for this will be with microsoft/msbuild#1754. That should transparently resolve some of the harder conflicts with, for example, Newtonsoft.Json.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom msbuild task tries to load dependency with wrong ...
MsBuild itself includes a dependency on Newtonsoft.Json 11.0.1, so custom tasks can't load any other version of this dependency.
Read more >
Create a custom task for code generation - MSBuild
In this tutorial, you'll create a custom task in MSBuild in C# that handles code generation, and then you'll use the task in...
Read more >
MSBuild tasks with dependencies
Workarounds. MSBuild tasks aren't well suited for dependencies beyond the task assembly itself. Although there is an issue open on MSBuild to ...
Read more >
Msbuild cannot find references. framwork. Check both of these a
You cannot reference any MSBuild types (from the Microsoft. dll and Ionic. NET Framework, and a target platform, which is a particular software ......
Read more >
Managing Dependencies in .NET: .csproj, .packages.config ...
Get an overview of the artifacts involved in .NET dependency management, how they interact, and how to use them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found