2

I recently migrated my projects from using PackageReferences to a package.config file. For awhile I've been able to call nuget.exe restore ...\Solution.sln and everything has looked fine. Now when I build I appear to be missing references to my packages used in my package.config files.

I removed all of the 'PackageReferences' from the .csproj file and added a 'packages.config' to each project that look like the following:

Ex 1:

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net31"/>
</packages>

Ex 2:

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="AspNetCore.HealthChecks.SqlServer" version="3.2.0" targetFramework="net31"/>
    <package id="Newtonsoft.Json" version="13.0.0" targetFramework="net31"/>
    <package id="System.ServiceModel.Security" version="4.9.0" targetFramework="net31"/>
</packages>

I have Automatically check for missing packages during build in Visual Studio checked in the NuGet Package Manager options of Visual Studio. I am using Visual Studio 2019 16.11.15 and NuGet 6.2.0.

Going to package manager and putting in update-package -reinstall outputs No package updates are available from the current package source for project 'ProjectName'.

If I right-click a packages.config file and select Migrate packages.config to PackageReference... I get an Operation Failed error. Is something wrong with my packages.config files? Is there anything else I can check?

Edit: I have attempted to delete all of my .vs, obj, and bin files. Also my csproj files begin with either <Project Sdk="Microsoft.NET.Sdk"> or <Project Sdk="Microsoft.NET.Sdk.Web">

Demasterpl
  • 2,103
  • 5
  • 24
  • 32
  • Why migrate back to packages.config out of interest? – rbennett485 Jun 14 '22 at 17:14
  • @rbennett485 never used it in the first place. Would like to use packages.config with nuget restore so all dependencies can always be downloaded/updated after a fresh pull. – Demasterpl Jun 14 '22 at 17:44
  • I should probably have said "backwards" rather than "back". Can you not just run a `dotnet restore` to do what you want with package references? – rbennett485 Jun 15 '22 at 09:06

1 Answers1

0

We can only see migrate from packages.config to PackageReference in offical documatation because PackageReference is something newer. Reverse migration is not a good option.

You said you want to use packages.config with nuget restore so all dependencies can always be downloaded/updated after a fresh pull. You can refer to this page, it gives us many methods to restore packages.

For example, you can use “msbuild -t:restore” in PackageReference to restore packages. See this.

Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10