Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe/feasible to migrate to "new project system" (PackageReference) for .NET framework solutions containing ASP.NET projects?

According to docs, new PackageReference is not supported (yet) for ASP.NET projects https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files

But what about class libraries that ASP.NET depend on? Let's suppose I have following .NET Framework solution:

  • Foo.Domain
  • Foo.PublicApi.Contract
  • Foo.Services
  • Foo.AspNetWebApp (has references to everything above)

I couldn't migrate to PackageReference Foo.AspNetWebApp as it not support for ASP.NET non-Core projects. But could I migrate everything else? Is it supported scenario? I will win at least merges for everything else :-)

like image 548
Leotsarev Avatar asked Jul 25 '18 10:07

Leotsarev


2 Answers

It's feasible and will save you tons of time when doing NuGet package restore (shorter CI builds), you can read more details about the gains here.

Also you can use the following useful extension for doing the conversion easily.

like image 175
MarkovskI Avatar answered Nov 03 '22 05:11

MarkovskI


I used the following PowerShell script for my conversion process of asp.net projects with success on over 20 projects at this point. You must first change PackageReference to the default behavior of Visual Studio in Tools > NuGet Package Manager > Package Manager Settings > Default package management format. Then you can run the powershell script in the Package Manager Console window, replacing the name of the project you wish to migrate.

$packages = Get-Package -ProjectName MyProjectName
$packages | %{ Uninstall-Package -Id $_.Id -ProjectName $_.ProjectName -RemoveDependencies -Force}
$packages | %{ Install-Package -Id $_.Id -Version $_.Versions[0] -ProjectName $_.ProjectName }

Expect a few innocuous errors during the uninstall step, as this script will try to force uninstall everything in the order it was listed, instead of the order of the dependencies. In the end it does remove them all and get rid of your packages.config for you. Then the last line of the script adds them all back this time as PackageReference's. Occasionally you need to do a bit of project file maintenance if the uninstall missed some targets or packages folder references that should have been removed.

like image 30
DannyMeister Avatar answered Nov 03 '22 04:11

DannyMeister