C
C#17mo ago
demndev

❔ issue with central package management

I added a Directory.Packages.props to the root of project and edited .csproj file like this:
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.1.3" />

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Infrastructure</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Blog.Application\Blog.Application.csproj" />
<ProjectReference Include="..\Blog.Domain\Blog.Domain.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.1.3" />

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Infrastructure</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Blog.Application\Blog.Application.csproj" />
<ProjectReference Include="..\Blog.Domain\Blog.Domain.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
</ItemGroup>

</Project>
27 Replies
canton7
canton717mo ago
I don't see the contents of Directory.Packages.props. Also, you reference two other projects: do either of those reference the Scrutor package?
demndev
demndev17mo ago
Directory.Packages.props:
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Markdig" Version="0.30.4" />
<PackageReference Include="NReco.Logging.File" Version="1.1.6" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />

<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Scrutor" Version="4.2.1" />

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.3"/>

</ItemGroup>
</Project>
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Markdig" Version="0.30.4" />
<PackageReference Include="NReco.Logging.File" Version="1.1.6" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />

<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Scrutor" Version="4.2.1" />

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.3"/>

</ItemGroup>
</Project>
Yes, Application project references it, but... but before I added D.P.props there was an error, because there is no reference in .csproj file
canton7
canton717mo ago
Right, if one of the projects you depend on references a package, by default your project inherits that reference I'm not sure what relevance D.P.props has here
demndev
demndev17mo ago
Before I added this file it was different - even though Infrastructure refers to Application, there was an error when I tried to use a package that was not referenced by Infrastructure, and then the Rider IDE prompted me to refer to this package
canton7
canton717mo ago
"Infrastructure" is the csproj you posted in the original question?
demndev
demndev17mo ago
yes Okay, I removed the ProjectReference in Application, but the problem still remains
canton7
canton717mo ago
Even after a clean/rebuild? Which problem? That you're able to refer to Scrutor but don't think you're referencing it?
demndev
demndev17mo ago
yes yes, even so
canton7
canton717mo ago
In VS, you can expand the project in the solution explorer and see a list of packages that are references. Is there something similar in Rider? Unless I'm missing something very obvious here, your D.P.props has:
<PackageReference Include="Scrutor" Version="4.2.1" />
<PackageReference Include="Scrutor" Version="4.2.1" />
I guess don't understand why it's a surprise that your project has a reference to Scrutor, in that case?
demndev
demndev17mo ago
Yes, DPProps has, but Blog.Infrastructure.csproj have no PackageReference to scrutor:
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" />
</ItemGroup>
canton7
canton717mo ago
But... You've got a D.P.props which does have a reference And everything in D.P.props is automatically applied to all projects
demndev
demndev17mo ago
Hmm, I didn't think so. I did the CPM with the help from the article (https://timdeschryver.dev/blog/directorypackagesprops-a-solution-to-unify-your-nuget-package-versions) and I thought that this file does not apply the package reference to all projects, but just indicates what version the packages should be
Directory.Packages.props, a solution to unify your NuGet package ve...
The Consolidate view is dead, long live Directory.Packages.props. Use the Directory.Packages.props file to define your NuGet package versions in a single file.
canton7
canton717mo ago
Aha right you are, I mis-remembered how it worked
canton7
canton717mo ago
Although, I don't see <Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.1.3" /> mentioned anywhere in https://devblogs.microsoft.com/nuget/introducing-central-package-management/
The NuGet Blog
Introducing Central Package Management - The NuGet Blog
Central Package Management Dependency management is a core feature of NuGet. Managing dependencies for a single project can be easy. Managing dependencies for multi-project solutions can prove to be difficult as they start to scale in size and complexity. In situations where you manage common dependencies for many different projects,
canton7
canton717mo ago
The other option is that you're referencing a package which has a dependency on Scrutor This would be a good test
demndev
demndev17mo ago
I don't see anything you described. But maybe the Nuget GUI will work? oh no, sorry, i see it
demndev
demndev17mo ago
it seems to have imported all the packages mentioned in DPProps
canton7
canton717mo ago
I'm suspicious of that <Sdk... line
demndev
demndev17mo ago
With or without this line, it's the same. I borrowed it from this repository: https://github.com/ardalis/CleanArchitecture
GitHub
GitHub - ardalis/CleanArchitecture: Clean Architecture Solution Tem...
Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core - GitHub - ardalis/CleanArchitecture: Clean Architecture Solution Template: A starting point for Clea...
canton7
canton717mo ago
I'm just going by the MS blog
demndev
demndev17mo ago
I did everything as it is written there, but the issue remains as it was before. Looks like I'll have to go back to the old way of versioning dependencies - via .csproj files. Thanks for the help
canton7
canton717mo ago
Have you ruled out Rider as a cause? I'm not sure how involved it gets here I.e. just building with dotnet
demndev
demndev17mo ago
I have already built via dotnet build and did before dotnet clean :/
canton7
canton717mo ago
There's still the possibility that 1) That Rider GUI is wrong, and 2) You're picking up Scrutor as a transitive dependency of something else
Wz
Wz17mo ago
it's PackageVersion not PackageReference
canton7
canton717mo ago
Aha, that's an important spot
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.