❔ issue with central package management

Ddemndev2/26/2023
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>
Image
Ccanton72/26/2023
I don't see the contents of Directory.Packages.props. Also, you reference two other projects: do either of those reference the Scrutor package?
Ddemndev2/26/2023
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>
Ddemndev2/26/2023
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
Ccanton72/26/2023
Right, if one of the projects you depend on references a package, by default your project inherits that reference
Ccanton72/26/2023
I'm not sure what relevance D.P.props has here
Ddemndev2/26/2023
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
Ccanton72/26/2023
"Infrastructure" is the csproj you posted in the original question?
Ddemndev2/26/2023
yes
Ddemndev2/26/2023
Okay, I removed the ProjectReference in Application, but the problem still remains
Ccanton72/26/2023
Even after a clean/rebuild?
Ccanton72/26/2023
Which problem? That you're able to refer to Scrutor but don't think you're referencing it?
Ddemndev2/26/2023
yes
Ddemndev2/26/2023
yes, even so
Ccanton72/26/2023
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?
Ccanton72/26/2023
Unless I'm missing something very obvious here, your D.P.props has:

<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?
Ddemndev2/26/2023
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>
Ccanton72/26/2023
But... You've got a D.P.props which does have a reference
Ccanton72/26/2023
And everything in D.P.props is automatically applied to all projects
Ddemndev2/26/2023
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
Ccanton72/26/2023
Aha right you are, I mis-remembered how it worked
Ccanton72/26/2023
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/
Ccanton72/26/2023
The other option is that you're referencing a package which has a dependency on Scrutor
Ccanton72/26/2023
This would be a good test
Ddemndev2/26/2023
I don't see anything you described. But maybe the Nuget GUI will work?
Ddemndev2/26/2023
oh no, sorry, i see it
Ddemndev2/26/2023
it seems to have imported all the packages mentioned in DPProps
Image
Ccanton72/26/2023
I'm suspicious of that <Sdk... line
Ddemndev2/26/2023
With or without this line, it's the same. I borrowed it from this repository: https://github.com/ardalis/CleanArchitecture
Ccanton72/26/2023
I'm just going by the MS blog
Ddemndev2/26/2023
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
Ccanton72/26/2023
Have you ruled out Rider as a cause? I'm not sure how involved it gets here
Ccanton72/26/2023
I.e. just building with dotnet
Ddemndev2/26/2023
I have already built via dotnet build
Ddemndev2/26/2023
and did before dotnet clean
Ddemndev2/26/2023
:/
Ccanton72/26/2023
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
WWz2/26/2023
it's PackageVersion not PackageReference
Ccanton72/26/2023
Aha, that's an important spot
AAccord2/27/2023
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.