Common Project Reference Pitt falls in Visual Studio project files


In my experience as a C# developer I've had to fix a lot of build issues and a lot of these are due to issues withing the .csproj files, so I thought maybe I should share some of the common problems that I have encountered.
Thus these are some of the first things I look at if there is strange issues with building projects or solutions, it is also worth it to periodically check the solution or project files for these issues.

A reference to a DLL that is provided by the Global Assembly Cache(GAC) or the Dotnet framework.

You should be able to completely remove the references in the below examples.
Example:
  1. <HintPath>C:\Microsoft.NET\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll</HintPath>
  2. <HintPath>C:\Windows\assembly\GAC_MSIL\Microsoft.TeamFoundation.TestImpact.Client\11.0.0.0__b03f5f7f11d50a3a\Microsoft.TeamFoundation.TestImpact.Client.dll</HintPath>
  3. <HintPath>C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll</HintPath>
  4. <HintPath>C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll</HintPath>
  5. <HintPath>System.Core.dll</HintPath>
Number 1 and 2 will definitely break as these paths aren’t the same across all the computers.

Embedding a DLL instead of using the NuGet package.

Once upon a time before NuGet existed it was important to save a lib folder or something similar in source control as well in our projects, today it is detrimental when there is a NuGet package available.
In the below example the referenced assembly is in source control but a NuGet package is available., this wouldn't be a breaking issue, but it removes the advantages using the NuGet package.
This might also be due to some form of licensing.
Example:
  1. <HintPath>..\..\..\ReferencedAssemblies\Microsoft.Crm.Sdk.Proxy.dll</HintPath>

Having a direct reference to a DLL/Project that is only on your PC

It sometimes happens that you might add a reference to a file that is only located on your PC, the problem here is that, the library used isn’t available on the build servers and not on anybody else’s computers.
Rather replace the reference with a nuget package where it is possible, or include the DLL in the project so that it is in source control and reference it using a relative path. If it is a reference to a project then rather add a copy of the project to the solution and in source control.
Example:

  1. <HintPath>..\..\..\..\..\Downloads\MBG.Extensions_v1.3_Bin\MBG.Extensions_v1.3_Bin\MBG.Extensions.dll</HintPath>

Using an absolute paths instead of a relative path.

The problem here is similar to referencing something in the GAC or having a direct reference to something that is purely on your computer, because solution locations aren't the same on everyone's computer except when everyone is forced to follow the same folder structures.

Nuget and Project References

Lastly check that all the nuget packages that are referenced within the project are actually being referenced within the project files and vice versa.

Comments

Popular Posts