Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExcludeAssets="Runtime" should not remove frameworkAssemblies #13951

Open
ericstj opened this issue Nov 21, 2024 · 1 comment
Open

ExcludeAssets="Runtime" should not remove frameworkAssemblies #13951

ericstj opened this issue Nov 21, 2024 · 1 comment
Labels
Functionality:Restore Partner:DotNet Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Style:PackageReference Type:Bug

Comments

@ericstj
Copy link

ericstj commented Nov 21, 2024

NuGet Product Used

dotnet.exe

Product Version

dotnet 9.0.100

Worked before?

Don't know

Impact

It's more difficult to complete my work

Repro Steps & Context

Build a project targeting .NET framework and referencing <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />

For example:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net4.8;net8.0</TargetFrameworks>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0"  />
  </ItemGroup>
</Project>

Note that System.ComponentModel.Annotations contains Framework References and those are correctly resolve on .NETFramework when referenced normally.
From NuSpec:

    <frameworkAssemblies>
      <frameworkAssembly assemblyName="mscorlib" targetFramework=".NETFramework4.6.1" />
      <frameworkAssembly assemblyName="System.ComponentModel.DataAnnotations" targetFramework=".NETFramework4.5" />
      <frameworkAssembly assemblyName="System.ComponentModel.DataAnnotations" targetFramework=".NETFramework4.6.1" />
    </frameworkAssemblies>

From Assets file:

    ".NETFramework,Version=v4.8": {
      "System.ComponentModel.Annotations/5.0.0": {
        "type": "package",
        "frameworkAssemblies": [
          "System.ComponentModel.DataAnnotations",
          "mscorlib"
        ],
        "compile": {
          "ref/net461/System.ComponentModel.Annotations.dll": {
            "related": ".xml"
          }
        },
        "runtime": {
          "lib/net461/System.ComponentModel.Annotations.dll": {}
        }
      }
    },

Now add ExcludeAssets="Runtime" to the reference:

    <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0"  ExcludeAssets="Runtime" />

NuGet removes the runtime asset, as expected, but also drops the frameworkAssemblies. The latter is incorrect. Framework Assemblies are not runtime assets, they are just references from the targeting pack. They need to be preserved as part of the compile assets.

    ".NETFramework,Version=v4.8": {
      "System.ComponentModel.Annotations/5.0.0": {
        "type": "package",
        "compile": {
          "ref/net461/System.ComponentModel.Annotations.dll": {
            "related": ".xml"
          }
        },
        "runtime": {
          "lib/net461/_._": {}
        }
      }
    },

Verbose Logs

No response

@nkolev92
Copy link
Member

This seems like a bug, but it's also a behavior that's always been a thing: https://github.com/NuGet/NuGet.Client/blame/cee6d943f9a6fa38daf5adba4d4dae9d230e83c6/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/LockFileUtils.cs#L1059, so likely the impact is pretty low.

@nkolev92 nkolev92 added Functionality:Restore Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Partner:DotNet and removed Area:ContentFiles PackageReference contentFiles folder labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Restore Partner:DotNet Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Style:PackageReference Type:Bug
Projects
None yet
Development

No branches or pull requests

3 participants