Avalonia 程序打包成Linux平台的运行程序
1.安装Parcel
dotnet tool install --global AvaloniaUI.Parcel
2.简化.csproj
一个干净的Avalonia MVVM项目的.csproj应该是这样的:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<!-- 这些打包属性是给 Parcel 读取的,不是必需的 -->
<ApplicationName>AvaloniaMvvmNew</ApplicationName>
<PackageName>avalonia-mvvm-new</PackageName>
<AssemblyVersion>1.0.0</AssemblyVersion>
</PropertyGroup>
<!-- 只需要 Avalonia 相关的包,不要加 Parcel 包引用 -->
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.3" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.3" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
</ItemGroup>
</Project>
注意事项:
Parcel 是.Net全局工具,不是Nuget包
.包名是 AvaloniaUI.Parcel 不是Avalonia.Ide 如果提示这个错误可能是包名引用错误
.它是通过 dotnet tool install安装的,而不是通过 添加到项目中的。
MSBuild 集成方式
。Parecel 的打包功能是铜鼓偶命令行或图形界面直接调用的
。不需要在.csproj中添加特殊的包引用
使用正确的打包命令:
既然Parcel 是独立的工具,打包的命令应该是这样的:
# 1. 进入项目目录
cd F:\Demos\AvaloniaDemos\t3\AvaloniaMvvmNew
# 2. 先发布项目(生成可执行文件)
dotnet publish -c Release -r linux-x64 --self-contained true -o ./publish/linux-x64
# 3. 使用 parcel 命令打包(不是 dotnet build -t:ParcelBuildDeb)
parcel pack ./publish/linux-x64 --output ./installers --platform linux --format deb


进入指定目录下可以看到:


浙公网安备 33010602011771号