I have an issue working with Microsoft.Build.BuildEngine which supposed to get fixed modifing my .exe.config file to add the following.
<?xml version ="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urnchemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
</dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Engine" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
My problem is, I can't modify the file, I have to fix it by code, and I think that's supposed to be possible, right?
But how?, how can I modify my application so it runs as if the above changes were made on the config file?
I was just struggling with a similar problem. The key is to use the AppDomain.AssemblyResolve event. Here's what my code looks like:
This completely ignores the version number and substitutes the already loaded library for any library reference named "FooLibrary". You can use the other attributes of the
AssemblyName
class if you want to be more restrictive.FooClass
can be any class in the FooLibrary assembly.