You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Libraries building against packages instead of ProjectReferences #40208
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.
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.
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.
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.
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.
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):
We aren't generating a bindingRedirect where one is needed (eg: due to conflict not present in reference assemblies).
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.
@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.
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
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.
Activity
ViktorHofer commentedon Jul 31, 2020
@ericstj the link isn't resolving for me correctly. Where do you see a live build asset not be preferred over a packagereference?
ericstj commentedon Jul 31, 2020
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.
ericstj commentedon Aug 26, 2020
@ViktorHofer were you going to have a look at this one now that you're back?
ViktorHofer commentedon Aug 26, 2020
Yeah will take a look
ViktorHofer commentedon Sep 2, 2020
Moving to 6.0 as this will likely not meet the bar for 5.0.
safern commentedon Sep 2, 2020
Usually regressions from a Preview to RC do meet the bar, right?
ViktorHofer commentedon Sep 2, 2020
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.
safern commentedon Sep 2, 2020
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.
ViktorHofer commentedon Sep 2, 2020
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.
ericstj commentedon Sep 2, 2020
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):
ViktorHofer commentedon Feb 12, 2021
@ericstj I just noticed that we were building against prebuilts even before we switched to PackageReferences. An example is
System.Threading.Channelswhich referencesSystem.Threading.Tasks.Extensionswhich referencesSystem.Runtime.CompilerServices.Unsafe. AsS.T.T.Extensionswas already restored via a depproj, it's reference toS.R.C.Uwas already pinned to specific version. If we look at theSystem.Threading.Channels5.0.0 P1 version of the package we can see that it only has a reference toS.T.T.Extensionswhere-as the 5.0.0 version of the package references bothS.T.T.ExtensionsandS.R.C.Uwhich I'm not sure this is right asS.T.Channelsdoesn't have a direct depency onS.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?
ericstj commentedon Feb 17, 2021
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 forSystem.Memoryand some others.Many of these happen to reference
System.Runtime.CompilerServices.Unsafeand will reference the old version of that package.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.