Skip to content

[Bug]: removing the reason of bindingRedirect doesn't trigger exe.config file to be regenerated #9773

@Stalli

Description

@Stalli

Issue Description

When I add 2 references to 3rd party libraries, which have a version conflict, a bindingRedirect will be automatically added to the config file of the start-up project on the next msbuild.
But when then I remove one of the references, the config file is not regenerated on the next msbuild and still have a bindingRedirect.
A workaround is to call "msbuild /t:Rebuild" explicitly.

Steps to Reproduce

Create a project of the type "Console application" in .Net Framework 4.7.2.
Add a default App.config file.
Add an assembly reference to ServiceStack.Redis.8.0.0 located locally.
Add an assembly reference to System.Runtime.CompilerServices.Unsafe.6.0.0 located locally.
So the csproj file has the following:

<ItemGroup>
        <Compile Include="Program.cs"/>
        <Compile Include="Properties\AssemblyInfo.cs"/>
</ItemGroup>
<ItemGroup>
      <Reference Include="ServiceStack.Redis">
        <HintPath>..\packages\ServiceStack.Redis.8.0.0\lib\net472\ServiceStack.Redis.dll</HintPath>
      </Reference>
      <Reference Include="System.Runtime.CompilerServices.Unsafe">        <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
      </Reference>
    </ItemGroup>
    <ItemGroup>
      <None Include="App.config" />
</ItemGroup>

Execute msbuild in the project folder.

Intermediate result (expected): a file projectName.exe.config has the App.config content plus a bindingRedirect for System.Runtime.CompilerServices.Unsafe.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>
  <appSettings></appSettings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Remove the assembly reference to System.Runtime.CompilerServices.Unsafe.6.0.0.
Execute msbuild in the project folder.
ConsoleApplication472.zip

Expected Behavior

projectName.exe.config file should be regenerated and have no bindingRedirects. It should only contains the content of the original App.config file.

Actual Behavior

projectName.exe.config's content remains unchanged (it was not regenerated from the previous msbuild call). It contains a bindingRedirect.

Analysis

No response

Versions & Configurations

MSBuild version 17.9.5+33de0b227 for .NET Framework
17.9.5.7608

.Net Framework tested: 4.7.2 and 4.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:2Work that is important, but not critical for the releasebugtriaged

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions