Skip to content

Regression: VS2017 / Package References in library projects do not generate binding redirects #1595

@MichaelKetting

Description

@MichaelKetting

This might be releated to #1351 but since all the existing issues only reference EXE and/or WinEXE project types, it also feels like a different issue.

In VS2013 and VS2015, when I created a Class Library project and added NuGet dependencies, I would get binding redirects generated into the app.config file.

In VS2017, this behavior still works vor Full Framework Class Library projects using packages.config. However, when I create a .NET Standard Class Library project or switch to PackageReferences in the Full Framework Class Library, this does not work. It also doesn't help to set
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>.

It can be workarounded by setting <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> in the project file.

I assume the reason is in
https://github.com/Microsoft/msbuild/blob/master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2109

  <Target Name="GenerateBindingRedirectsUpdateAppConfig"
    AfterTargets="GenerateBindingRedirects"
    Condition="'$(AutoGenerateBindingRedirects)' == 'true' and '$(GenerateBindingRedirectsOutputType)' == 'true' and Exists('$(_GenerateBindingRedirectsIntermediateAppConfig)')">

and
https://github.com/Microsoft/msbuild/blob/master/src/Tasks/Microsoft.Common.CurrentVersion.targets#L326
<GenerateBindingRedirectsOutputType Condition="'$(OutputType)'=='exe' or '$(OutputType)'=='winexe'">true</GenerateBindingRedirectsOutputType>
If GenerateBindingRedirectsOutputType would also check for type 'Library', it would work. Actually, why check at all?

While there exists a workaround, for library authors this is a pretty major problem since the concept of semantically versioned NuGet packages breaks down if the tooling doesn't support binding redirects - it is common and intended to have mismatched dependency version numbers. In turn, this means it's not possible to run unit tests on your library without binding redirects.

Edit: Sorry, I think I might have created a duplicate of this one here: dotnet/msbuild#1310

Edit 2: Added documentation about both .NET Standard and Full Framework with Package References.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions