Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2015 to 2017 migrate to package reference failed

I've inherited a VS-2015 C# application and would like to migrate it to VS 2017 or 2019. It has a packages.config file with 4 packages:

<package id="AjaxControlToolkit" version="15.1.4.0" targetFramework="net4" />
<package id="EntityFramework" version="6.0.0" targetFramework="net4" />
<package id="Microsoft.AspNet.Providers" version="2.0.0" targetFramework="net4" />
<package id="Microsoft.AspNet.Providers.Core" version="2.0.0" targetFramework="net4" />

The first few lines of the project's sln file are:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}")

I'd like to migrate the packages.config file to a csproj file.

In Visual Studio 2017, I tried migrating it by right-clicking on packages.config and clicking 'Migrate packages.config to PackageReference', but it gives me an error:

Operation Failed - Project is not Eligible for Migration.

error message

I also tried this tool: https://github.com/hvanbakel/CsprojToVs2017 and this also fails.

Is there really no way to migrate this to .csproj?

like image 971
VBStarr Avatar asked Aug 20 '19 21:08

VBStarr


People also ask

How do I restore references in Visual Studio?

Restore packages (In Visual Studio, the references appear in Solution Explorer under the Dependencies \ NuGet or the References node.) If the package references in your project file are correct, use your preferred tool to restore packages. If the package references in your project file (. csproj) or your packages.


1 Answers

There is a workaround to this issue that I have used for older ASP.NET projects (and may potentially work with other project types which exhibit this issue too).

Essentially, the migration tool can still work, but first you must fool Visual Studio (temporarily) into thinking your project is a class library rather than a web project while you do the migration.

Detailed steps:

  1. Close your project/solution if it's open in Visual Studio, and take a backup of it.

  2. Open the .csproj file in a text editor

  3. Cut the ProjectGuid and ProjectTypeGuids entries, and paste them somewhere else temporarily.

  4. Insert <ProjectGuid>{7C796B6B-86B5-4C57-ADAA-12CF1FECDA71}</ProjectGuid> where your ProjectGuid entry was previously, and save the file

  5. Open the project in Visual Studio (2017 or later)

  6. Right-click the packages.config file and choose the option to migrate to package reference.

  7. Once the migration is successful, close the project/solution again.

  8. Go back into the .csproj file and replace the ProjectGuid entry with the ProjectGuid and ProjectTypeGuids entries which you saved in step 3.

  9. Re-open the project in Visual Studio. You should now be able to use it as normal.

This has worked for me on two projects so far. I can't promise there wouldn't be any side-effects in edge cases or more complex projects, but it's certainly something you can try.

Credit to this GitHub comment for the idea.

like image 133
ADyson Avatar answered Oct 01 '22 11:10

ADyson