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
Copy file name to clipboardexpand all lines: accepted/2021/experimental-package-shading/experimental-package-shading.md
+22-2
Original file line number
Diff line number
Diff line change
@@ -193,7 +193,25 @@ We could build a mechanism for opting transitive references out of shading, but
193
193
194
194
However, direct dependencies that are shaded will unify with indirect dependencies that are transitive via other shaded dependencies. This is necessary for correctness, but it also means a package author can opt into shading a transitive dependency by making it a direct dependency.
195
195
196
-
> TODO diagrams
196
+
To demonstrate this, consider a project that produces a package. The project has a shaded reference to package `Foo`, and `Foo` depends on package `Bar`, so the package project transitively depends on `Bar`.
197
+
198
+

199
+
200
+
Restoring, building and packing this will result in a package where the transitive reference to `Bar` from the project has become a direct dependency in the package. The shaded package `Foo` has been hidden from the dependency graph but the graph is otherwise unchanged.
201
+
202
+

203
+
204
+
However, if the project adds a direct shaded reference to `Bar`, this will unify with the transitive reference from `Bar`, and `Foo` will depend on the shaded version of `Bar`.
205
+
206
+

207
+
208
+
This unification is necessary so that the package project doesn't have two references to differently named copies of the same assembly, which would result in the same problems as shading public references. The package project would see multiple copies of the types from `Bar` with the exact same fully qualified names, which would cause compile errors. While it is possible to resolve this, it would substantially increase scope.
209
+
210
+
Lastly, consider a case where the package project has a shaded reference to a package that's also a dependency of an unshaded reference.
211
+
212
+

213
+
214
+
This is **explicitly disallowed** at this time for the same reason as the previous example: the package project's direct and transitive references to `Bar` must unify. The only way to do this is by shading `Foo` so that its references to `Bar` can be updated to target the shaded version, and we require the developer do this explicitly so that all shading operations are clear and intentional.
197
215
198
216
## FAQ
199
217
@@ -207,7 +225,9 @@ We could build a mechanism for opting transitive references out of shading, but
207
225
208
226
### Why only allow shading private references?
209
227
210
-
> TODO
228
+
We have made an explicit scoping decision to disallow shading of public references. Shading of public references leads to scenarios where a project has references to multiple types with the same fully qualified names, differing only by assembly name. While this could be handled using [`extern alias`](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/extern-alias), it massively complicates the experience for consumers of the library, and would need better support from tooling before being made mainstream.
229
+
230
+
Changing the *namespace* of shaded assemblies would also make public shaded references possible, but this would substantially complicate the assembly rewriting and bake the rewritten namespaces into the APIs, samples, and docs. This is not scalable and doesn't align with the long term goal of consumer-side shading.
211
231
212
232
### As a package author, when should I shade a dependency?
0 commit comments