Skip to content

Commit 542ece2

Browse files
committed
支持平台运行时包自动注册与分析器校验
重构包结构,新增 LVGLSharp.Core、Runtime.Windows、Runtime.Linux,Forms 只负责 WinForms API 兼容层。实现 Application.UseRuntime 自动注册机制,入口代码更简洁。Demo 工程多目标引用并自动选择运行时。CI 打包流程同步调整。新增 Roslyn 分析器和 MSBuild 校验,编译期提示未引用平台运行时包。抽象输入状态,支持跨平台右键菜单。完善 README 与 NuGet 元数据,提升开发体验与安全性。
1 parent bdbb391 commit 542ece2

24 files changed

+399
-49
lines changed

.github/workflows/nuget-publish.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
contents: read
3434

3535
# ──────────────────────────────────────────────────────────────────────────
36-
# 2. 组装 LVGLSharp.Native NuGet 包及托管代码包
36+
# 2. 组装原生包、共享托管包、平台运行时包与 Forms 包
3737
# ──────────────────────────────────────────────────────────────────────────
3838
pack:
3939
needs: build-native
@@ -119,21 +119,45 @@ jobs:
119119
-p:Version=${{ steps.ver.outputs.version }} \
120120
--output nupkgs
121121
122-
# ── 注册本地 NuGet 源,供 Interop 打包时解析 LVGLSharp.Native 依赖 ────
122+
# ── 注册本地 NuGet 源,供依赖 LVGLSharp.Native 的包在 CI 中解析本地产物 ───
123123
# CI 环境中 $(CI)==true 会激活 LVGLSharp.Native 包引用,
124124
# 此时该包尚未发布到 NuGet.org,需要指向本地 nupkgs/ 目录。
125125
- name: 注册本地 NuGet 源
126126
run: dotnet nuget add source "$(pwd)/nupkgs" --name local-packages
127127

128-
# ── 打包 LVGLSharp.Interop ────────────────────────────────────────────
128+
# ── 打包 LVGLSharp.Interop(依赖 LVGLSharp.Native) ───────────────────
129129
- name: 打包 LVGLSharp.Interop
130130
run: |
131131
dotnet pack src/LVGLSharp.Interop/LVGLSharp.Interop.csproj \
132132
-c Release \
133133
-p:Version=${{ steps.ver.outputs.version }} \
134134
--output nupkgs
135135
136-
# ── 打包 LVGLSharp.Forms ──────────────────────────────────────────────
136+
# ── 打包 LVGLSharp.Core(Forms 与平台运行时共享依赖) ─────────────────
137+
- name: 打包 LVGLSharp.Core
138+
run: |
139+
dotnet pack src/LVGLSharp.Core/LVGLSharp.Core.csproj \
140+
-c Release \
141+
-p:Version=${{ steps.ver.outputs.version }} \
142+
--output nupkgs
143+
144+
# ── 打包 LVGLSharp.Runtime.Windows(Windows 平台运行时) ───────────────
145+
- name: 打包 LVGLSharp.Runtime.Windows
146+
run: |
147+
dotnet pack src/LVGLSharp.Windows/LVGLSharp.Runtime.Windows.csproj \
148+
-c Release \
149+
-p:Version=${{ steps.ver.outputs.version }} \
150+
--output nupkgs
151+
152+
# ── 打包 LVGLSharp.Runtime.Linux(Linux 平台运行时) ──────────────────
153+
- name: 打包 LVGLSharp.Runtime.Linux
154+
run: |
155+
dotnet pack src/LVGLSharp.Runtime.Linux/LVGLSharp.Runtime.Linux.csproj \
156+
-c Release \
157+
-p:Version=${{ steps.ver.outputs.version }} \
158+
--output nupkgs
159+
160+
# ── 打包 LVGLSharp.Forms(平台无关;由运行时包自动注册宿主) ──────────
137161
- name: 打包 LVGLSharp.Forms
138162
run: |
139163
dotnet pack src/LVGLSharp.WinForms/LVGLSharp.Forms.csproj \

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131

3232
| 包名 | 说明 |
3333
|------|------|
34-
| `LVGLSharp.Forms` | WinForms API 兼容层(核心包) |
34+
| `LVGLSharp.Forms` | WinForms API 兼容层 |
35+
| `LVGLSharp.Core` | 运行时共享抽象与公共字体/宿主辅助能力 |
36+
| `LVGLSharp.Runtime.Windows` | Windows 平台运行时;引用后自动注册 Windows 宿主 |
37+
| `LVGLSharp.Runtime.Linux` | Linux 平台运行时;引用后自动注册 Linux 宿主 |
3538
| `LVGLSharp.Interop` | LVGL P/Invoke 绑定(自动生成) |
3639
| `LVGLSharp.Native` | 各平台 LVGL 原生库(win-x86 / win-x64 / win-arm64、linux-arm 等) |
3740

@@ -41,10 +44,20 @@
4144

4245
### 1. 创建项目
4346

44-
推荐按仓库中的示例采用多目标框架的方式:使用 Visual Studio 创建 Windows Forms 应用程序(.NET),以 `net10.0-windows` 目标启用设计器(`UseWindowsForms=true`),再增加一个纯 `net10.0` 目标用于跨平台运行并在该目标下引用 `LVGLSharp.Forms`。可参考示例工程的配置:[`src/Demos/WinFormsDemo/WinFormsDemo.csproj`](./src/Demos/WinFormsDemo/WinFormsDemo.csproj)
47+
推荐按仓库中的示例采用多目标框架的方式:使用 Visual Studio 创建 Windows Forms 应用程序(.NET),以 `net10.0-windows` 目标启用设计器(`UseWindowsForms=true`),再增加一个纯 `net10.0` 目标用于跨平台运行。
48+
49+
在跨平台运行目标下:
50+
51+
- 始终引用 `LVGLSharp.Forms`
52+
- Windows 项目再引用 `LVGLSharp.Runtime.Windows`
53+
- Linux 项目再引用 `LVGLSharp.Runtime.Linux`
54+
55+
对应平台运行时包被引用后,会自动完成宿主注册;如果没有引用任何平台运行时包,编译期会收到提示。可参考示例工程的配置:[`src/Demos/WinFormsDemo/WinFormsDemo.csproj`](./src/Demos/WinFormsDemo/WinFormsDemo.csproj)
4556

4657
### 2. 入口程序
4758

59+
引用了对应平台运行时包后,入口程序无需手动注册运行时:
60+
4861
```csharp
4962
using LVGLSharp.Forms;
5063

@@ -90,10 +103,12 @@ src/
90103
├── LVGLSharp.WinForms/ # WinForms API 兼容层(核心)
91104
│ ├── Forms/ # 控件实现(Control、Form、Button 等)
92105
│ ├── Darwing/ # 跨平台绘图类型(Size、Point、Color 等)
93-
│ └── Runtime/ # 平台运行时(Windows / Linux)
106+
│ └── Runtime/ # 公共运行时注册入口与共享胶水代码
107+
├── LVGLSharp.Core/ # 公共核心库
108+
├── LVGLSharp.Windows/ # Windows 平台运行时
109+
├── LVGLSharp.Runtime.Linux/# Linux 平台运行时
94110
├── LVGLSharp.Interop/ # LVGL P/Invoke 自动生成绑定
95111
├── LVGLSharp.Native/ # 各平台原生库
96-
├── LVGLSharp.Core/ # 公共核心库
97112
└── Demos/
98113
└── WinFormsDemo/ # 演示项目
99114
libs/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using LVGLSharp.Forms;
3+
4+
internal static class DemoRuntimeConfiguration
5+
{
6+
internal static void Configure()
7+
{
8+
if (OperatingSystem.IsWindows())
9+
{
10+
Application.UseWindowsRuntime();
11+
return;
12+
}
13+
14+
if (OperatingSystem.IsLinux())
15+
{
16+
Application.UseLinuxRuntime();
17+
return;
18+
}
19+
20+
throw new PlatformNotSupportedException();
21+
}
22+
}

src/Demos/PictureBoxDemo/PictureBoxDemo.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@
1717
</ItemGroup>
1818
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
1919
<ProjectReference Include="..\..\LVGLSharp.WinForms\LVGLSharp.Forms.csproj" />
20+
<ProjectReference Include="..\..\LVGLSharp.Windows\LVGLSharp.Runtime.Windows.csproj" />
21+
<ProjectReference Include="..\..\LVGLSharp.Runtime.Linux\LVGLSharp.Runtime.Linux.csproj" />
22+
<Compile Include="..\DemoRuntimeConfiguration.cs" Link="DemoRuntimeConfiguration.cs" />
23+
<Compile Include="..\..\LVGLSharp.Windows\buildTransitive\LVGLSharp.Runtime.Windows.ApplicationExtensions.g.cs" Link="Generated\LVGLSharp.Runtime.Windows.ApplicationExtensions.g.cs" Visible="false" />
24+
<Compile Include="..\..\LVGLSharp.Runtime.Linux\buildTransitive\LVGLSharp.Runtime.Linux.ApplicationExtensions.g.cs" Link="Generated\LVGLSharp.Runtime.Linux.ApplicationExtensions.g.cs" Visible="false" />
2025
<Using Include="LVGLSharp.Forms" />
2126
<Using Include="LVGLSharp.Darwing" />
2227
</ItemGroup>
2328
<ItemGroup>
24-
<ProjectReference Include="..\..\LVGLSharp.Analyzers\LVGLSharp.Analyzers.csproj"
25-
OutputItemType="Analyzer"
26-
ReferenceOutputAssembly="false" />
29+
<ProjectReference Include="..\..\LVGLSharp.Analyzers\LVGLSharp.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
2730

2831
<Content Include="lvgl.png">
2932
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3033
</Content>
3134
</ItemGroup>
3235
<ItemGroup>
33-
<PackageReference Include="LVGLSharp.Native" Version="0.0.3" />
36+
<PackageReference Include="LVGLSharp.Native" Version="9.3.0.1" />
3437
</ItemGroup>
3538

3639
</Project>

src/Demos/PictureBoxDemo/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ static void Main()
1313
// To customize application configuration such as set high DPI settings or default font,
1414
// see https://aka.ms/applicationconfiguration.
1515
ApplicationConfiguration.Initialize();
16+
17+
#if !WINDOWS
18+
DemoRuntimeConfiguration.Configure();
19+
#endif
20+
1621
Application.Run(new frmPictureBoxDemo());
1722
}
1823
}

src/Demos/WinFormsDemo/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ static void Main()
1313
// To customize application configuration such as set high DPI settings or default font,
1414
// see https://aka.ms/applicationconfiguration.
1515
ApplicationConfiguration.Initialize();
16+
17+
#if !WINDOWS
18+
DemoRuntimeConfiguration.Configure();
19+
#endif
20+
1621
Application.Run(new frmMain());
1722
}
1823
}

src/Demos/WinFormsDemo/WinFormsDemo.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
</ItemGroup>
2121
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
2222
<ProjectReference Include="..\..\LVGLSharp.WinForms\LVGLSharp.Forms.csproj" />
23+
<ProjectReference Include="..\..\LVGLSharp.Windows\LVGLSharp.Runtime.Windows.csproj" />
24+
<ProjectReference Include="..\..\LVGLSharp.Runtime.Linux\LVGLSharp.Runtime.Linux.csproj" />
25+
<Compile Include="..\DemoRuntimeConfiguration.cs"
26+
Link="DemoRuntimeConfiguration.cs" />
27+
<Compile Include="..\..\LVGLSharp.Windows\buildTransitive\LVGLSharp.Runtime.Windows.ApplicationExtensions.g.cs"
28+
Link="Generated\LVGLSharp.Runtime.Windows.ApplicationExtensions.g.cs"
29+
Visible="false" />
30+
<Compile Include="..\..\LVGLSharp.Runtime.Linux\buildTransitive\LVGLSharp.Runtime.Linux.ApplicationExtensions.g.cs"
31+
Link="Generated\LVGLSharp.Runtime.Linux.ApplicationExtensions.g.cs"
32+
Visible="false" />
2333
<Using Include="LVGLSharp.Forms" />
2434
<Using Include="LVGLSharp.Darwing" />
2535
</ItemGroup>

src/LVGLSharp.Analyzers/AnalyzerReleases.Unshipped.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Rule ID | Category | Severity | Notes
66
--------|----------|----------|-----
77
LVGL001 | Layout | Warning | Enforces LVGLSharp layout FlowLayoutPanel rows inside main TableLayoutPanel layouts.
88
LVGL002 | Layout | Warning | Disallows percent-based RowStyle usage in LVGLSharp layout designer layouts.
9+
LVGL003 | Usage | Warning | Reports when LVGLSharp.Forms is referenced without LVGLSharp.Runtime.Windows or LVGLSharp.Runtime.Linux.

src/LVGLSharp.Analyzers/AnalyzerResources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,13 @@
3030
<data name="AbsoluteRowRuleDescription" xml:space="preserve">
3131
<value>LVGLSharp layout uses fixed row heights for the outer main TableLayoutPanel to keep LVGL controls visible.</value>
3232
</data>
33+
<data name="MissingRuntimeRuleTitle" xml:space="preserve">
34+
<value>LVGLSharp.Forms requires a platform runtime package</value>
35+
</data>
36+
<data name="MissingRuntimeRuleMessage" xml:space="preserve">
37+
<value>Add a reference to LVGLSharp.Runtime.Windows or LVGLSharp.Runtime.Linux so LVGLSharp.Forms can register a runtime automatically.</value>
38+
</data>
39+
<data name="MissingRuntimeRuleDescription" xml:space="preserve">
40+
<value>LVGLSharp.Forms needs a platform runtime package reference to provide the host window implementation and automatic runtime registration.</value>
41+
</data>
3342
</root>

src/LVGLSharp.Analyzers/LVGLSharp.Analyzers.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
14-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" PrivateAssets="all" />
13+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="5.3.0" PrivateAssets="all" />
14+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" PrivateAssets="all" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

0 commit comments

Comments
 (0)