MSBuildLocator icon indicating copy to clipboard operation
MSBuildLocator copied to clipboard

Is there a way to avoid needing the exe.config with bindingRedirects?

Open galensoft opened this issue 1 year ago • 1 comments

Hi! When I build my analyzer it has some generated bindingRedirects but I don't understand why. I would like to understand why to see if there's a way to avoid it so that I can distribute my analyzer as a single exe that is framework dependent. The exe.config looks like this:

<?xml version="1.0" encoding="utf-8"?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> </startup> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Build" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-15.1.0.0" newVersion="15.1.0.0" /> </dependentAssembly> </assemblyBinding> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-15.1.0.0" newVersion="15.1.0.0" /> </dependentAssembly> </assemblyBinding> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Build.Utilities.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-15.1.0.0" newVersion="15.1.0.0" /> </dependentAssembly> </assemblyBinding> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Build.Tasks.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-15.1.0.0" newVersion="15.1.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>

This project started from the template Standalone Code Analysis Tool in Visual Studio

galensoft avatar Jun 19 '24 08:06 galensoft

Hi @eriknielsen,

I have no insight on why it was added. Hopefully, @rainersigwald can tell us more.

YuliiaKovalova avatar Jun 19 '24 08:06 YuliiaKovalova

These binding redirects are required for MSBuild tasks to work compatibly. Specifically, if an old task was compiled against (say) Microsoft.Build.Framework version 14.0.0.0, it will fail at runtime if the binding redirects aren't present, because it would try to communicate with its host MSBuild engine using v14 types that are either unloadable (if the files can't be found) or mismatched with the v15.1 assemblies (if they exist somewhere).

rainersigwald avatar Jul 31 '24 15:07 rainersigwald