Search code examples
visual-studiocsproj

Do I need to have a hintpath in my csproj file reference?


I manually edited in a reference (Reference not ProjectReference) in my csproj file, and after reviewing the code, I can see that the hintpath is wrong:

+    <Reference Include="Company.Core.Data.Web.UnitTests">
+      <HintPath>..\..\..\..\..\Code\Bin\Company.Core.Data.Web.UnitTests.dll</HintPath>
+      <Private>True</Private>
+    </Reference>

The right path would be ..\..\..\..\..\Build\UnitTests\Company.Core.Data.Web.UnitTests.dll.

However, I notice that a clean build of my project works fine. Does this matter? Is this something I need to fix?


Solution

  • As described in https://stackoverflow.com/a/2733113/5749914, Visual Studio will search a number of locations for the DLL, and the fact that a clean build is working with a incorrect hint path indicates the hint path is not needed.

    In this case, the $(outDir) was being searched: in my project, the outputPath tag was

    <OutputPath>..\..\..\..\..\Build\UnitTests\</OutputPath>.
    

    which was the same directory my project was being built to.

    So, if the referenced DLL is in the same build directory that the project is being built to, there is no need for a hintpath.