There seems to be a bug in Visual Studio 2010 when adding references to Silverlight projects.  You can add “regular” .Net references just fine using the add reference dialog.  However if you use the browse feature to find a reference in an “unusual” location, Visual Studio is supposed to record that location along with the reference in the .csproj file.  It includes the location via the HintPath property.

At my company, we use build machines and we don’t like to install a lot of software on them.  So in source control we have a folder (assets\lib) that includes all of the necessary .dll files that we need to build or projects.  When we add references to our project, like for a Silverlight control library, we add it from the assets\lib\Silverlight folder, even though that library is installed on my local machine.  Anyway, when I tried doing this in Visual Studio 2010 (I’m upgrading our existing 2008 solution), VS 2010 isn’t including the HintPath.  If you aren’t careful, you may not realize this is happening.  That’s because since the library is installed on my machine, the build works just fine, except it pulls the .dll from the wrong place.  If I were to try this build from my build server, it would fail though. 

Anyway, here is the workaround.  It’s a pain but it works…

  1. Add your references as you would normally do it via Visual Studio.
  2. Right click the project file in the Solution Explorer and choose Unload Project.
  3. Once the project is unloaded, right click again and chose edit.  This will open the file, and xml document, in Visual Studio.
  4. Find the incorrect reference in the file and edit it manually.  You’ll need to make it look something like this:
    <Reference Include="System.Windows.Controls, Version=, Culture=neutral, 
    PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
    " > <HintPath>..\..\..\Assets\lib\Silverlight\System.Windows.Controls.dll</HintPath> </Reference>

  5. Save the file and close it.
  6. Reload the project.

When you are done you can verify that it works.  Here’s how…

  1. In Visual Studio, choose Tools > Options.
  2. Find the Projects and Solutions section and select Build and Run.
  3. In the section “MsBuild Project build output verbosity”, select “Detailed”.
  4. Now build your project.  When you do so, you’ll see a lot of details of what goes on in the Output Window.  You’ll need to find the output that relates to the file that you specified, in my case it is System.Windows.Controls and the important output looks like this:

    Primary reference "System.Windows.Controls, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35".

          Resolved file path is "C:\Projects\MC\BackOffice\UI\branches\2010Migration\Assets\lib\Silverlight\System.Windows.Controls.dll".

          Reference found at search path location "{HintPathFromItem}".

  5. You will note that it tells you specifically which path was used to resolve the reference!  And if you are so lazy that you don’t want to read the entire path used, you see that it says the reference was found at the search path location “{HintPathFromItem}”.  That means it used the path you specified.

I hope this helps!  Good luck and let’s hope they fix this bug soon.

6 thoughts on “Work-around for VS 2010 & Silverlight Add Reference Hint Path Bug

  1. I stumbled across this post looking for an answer to another problem. But the trick of unloading the project and then editing the csproj is something I never knew, that’s a really cool trick! You need to mention this nugget when you give one of your slick Studio talks at a Code Camp : )

  2. VS also falsly enables "SpecificVersion" which you normally don’t want to be enabled for project-relative assemblies.


Leave a reply


<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>