79494918

Date: 2025-03-08 19:35:50
Score: 2
Natty:
Report link

One option that requires a tiny bit of extra management is to use a combination of the original answer with project variables in the csproj file.

<Project>
    ...
    <PropertyGroup>
        <!-- mixed inclusive minimum and exclusive maximum version -->
        <EntityFrameworkCoreVersion>[8.0.12,9.0)</EntityFrameworkCoreVersion>
    </PropertyGroup>
    ...
</Project>

and then use the variable to set the version for any packages like this:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EntityFrameworkCoreVersion)" />

Now, if you use the package manager gui, nuget will still replace $(EntityFrameworkCoreVersion) with the new version (ex: 8.0.13)

However, (and this is the tiny bit of work part) instead of using the package manager gui to update the version(s)...just change the variable inside the csproj file instead.

Full Example: (after you already have it setup with package variables as explained above)
1. Open package manager to observe packages that have updates (in this case 8.0.12 > 9.0.0)
2. Edit the csproj project variable(s) to include the new version in the project variable (ex: [8.0.13,9.0)
3. Save csproj and you're done
4. Next time you look for updates, it will only show greater than 8.0.13, but less than (exclude) 9.0.0

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <EntityFrameworkCoreVersion>[8.0.12,9.0)</EntityFrameworkCoreVersion>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EntityFrameworkCoreVersion)" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="$(EntityFrameworkCoreVersion)" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EntityFrameworkCoreVersion)" />
    </ItemGroup>

</Project>

It really isn't much more additional/manual work, you can still update many packages at once.

You can also do this with central package management as well by using a Directory.Packages.props file. VS will look for this file in the folder hierarchy all the way to the root folder of the drive your project/solution resides on and a single change to this file will update all projects in a solution vs. just one project. However, I'm not sure when it was introduced...I think it has to be an sdk style project which I think was introduced in VS 2019???

Reasons:
  • Blacklisted phrase (1): ???
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: Mike