Add a bindingRedirect to the web.config declaratively in SharePoint 2007

1k views Asked by At

It is possible to add keys to the web.config by creating a file: 12/CONFIG/webconfig.name.xml (See http://msdn.microsoft.com/en-us/library/ee413929.aspx) With contents:

<actions>
<add path="configuration/SharePoint/SafeControls">
    <SafeControl
        Assembly="CustomWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456789abcdefgABC"
        Namespace="CustomWebPart"
        TypeName="*"
        Safe="True" />
</add>
<add path="configuration/runtime/assemblyBinding">
  <dependentAssembly>
     <assemblyIdentity name="CustomWebPart" publicKeyToken="123456789abcdefgABC" culture="neutral" />
     <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
</actions>

This works great for adding safe controls, but it doens't seem to work for assembly redirects. Does anyone have an idea why this doens't work? Is it maybe the case only tags inside "configuration/SharePoint/" can be added?

1

There are 1 answers

1
Ryan On BEST ANSWER

You can't add binding redirects on deployment with configuration files in SharePoint 2007 (though you can in 2010) so you would have to write code to do this using SPWebConfigModification.

Beware though its not easy - just search on SPWebConfigModification and check out the first page of results.

As an alternative I've got to ask why you might want to do this - if this is just versioning minor changes (i.e. v1.1 > v1.2) then perhaps this is not the best way to do this - check out file assembly versioning instead.