Skip to content

Libraries building against packages instead of ProjectReferences #40208

Closed

Description

@ericstj

Description

First noted here: 809a06f#comments

After switching to PackageReference we are bringing in some transitive packages that are older than live-built assets. In this case, System.Runtime.CompilerServices.Unsafe.

We should audit all of our library builds to make sure we aren't doing this in additional places.

It may be possible for us to automatically do this, but it it could get a little tricky (and expensive) to do during source build, as we would need to check for every package referenced by src if we have a src project for it for the target configuration and its building live. Perhaps we can add coverage in package testing for this.

Regression?

Yes, regressed from Preview8

Activity

  1. added this to the 5.0.0 milestone on Jul 31, 2020
  2. added
    untriaged
    on Jul 31, 2020
  3. ViktorHofer commented on Jul 31, 2020

    @ViktorHofer
    Member

    @ericstj the link isn't resolving for me correctly. Where do you see a live build asset not be preferred over a packagereference?

  4. ericstj commented on Jul 31, 2020

    @ericstj
    MemberAuthor

    System.Text.Json -> It's getting a System.Runtime.CompilerServices.Unsafe reference transitively from packages rather than a project reference. I was looking at the net4* configuration.

  5. removed
    untriaged
    on Aug 4, 2020
  6. ericstj commented on Aug 26, 2020

    @ericstj
    MemberAuthor

    @ViktorHofer were you going to have a look at this one now that you're back?

  7. ViktorHofer commented on Aug 26, 2020

    @ViktorHofer
    Member

    Yeah will take a look

  8. modified the milestones: 5.0.0, 6.0.0 on Sep 2, 2020
  9. ViktorHofer commented on Sep 2, 2020

    @ViktorHofer
    Member

    Moving to 6.0 as this will likely not meet the bar for 5.0.

  10. safern commented on Sep 2, 2020

    @safern
    Member

    Usually regressions from a Preview to RC do meet the bar, right?

  11. ViktorHofer commented on Sep 2, 2020

    @ViktorHofer
    Member

    Without this change you will get a binding redirect when referencing System.Memory which has reference on System.Runtime.CompilerServices.Unsafe and with it you will still get one. Even though this regressed there is no clear customer impact. Our packaging system will still target the latest System.Runtime.CompilerServices.Unsafe package.

  12. safern commented on Sep 2, 2020

    @safern
    Member

    Binding redirects usually cause problems on customers from my understanding so I guess if we avoid it it would be nice, I don't know what @ericstj thoughts on this are.

  13. ViktorHofer commented on Sep 2, 2020

    @ViktorHofer
    Member

    As said, you will already get a binding redirect when i.e. referencing System.Memory as it references an older System.Runtime.CompilerServices.Unsafe assembly. Unification will update to the latest version and cause the binding redirect. I need to check other assemblies but right now I doubt there is one that now creates a binding redirect and didn't before because of this change.

  14. ericstj commented on Sep 2, 2020

    @ericstj
    MemberAuthor

    So I opened this based on an observation. The thing I observed alone wouldn't justify a fix for 5.0. If we can find a scenario that's impacted then it would justify.

    I think the two scenarios that would meet the bar (there may be more):

    1. We aren't generating a bindingRedirect where one is needed (eg: due to conflict not present in reference assemblies).
    2. We started requiring a bindingRedirect where one wasn't needed before the refactoring (because we compile against an old assembly rather than everything compiling against latest). We had a hard time imagining this since the old Unsafe was coming from System.Memory which would itself have the old reference and thus require the bindingRedirect.
  15. ghost locked as resolved and limited conversation to collaborators on Dec 8, 2020
  16. ViktorHofer commented on Feb 12, 2021

    @ViktorHofer
    Member

    Yes, regressed from Preview8

    @ericstj I just noticed that we were building against prebuilts even before we switched to PackageReferences. An example is System.Threading.Channels which references System.Threading.Tasks.Extensions which references System.Runtime.CompilerServices.Unsafe. As S.T.T.Extensions was already restored via a depproj, it's reference to S.R.C.U was already pinned to specific version. If we look at the System.Threading.Channels 5.0.0 P1 version of the package we can see that it only has a reference to S.T.T.Extensions where-as the 5.0.0 version of the package references both S.T.T.Extensions and S.R.C.U which I'm not sure this is right as S.T.Channels doesn't have a direct depency on S.R.C.U. https://www.nuget.org/packages/System.Threading.Channels/5.0.0-preview.1.20120.5.

    Apparently the packaging infrastructure then removes the dependency if it's already satisfied by the shared framework.

    Thoughts?

  17. ericstj commented on Feb 17, 2021

    @ericstj
    MemberAuthor

    Right we build against some old libraries if those packages have been removed from the branch, as is the case with System.Trheading.Tasks.Extensions, the same is true for System.Memory and some others.

    Many of these happen to reference System.Runtime.CompilerServices.Unsafe and will reference the old version of that package.

    System.Threading.Channels
    where-as the 5.0.0 version of the package references both S.T.T.Extensions and S.R.C.U

    I'm not seeing this. https://www.nuget.org/packages/System.Threading.Channels/5.0.0

    Also I don't see an assembly reference in the S.T.C.dll. We don't need to copy transitive references up the stack. We should only be referencing packages which are directly used. We should reference all packages which are directly used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions