nugetizer icon indicating copy to clipboard operation
nugetizer copied to clipboard

Add/Improve support for Central Package Management

Open navruz-rakhimov opened this issue 1 year ago • 4 comments

Describe the Bug

NuGetizer is ignoring central package management.

Steps to Reproduce

  1. Create an empty solution
  2. Create a Directory.Packages.props and enable central package management for the solution.
<Project>
    <PropertyGroup>
        <EnablePackageVersionOverride>true</EnablePackageVersionOverride>
        <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    </PropertyGroup>
    <ItemGroup>
        <PackageVersion Include="NuGetizer" Version="1.2.3" />
        <PackageVersion Include="Unity" Version="5.11.10" Condition=" '$(TargetFramework)' == 'net8.0' " />
        <PackageVersion Include="Unity" Version="4.0.1" Condition=" '$(TargetFramework)' == 'net472' " />
    </ItemGroup>
</Project>
  1. Add a class library with the following project file content
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net8.0;net472</TargetFrameworks>
        <ImplicitUsings>enable</ImplicitUsings>
        <PackageId>MyClassLib</PackageId>
        <Version>1.0.0</Version>
        <Nullable>enable</Nullable>
        <LangVersion>12</LangVersion>
    </PropertyGroup>
    
    <ItemGroup>
        <PackageReference Include="NuGetizer" />
        <PackageReference Include="Unity" />
    </ItemGroup>
    
</Project>

Expected Behavior

I expected the following dependencies in the nuspec file when I dotnet pack:

<dependencies>
      <group targetFramework="net8.0">
          <dependency id="Unity" version="5.11.10" />
      </group>
      <group targetFramework=".NETFramework4.7.2">
          <dependency id="Unity" version="4.0.1" />
      </group>
</dependencies>

but I am getting:

<dependencies>
      <group targetFramework="net8.0">
          <dependency id="Unity" version="5.11.10" />
      </group>
      <group targetFramework=".NETFramework4.7.2">
          <dependency id="Unity" version="5.11.10" />
      </group>
</dependencies>

Exception with Stack Trace

Version Info

Additional Info

Central Package Management works fine when I use dotnet pack command alone without NuGetizer. Similarly, I can conditionally specify different versions in the project file with NuGetizer if the Central Package Management disabled.

The problem is that I can't use both Central Package Management and NuGetizer to use different versions of a dependency per target when multitargeting.

Back this issue Back this issue

navruz-rakhimov avatar Dec 17 '24 07:12 navruz-rakhimov

See if this one works for you (step 4)

    <PackageReference Include="Unity" Pack="false" />
    <PackageFile PackFolder="Dependency" Include="Unity" Version="4.0.1" Condition=" '$(TargetFramework)' == 'net472' " />
    <PackageFile PackFolder="Dependency" Include="Unity" Version="5.11.10" Condition=" '$(TargetFramework)' == 'net8.0' " />

khamza85 avatar Dec 17 '24 22:12 khamza85

This is a good feature to add (since now CPV is quite a bit more flexible than it used to be, and therefore more useful in general).

kzu avatar Jan 09 '25 21:01 kzu

Really interested in having support for this too. Maintaining versions in the projects themselves again sadly defeats the entire point of CPM.

jwfx avatar May 28 '25 13:05 jwfx

If the issue gets sufficient funding, I might work on it.

Happy to take a PR for it too.

Thanks!

kzu avatar Jul 07 '25 18:07 kzu