feat: 新的插件结构和加载逻辑, 插件项目模板 #18
Merged
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.
旧说明
现在所有在
Plugins的插件可以有两种形式, 一种是没有外部依赖的"裸"dll, 会被直接加载, 另一种是打包后的插件, 遵循以下结构:是的还支持了 .NET 本体的附属程序集, 但是整个项目被改的很看不下去, 在考虑是不是真的需要支持附属程序集最顶层只能放置插件的程序集以及符号文件, 以及
Libraries目录, 任何插件尝试加载的程序集都会在这里寻找,Libraries/zh-Hans这种更深层的附属程序集的目录也会被在尝试加载附属程序集时寻找(使用的 Culture 是CurrentUICulture, 和ResourceManager使用的默认 Culture 一致, 或许应该考虑和 I18N service 的一致?).此外新增
PluginTypeAttribute, 应用在程序集上, 来指定该程序集的Plugin类, 如果没有找到的话会 fallback 到搜索整个程序集.有关模板, 新增了一个
CurvaLauncher.PluginTemplate目录放置模板项目, 可以在src目录下使用dotnet new install CurvaLauncher.PluginTemplate安装, 然后使用类似下面的命令行:dotnet new curvaplugin -n "MySuperCurvaPlugin" dotnet new curvaplugin -clproj ../CurvaLauncher dotnet new curvaplugin -clpath ../CurvaLauncher/buildclproj和clpath都会更改生成的.csproj里的两个目录CurvaLauncherProject,CurvaLauncherPath, 前者用来指定CurvaLauncher项目源代码位置(用来引用Plugins项目, 有更优雅的做法吗(?)), 后者用来指定CurvaLauncher编译产物的位置(用来在编译完后复制项目编译后的文件到Plugins文件夹内)模板生成的项目在编译后会执行一个
msbuildtask 将所有编译产物调整至上面 zip 的结构然后打包成 zip 复制到程序的Plugins文件夹内.此外还附带一个
publishToZip.ps1脚本, 它会将项目编译完后的.zip放置到项目根目录用来分发.大概就这些了, 但是感觉要改的地方好多breaking change 地修改了加载逻辑, 除了和之前兼容的"裸 dll"加载方法, 现在对于 zip 插件加载, zip 可有如下结构:
Manifest.jsonMyPlugin.dllMyPlugin.pdbMyPlugin.deps.jsonxxx.dllruntimeswin-x64nativenativelib.dllzh-HansFSharp.Core.resources.dll其中
Manifest.json结构:{ "ID": "SHLoadIndirectStringList", "Assembly": "CurvaLauncher.Plugins.SHLoadIndirectStringList.dll" }ID作为保留字段(目前插件似乎都没有一个类似 id 的东西来着), 可能未来在支持插件见引用时有用(真的会有支持这个的时候吗(x))Assembly指示插件主程序集的名字所有
runtimes(包括本机库),zh-Hans(附属程序集) 会使用MyPlugin.deps.json进行 probe, 所以如果需要额外的平台库或者附属程序集正常加载的话需要正确添加.deps.json文件(通过设置GenerateDependencyFile为true)此外新增
PluginTypeAttribute, 应用在程序集上, 来指定该程序集的Plugin类, 如果没有找到的话会 fallback 到搜索整个程序集.模板位于
Template文件夹中作为一个独立的CurvaLauncher.PluginTemplate.csproj项目, 可以通过dotnet pack后得到的 nuget 包使用类似于dotnet new install CurvaLauncher.PluginTemplate.0.7.1-beta.nupkg安装, 或者发布到 nuget.org 上后直接使用类似dotnet new install CurvaLauncher.PluginTemplate安装.然后可以用类似下面的命令行创建项目:
如果 clpath 被正确指定了的话, 在项目构建完成时 msbuild 会将编译输出打包复制到 CurvaLauncher 的 Plugins 目录下.
可通过
NoZipOutputPlugin设置为true关闭.此外也还附带一个
publishToZip.ps1, 会将项目以Release配置编译后就地打包一个 zip 以便发布.大概就这些了, 另外测试时出现了大量 bug, 现在生怕有漏网之鱼