VS 2017 Nuget Package Manager dependency resolution issue when using Packages.config as package management format

Babu Annamalai
2 min readOct 7, 2017

--

To set some context, several users had reported issues with regards to Nuget dependency resolution issues with Marten (pertaining to Baseline library), OSS project which I love and contribute to. Marten uses the new csproj and creates Nuget packages using dotnet core sdk 2.0 CLI pack command

I went ahead and did some troubleshooting and zeroed in to find out that this issue happens only in the case where you have created a project targeting .NET framework with Nuget package management format using Packages.config. Note that VS2017 by default has the Nuget Package management format as Packages.config for projects targeting .NET Framework hence readily brings up this issue.

See the error below when trying to add Marten via Nuget Package Manager with Packages.config as the package management format:

Error  Unable to resolve dependency 'Baseline'. Source(s) used: 'nuget.org', 'Test Local', 'Microsoft Visual Studio Offline Packages'.

I also observed that any project targeting .Net core or target multiple frameworks (using new csproj format) did not have this issue.

Simple solution to solve the problem is to change the package management format in the VS 2017. Go to Nuget package Manager settings-> General and change the default package management format to “PackageReference”. See screenshot below:

If you would want to convert libraries in Packages.config in the existing project to use PackageReference and remove Packages.config all together, you can install VS extension Nuget PackageReference Upgrader. Once you install the extension, you can right-click on the Packages.config file and click on “Upgrade to PackageReferences”

In summary, the problem lies with Nuget package resolution in combination with usage of Packages.config as the package management format (strongly suspect VS 2017 Nuget Package Manager may be using an older API which is not compatible with the Nuget packages published via new dotnet CLI using the new csproj). I would recommend to use PackageReference as your default package management format in VS 2017.

--

--