SharePoint 2010, Powershell and BindingRedirects

Powershell is a great tool when working with SharePoint 2010!

However there is one thing to be wary of: BindingRedirects.


In SharePoint 2010 you probably used the following xml in a solution package:

<?xml version=”1.0″ encoding=”utf-8″?>
<Solution xmlns=”http://schemas.microsoft.com/sharepoint/“>
<Assemblies>
<Assembly Location=”{YourDllName}.dll” DeploymentTarget=”GlobalAssemblyCache”>
<BindingRedirects>
<BindingRedirect OldVersion=”1.0.0.0″/>
</BindingRedirects>
</Assembly>
</Assemblies>
</Solution>

And your controls and code is updated from 1.0.0.0 to the latest version (for example: 1.1.0.0) in SharePoint 2010!

However! Not in Powershell!

So if you use powershell for example to create a number of sites based on a custom site defintion with for example custom provisioning code which still references the old version, that version, if it exists on the machine, is used or if it doesn’t exists throws the following error:

Could not load file or assembly ‘{YourDllName}, Version=1.0.0.0, Culture=neutral, PublicKeyToken={PublicKeyToken}’ or one of its dependencies. The system cannot find the file specified.

You could solve this by editing/adding the powershell config file.

Powershell is located on 32-bit systems here is C:\Windows\System32\WindowsPowerShell\v1.0,
on 64-bit systems here C:\Windows\SysWOW64\WindowsPowerShell\v1.0.

Edit/Add the file powershell.exe.config and add the following (make sure to change these to the correct version numbers and make sure to add the correct assembly name and public key token):

<?xml version=”1.0″?>
<configuration>
<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<dependentAssembly>
<assemblyIdentity name=”{YourDllName}” publicKeyToken=”{PublicKeyToken}” culture=”neutral” />
<bindingRedirect oldVersion=”1.0.0.0″ newVersion=”1.1.0.0″ />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Restart powershell and it should use the correct version.

Advertisements

One thought on “SharePoint 2010, Powershell and BindingRedirects

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: