dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

Unresolved assembly binding redirect #4496

Open u7pro opened 5 years ago

u7pro commented 5 years ago

Why assembly binding redirect is not resolved for assembly System.Numerics.Vectors 4.0.4.1 (package : 4.5.0) ?

It should be emited on app.config as package Microsoft.CodeAnalysis.CSharp 3.0.0 depends on package System.Numerics.Vectors >= 4.4.0 (assembly: 4.1.3.0)

We have to add it manually to the app.config to avoid a FileLoadException

Steps to reproduce

Project file

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net471</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0" />
  </ItemGroup>
</Project>

Directory contents:

/
- RarDemo.csproj
- Program.cs

Program.cs content

using Microsoft.CodeAnalysis.CSharp;

namespace RarDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            CSharpSyntaxTree.ParseText("class X { private int _x; }");
        }
    }
}

Command line

msbuild RarDemo.csproj /bl

image

Expected behavior

Execute without any exception

Actual behavior

System.IO.FileLoadException: 'Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

Environment data

msbuild /version output: Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework Copyright (C) Microsoft Corporation. All rights reserved.

15.9.21.664

OS info: windows 10 v1709 (Build 16299.547)

u7pro commented 5 years ago

any chance to make this work without adding manual SuggestedBindingRedirects ?