1

I have a web project that I'm trying to convert to Microsoft.NET.Sdk.Web. When I make the change to the .csproj file, though, it seems to force it to be interpreted as a <PackageReference>-based project. Of course, <PackageReference> isn't supported in web projects, because it doesn't support persisting the results of installing a package. Web projects must use packages.config in order to support NuGet packages that inject static content into the site's space (such as NewRelic). But, after switching to Microsoft.NET.Sdk.Web, the build system seems absolutely stuck on the project being <PackageReference>-based. How do I resolve this? Surely the very existence of Microsoft.NET.Sdk.Web implies that it is possible to use packages.config with an SDK project. But, even if I set <RestoreProjectStyle>Packages.config</RestoreProjectStyle>, it still thinks the project is <PackageReference>-based. I've seen advice to try running Update-Package -Reinstall after clearing out obj, bin and .vs, but nothing I've tried has convinced it that this is not a <PackageReference>-based project:

The -Reinstall parameter does not apply to PackageReference based projects

In Visual Studio, all of the NuGet-inserted references are lumped in with other references under Dependencies\Assemblies, and the "Installed" tab of the NuGet Package Manager is empty.

What do I do?

Jonathan Gilbert
  • 3,526
  • 20
  • 28
  • _Surely the very existence of Microsoft.NET.Sdk.Web implies that it is possible to use packages.config with an SDK project._ → could you please clarify what brings you to this assumption? – mu88 Nov 03 '22 at 11:32
  • @mu88 The fact that they took the time to create an entire SDK just for web projects when web projects _must_ use packages.config. – Jonathan Gilbert Nov 03 '22 at 14:02
  • @mu88 If you open a web project, right-click on its packages.config file and select "Migrate packages.config to PackageReference", you get a notice that says, "Operation failed - Project is not eligible for migration". The system recognizes that web projects must use packages.config. Based on that, it is only logical that they wouldn't make Microsoft.NET.Sdk.Web _if it couldn't be used_. – Jonathan Gilbert Nov 03 '22 at 14:26
  • 1
    `Microsoft.NET.Sdk.Web` is meant to be used for ASP.NET Core and all the ASP.NET Core templates and projects I know use `PackageReference`, not `packages.config` - but maybe you find a counterexample – mu88 Nov 03 '22 at 14:41
  • Oh? But then how do they use things like NewRelic, that want to dump a bunch of static content into the project as part of package installation?? – Jonathan Gilbert Nov 03 '22 at 15:07
  • I don't know NewRelic, but usually these kind of things are done via `contentFiles` ([see here](https://learn.microsoft.com/en-us/nuget/reference/nuspec#including-content-files)) – mu88 Nov 03 '22 at 15:15

0 Answers0