Cli tool throws exception when dispatching and calling into "PlatformAbstractions" APIs
See original GitHub issueSteps to reproduce
Repro repo here.
I have a tool that needs to load the target project, which targets the full .Net framework. As a result, I should dispatch the execution to the context of the target tfm (so net46 for example), because cli tools are always executed in the context of “netcoreapp”. Dispatching like this used to work perfectly in the preview2 tooling.
After the dispatch, if I try to use any of the “PlatformAbstractions” APIs the following exception occurs:
Unhandled Exception: System.IO.FileLoadException:
Could not load file or assembly 'Microsoft.DotNet.PlatformAbstractions, Version=1.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
This line works when the context is “netcoreapp”, but it throws the exception after the dispatch to “net46”.
This is a major problem because “Command.CreateDotNet” fails as a result. My tool has a reference to “Microsoft.DotNet.Cli.Utils” v1.0.1 which I suspect is the root of the problem. Or maybe this is not how dispatching should be done in 1.0? (which I doubt, because when PlatformAbstractions is not involved, everything works).
I can’t find info or documentation at all about this. What’s going on?
Environment data
dotnet --info
output:
.NET Command Line Tools (1.0.0)
Product Information:
Version: 1.0.0
Commit SHA-1 hash: e53429feb4
Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\1.0.0
For reference this is the tool I maintain.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:22 (8 by maintainers)
Top GitHub Comments
According to NuGet and project.assets.json the lowest version is indeed 1.0.3, but after building the project there’s definitely a reference to 1.0.1 (InformationVersion 1.0.1-beta). Same for Microsoft.Extensions.DependencyModel.
Here’s a minimum .csproj to reproduce: Just run
dotnet restore && dotnet build
It also reproduces with netcoreapp1.0, but it’s easier to see the output with net462.
Update: Did some more testing and
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="1.0.3" />
downloads the 1.0.1.0 (1.0.1-beta) package. Same forMicrosoft.Extensions.DependencyModel
Just wrote a prototype and it indeed does not work yet. The project were I include a tool that only targets
net46
throws aNU1202
error during package restore:Package tool-x 1.0.0 is not compatible with netcoreapp2.0.
I just found a newer version of
DotnetToolDispatcher
here: https://github.com/aspnet/Scaffolding/blob/8675aa97cd967d92bfa98e4008feb98853ca25e6/src/Shared/DotNetDispatcher/DotnetToolDispatcher.cs Note the methodEnsureBindingRedirects
. I’m slightly optimistic they fixed the binding redirect issue.@livarcocc : Is there an official way to get to work what @mrahhal described (a cli tool that targets netfull)? Or at least an official NuGet package with
DotnetToolDispatcher
? Because currently the source is copied over manually an part of the tool project, which seems error prone.