Skip to content

Fix the plugin references to work with packages - #16799

Merged
tdykstra merged 4 commits into
dotnet:masterfrom
vitek-karas:FixPluginProjectReferences
Jan 24, 2020
Merged

tdykstra merged 4 commits into
dotnet:masterfrom
vitek-karas:FixPluginProjectReferences

Conversation

@vitek-karas

Copy link
Copy Markdown
Member

Summary

For plugins to correctly reference other projects they need to specify both Private=false and ExcludeAssets=runtime so that it works for both project and package references.

Fixes #15811

For plugins to correctly reference other projects they need to specify both Private=false and ExcludeAssets=runtime so that it works for both project and package references.
@mairaw
mairaw requested a review from jkoritzinsky January 24, 2020 02:15

@tdykstra tdykstra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for one question.

The `<Private>false</Private>` element is important. This tells MSBuild to not copy *PluginBase.dll* to the output directory for HelloPlugin. If the *PluginBase.dll* assembly is present in the output directory, `PluginLoadContext` will find the assembly there and load it when it loads the *HelloPlugin.dll* assembly. At this point, the `HelloPlugin.HelloCommand` type will implement the `ICommand` interface from the *PluginBase.dll* in the output directory of the `HelloPlugin` project, not the `ICommand` interface that is loaded into the default load context. Since the runtime sees these two types as different types from different assemblies, the `AppWithPlugin.Program.CreateCommands` method won't find the commands. As a result, the `<Private>false</Private>` metadata is required for the reference to the assembly containing the plugin interfaces.

Now that the `HelloPlugin` project is complete, we should update the `AppWithPlugin` project to know where the `HelloPlugin` plugin can be found. After the `// Paths to plugins to load` comment, add `@"HelloPlugin\bin\Debug\netcoreapp3.0\HelloPlugin.dll"` as an element of the `pluginPaths` array.
Similarly, the `<ExcludeAssets>runtime</ExcludeAssets>` element is also important if the `PluginBase` references other packages. This setting has the same effect as `<Private>false</Private>` but works on package references in the transitive closure of dependencies of the `PluginBase` project.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we expect the intended audience of this article to be familiar with the phrase "transitive closure of dependencies"? If not, a brief explanation might be helpful.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I changed the wording - hopefully it's easier to understand now.

@tdykstra tdykstra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugins should include ExcludeAssets=runtime for project references to shared assemblies

7 participants