Search code examples
c#asp.netvisual-studiodependenciescsproj

How to enforce a minimum version for dependencies in project.assets.json in ASP.NET project?


In my project.csproj file I have the following:

<PackageReference Include="System.Text.Encodings.Web" Version="5.0.1" />

However, my other dependencies pull in a lower version of the package as their dependencies. For example in my project.assets.json I see (18 total instances that pull version 4.5.0):

  "Microsoft.AspNetCore.Http.Abstractions/2.2.0": {
    "type": "package",
    "dependencies": {
      "Microsoft.AspNetCore.Http.Features": "2.2.0",
      "System.Text.Encodings.Web": "4.5.0" // <-- the problem
    },

How can I enforce a minimum version for these dependencies? To be more specific, any version above 4.5.1 would work to fulfill my needs for compliance.


Solution

  • I've found out that if you add the ProjectReference, that might actually solve the problem. Here is a good read:

    https://learn.microsoft.com/en-us/nuget/concepts/dependency-resolution

    After adding the ProjectReference, the project.assets.json still had the 4.5.0 as dependency but it only pulled in the ProjectReference version, which was 5.0.1 in this case.