Microsoft.NET.Sdk.Web and packages.config
Asked Answered
S

0

2

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?

Sendal answered 3/11, 2022 at 5:8 Comment(6)
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?Herra
@Herra The fact that they took the time to create an entire SDK just for web projects when web projects must use packages.config.Sendal
@Herra 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.Sendal
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 😉Herra
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??Sendal
I don't know NewRelic, but usually these kind of things are done via contentFiles (see here)Herra

© 2022 - 2024 — McMap. All rights reserved.