NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

CPM GlobalPackageReference support override default IncludeAssets #13522

Open WeihanLi opened 3 months ago

WeihanLi commented 3 months ago

NuGet Product(s) Involved

NuGet.exe

The Elevator Pitch

The GlobalPackageReference would use Runtime;Build;Native;contentFiles;Analyzers for the IncludeAssets while sometimes the package may need to use all to include the compile, maybe we could support overriding the default IncludeAssets, trying to add IncludeAssets="All" but no working

Additional Context and Details

I'm trying to use CPM for the EasyNetQ project and trying to use the GlobalPackageReference for Fody

  <ItemGroup>
    <GlobalPackageReference Include="Fody" Version="6.8.1" />
    <GlobalPackageReference Include="NullGuard.Fody" Version="3.1.1" />
  </ItemGroup>

image

jeffkl commented 3 months ago

To override how NuGet handles global package references, you'll need to set RestoreEnableGlobalPackageReference to false to disable the built-in logic. Then in your Directory.Build.targets you can do something like:

  <ItemGroup>
    <PackageReference Include="@(GlobalPackageReference)"
                      Version=""
                      IncludeAssets="MyDefaultIncludeAssets"
                      PrivateAssets="All" />

    <PackageVersion Include="@(GlobalPackageReference)"
                    Version="%(Version)" />
  </ItemGroup>
WeihanLi commented 3 months ago

@jeffkl thanks, it could help while we may want to update this for specific reference only, keep using the default behavior for other references, so maybe it's better to support an inline override