Search code examples
csprojdotnet-sdk

ReferencePath with the new .NET SDK?


I am trying to specify a custom ReferencePath in my .csproj file, that uses the new format.

Here's how it looks like:

<PropertyGroup>
  <ReferencePath>C:\...\binaries</ReferencePath>
</PropertyGroup>

With the following reference:

<Reference Include="MyDll">
  <Private>false</Private>
  <SpecificVersion>false</SpecificVersion>
</Reference>

C:\...\binaries contains MyDll.dll

However, during build I still get

warning MSB3245: Could not resolve this reference. Could not locate the assembly "MyDll". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

I am trying to switch to ReferencePath from HintPaths, as they've become cumbersome to maintain.


Solution

  • In the new SDK csproj you can use the AssemblySearchPaths variable instead of the ReferencePath variable to influence assembly probing

    <AssemblySearchPaths>
      $(YOUR_SEMICOLON_SEPARATED_DIR_PATHS);$(AssemblySearchPaths);
    </AssemblySearchPaths>
    

    However, be careful with the old .NET Framework projects where this trick does not work.