Use PackageReference in *.csproj files

Ikechi Michael
May 17, 2024

--

I recently learnt that a *.csproj file that uses:

<Reference Include="Foo.Bar" Version="0.0.0">
<HintPath>..\..\packages\Foo.Bar.0.0.0\lib\net46\Foo.Bar.dll</HintPath>
</Reference>

can be modified to use:

<PackageReference Include="Foo.Bar" Version="0.0.0" />

and this gives the advantages:

  • having both nuget restore and dotnet restore commands working
  • one place to define dependencies instead of dealing with packages.config files in every project.
  • prevents errors from mismatched HintPath values
  • should be able to use a Directory.Packages.props file to define the dependency versions once for the entire solution (I haven't tried this one particularly tbh, but I don't see why not)

I used to think that we needed to upgrade the *.csproj SDK format from 2003 to have this functionality but seeing it work with the same format is a huge eye opener.

I think all legacy .NET framework projects could begin doing this to gain an advantage.

--

--

Ikechi Michael
Ikechi Michael

Written by Ikechi Michael

I’ve learned I don’t know anything. I've also learned that people will pay for what I know. Maybe that's why they never pay.

No responses yet