Reference resolution with Code Analysis/FxCop

Just ran into an interesting problem whilst using NuGet for adding references to my project. If you add a library A, and then another library B that depends on an earlier version of A, then you’ll run into problems because NuGet will see you have a later version of A and therefore not install the older version, but B will still look for the version of A that it was expecting. To resolve this, you need to add a binding redirect (see here for more details), which can be done easily using the Package Manager Console and a swift


run against the project in question. However, although this fixes your runtime issues, code analysis still fails (with an error similar to “CA0058: The referenced assembly A could not be found. This assembly is required for analysis and was referenced by: B.”), because it resolves references differently at compile time (helpfully), ignoring any of your binding redirects. The blog post here describes two workarounds: the obvious one is to add a reference to the version of A that B was looking for, but this is messy, and will require you to do additional work beyond NuGet. The solution I took was to change FxCop’s settings to ignore versions when resolving references, which is done by changing the config file at C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe.config (or similar), using the following setting under appSettings:

<add key="AssemblyReferenceResolveMode" value="StrongNameIgnoringVersion" />

Hey presto.

2 Replies to “Reference resolution with Code Analysis/FxCop”

  1. What if your code is build on someone else’s machine? Are going to change there as well?and on evry machine its built? on build srver?

Leave a Reply to nishakant Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.