dotnet msbuild can't load custom task dependencies
See original GitHub issueSteps 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:
- Created 6 years ago
- Reactions:5
- Comments:14 (9 by maintainers)
Top GitHub Comments
I am running into a similar issue here. Is there a solution for this?
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.