Force generated assemblies to reference jsii-only dependencies.#216
Merged
Force generated assemblies to reference jsii-only dependencies.#216
Conversation
costleya
approved these changes
Sep 7, 2018
packages/jsii-dotnet-generator/src/Amazon.JSII.Generator.UnitTests/AssemblyGeneratorTests.cs
Show resolved
Hide resolved
| return Path.Combine(path, "Internal", "DependencyResolution", "Anchor.cs"); | ||
| } | ||
|
|
||
| static string GetTypeFilePath(string dotnetPackage, string dotnetNamespace, string dotnetType) |
Contributor
Author
There was a problem hiding this comment.
I'm find with adding explicit access modifiers where they are currently implied, but currently the codebase omits all redundant access modifiers. If we change this, we should change it across the whole codebase.
Created #217 to track this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-runtimeloads 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-packagedepends onmy-dependency.my-packagerequires symbols frommy-dependency. Therefore the NuGet packageMyPackagelistsMyDependencyas a dependency.MyPackagedoes not reference any symbols fromMyDependency.At runtime, the first time a type from
MyPackageis used,jsii-dotnet-runtimewill search forMyPackage's dependencies, and askjsii-runtimeto 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-packageattempts torequire('my-dependency'), it will fail.To work around this issue, for each package, we generate a type
MyNamespace.Internal.DependencyResolution.Anchorthat references theAnchorfrom each of its dependencies. This way all listed dependencies will show up in the .NET assembly's references, avoiding this issue.