Exclude nuget dll from build

I’m multitargetting net48,net7-windows and at the same time, i’m using rhino 7 nuget package for net48 and rhino 8 nuget package for net7, this is done by manually editing the csproj like this:

  <ItemGroup Condition="'$(TargetFramework)' == 'net7.0-windows'">
    <PackageReference Include="Grasshopper" Version="8.0.23304.9001" />
  </ItemGroup>
  <ItemGroup Condition="'$(TargetFramework)' == 'net48'">
    <PackageReference Include="Grasshopper" Version="7.0.20314.3001" />
  </ItemGroup>

But this results in Eto.dll and Rhino*.dll being included in the build, where as if both frameworks targeted the same nuget package, these don’t get included in the build.
is there a setting I can set so that thye’re not included?

Try adding <ExcludeAssets> runtime </ExcludeAssets> to the <PackageReference>:

  <ItemGroup Condition="'$(TargetFramework)' == 'net7.0-windows'">
    <PackageReference Include="Grasshopper" Version="8.0.23304.9001">
      <ExcludeAssets> runtime </ExcludeAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup Condition="'$(TargetFramework)' == 'net48'">
    <PackageReference Include="Grasshopper" Version="7.0.20314.3001">
      <ExcludeAssets> runtime </ExcludeAssets>
    </PackageReference>
  </ItemGroup>
1 Like