Force generated assemblies to reference jsii-only dependencies. #216
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a NuGet package is restored, all of its listed dependencies are restored (whether or not they are actually used). But when a .NET assembly is built, if it does not reference any .NET types from the dependency, the compiled .NET assembly will not reference the dependency .NET assembly.
At runtime,
jsii-dotnet-runtime
loads JSII dependencies by looking through the .NET assembly's references. If the dependency does not appear in references, it won't be found.This breaks the following scenario:
my-package
depends onmy-dependency
.my-package
requires symbols frommy-dependency
. Therefore the NuGet packageMyPackage
listsMyDependency
as a dependency.MyPackage
does not reference any symbols fromMyDependency
.At runtime, the first time a type from
MyPackage
is used,jsii-dotnet-runtime
will search forMyPackage
's dependencies, and askjsii-runtime
to load each of them (i.e.my-dependency
) before attempting to loadmy-package
. But due to the missing assembly reference, it won't be able to findmy-dependency
. So when the javascript code formy-package
attempts torequire('my-dependency')
, it will fail.To work around this issue, for each package, we generate a type
MyNamespace.Internal.DependencyResolution.Anchor
that references theAnchor
from each of its dependencies. This way all listed dependencies will show up in the .NET assembly's references, avoiding this issue.