Here’s a little NuGet gem that I didn’t know and just found out about today: You can get NuGet to explicitly re-write your reassembly redirects in your .config files based on the installed NuGet Packages in the project.
You can use the following command from the Package Manager console:
PM> Get-Project –All | Add-BindingRedirect
This recreates all those assembly redirects that are defined in your web.config or app.config file for a solution and updates them to match the versions from the various packages that are installed in each project. IOW it refreshes the assembly redirects to the actually installed packages of each project.
Right on! This is something I run into quite frequently and this simple command fixes the problem easily! If you want this to work for an individual project just remove the –all flag.
Thanks to @maartenballiauw and @tsimbalar who pointed out this command to me when I was griping on Twitter about mismatched assemblies after an update to the latest ASP.NET WebAPI and MVC packages in a couple of projects. If you get “Could not load file or assembly '' or one of its dependencies.” errors when you know you have the package and assembly referenced in your project, you’re likely running into a problem related to assembly versioning and need assembly redirects. NuGet automatically creates redirects for you, but versions can get out of sync when projects with cyclical dependencies are upgraded in a single solution.
Maarten also wrote up a blog post on this and I don’t want to take away from Maartens’s post here, and instead just link you to that for a good deal more information:
I thought it was important enough to repost this here, since it’s a little known command that probably can benefit many people. I know it’s definitely a problem I run into a lot because I have a few component libraries that take dependencies on high level framework libraries that rev frequently, so it’s easy for things to get out of sync. This will help me tremendously in making sure that libraries are properly redirected.
Other Posts you might also like