name: msix-package-generator description: 为Windows应用程序生成包含清单、资源和签名的MSIX打包配置 allowed-tools: Read, Write, Edit, Bash, Glob, Grep tags: [windows, msix, 打包, uwp, 分发]
msix-package-generator
为Windows应用程序生成MSIX打包配置,包括正确的清单、资源、签名配置和商店提交准备。此技能处理完整的MSIX打包工作流。
功能
- 生成Package.appxmanifest
- 创建所需的视觉资源(图标、磁贴)
- 配置应用程序功能和声明
- 设置MSIX代码签名
- 配置自动更新设置
- 准备Microsoft商店提交
- 生成CI/CD打包脚本
- 配置旁加载部署
输入模式
{
"type": "object",
"properties": {
"projectPath": {
"type": "string",
"description": "项目路径"
},
"appInfo": {
"type": "object",
"properties": {
"name": { "type": "string" },
"displayName": { "type": "string" },
"publisher": { "type": "string" },
"publisherDisplayName": { "type": "string" },
"version": { "type": "string" },
"description": { "type": "string" }
},
"required": ["name", "displayName", "publisher", "version"]
},
"capabilities": {
"type": "array",
"items": {
"enum": ["internetClient", "privateNetworkClientServer", "documentsLibrary", "musicLibrary", "picturesLibrary", "webcam", "microphone", "location", "removableStorage", "appointments", "contacts"]
}
},
"executables": {
"type": "array",
"items": {
"type": "object",
"properties": {
"target": { "type": "string" },
"id": { "type": "string" },
"subsystem": { "enum": ["windows", "console"] }
}
}
},
"distribution": {
"enum": ["store", "sideload", "both"],
"default": "sideload"
}
},
"required": ["projectPath", "appInfo"]
}
输出模式
{
"type": "object",
"properties": {
"success": { "type": "boolean" },
"files": {
"type": "array",
"items": {
"type": "object",
"properties": {
"path": { "type": "string" },
"type": { "enum": ["manifest", "assets", "priconfig", "signing"] }
}
}
},
"buildCommands": {
"type": "object",
"properties": {
"package": { "type": "string" },
"sign": { "type": "string" }
}
}
},
"required": ["success"]
}
Package.appxmanifest
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap uap3 desktop rescap">
<Identity Name="MyCompany.MyApp"
Publisher="CN=My Company, O=My Company, L=City, S=State, C=US"
Version="1.0.0.0"
ProcessorArchitecture="x64"/>
<Properties>
<DisplayName>我的应用程序</DisplayName>
<PublisherDisplayName>我的公司</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
<Description>一个优秀的应用程序</Description>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop"
MinVersion="10.0.17763.0"
MaxVersionTested="10.0.22621.0"/>
</Dependencies>
<Resources>
<Resource Language="en-us"/>
</Resources>
<Applications>
<Application Id="App"
Executable="MyApp.exe"
EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements
DisplayName="我的应用程序"
Description="一个优秀的应用程序"
BackgroundColor="transparent"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile
Wide310x150Logo="Assets\Wide310x150Logo.png"
Square310x310Logo="Assets\Square310x310Logo.png"
Square71x71Logo="Assets\SmallTile.png"
ShortName="MyApp">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo"/>
<uap:ShowOn Tile="wide310x150Logo"/>
<uap:ShowOn Tile="square310x310Logo"/>
</uap:ShowNameOnTiles>
</uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png"/>
</uap:VisualElements>
<!-- 文件类型关联 -->
<Extensions>
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="myapp">
<uap:SupportedFileTypes>
<uap:FileType>.myapp</uap:FileType>
</uap:SupportedFileTypes>
</uap:FileTypeAssociation>
</uap:Extension>
<!-- 协议处理器 -->
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="myapp">
<uap:DisplayName>我的应用程序协议</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
<!-- 启动任务 -->
<desktop:Extension Category="windows.startupTask">
<desktop:StartupTask
TaskId="MyAppStartupTask"
Enabled="false"
DisplayName="我的应用程序后台服务"/>
</desktop:Extension>
</Extensions>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient"/>
<rescap:Capability Name="runFullTrust"/>
</Capabilities>
</Package>
视觉资源
Assets/
├── AppIcon.ico # 传统图标
├── StoreLogo.png # 50x50
├── Square44x44Logo.png # 44x44(包含.targetsize-*变体)
├── Square44x44Logo.targetsize-16.png
├── Square44x44Logo.targetsize-24.png
├── Square44x44Logo.targetsize-32.png
├── Square44x44Logo.targetsize-48.png
├── Square44x44Logo.targetsize-256.png
├── Square150x150Logo.png # 150x150
├── Square310x310Logo.png # 310x310
├── Wide310x150Logo.png # 310x150
├── SmallTile.png # 71x71
├── SplashScreen.png # 620x300
└── BadgeLogo.png # 24x24
priconfig.xml
<?xml version="1.0" encoding="utf-8"?>
<resources targetOsVersion="10.0.0" majorVersion="1">
<packaging>
<autoResourcePackage qualifier="Language"/>
<autoResourcePackage qualifier="Scale"/>
</packaging>
<index root="\" startIndexAt="\">
<default>
<qualifier name="Language" value="en-US"/>
<qualifier name="Scale" value="100"/>
</default>
<indexer-config type="folder" foldernameAsQualifier="true" filenameAsQualifier="true"/>
<indexer-config type="resw" convertDotsToSlashes="true" initialPath=""/>
<indexer-config type="resfiles" qualifierDelimiter="."/>
<indexer-config type="PRI"/>
</index>
</resources>
构建命令
# 构建MSIX包
msbuild MyApp.wapproj /p:Configuration=Release /p:Platform=x64 /p:AppxBundle=Always
# 使用makeappx创建包
makeappx pack /d output\ /p MyApp.msix
# 签名包
signtool sign /fd SHA256 /a /f certificate.pfx /p password MyApp.msix
# 创建测试用的自签名证书
$cert = New-SelfSignedCertificate -Type Custom -Subject "CN=MyCompany" `
-KeyUsage DigitalSignature -FriendlyName "MyApp Test Cert" `
-CertStoreLocation "Cert:\CurrentUser\My"
Export-PfxCertificate -cert $cert -FilePath test.pfx -Password (ConvertTo-SecureString -String "password" -Force -AsPlainText)
.csproj配置
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<!-- MSIX打包 -->
<EnableMsixTooling>true</EnableMsixTooling>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
<PublishProfile>MSIX</PublishProfile>
<!-- 包标识 -->
<ApplicationId>MyCompany.MyApp</ApplicationId>
<ApplicationDisplayVersion>1.0.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
</PropertyGroup>
<ItemGroup>
<Content Include="Assets\**" CopyToOutputDirectory="PreserveNewest"/>
</ItemGroup>
</Project>
GitHub Actions CI
name: 构建MSIX
on: [push]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: 设置.NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: 解码证书
run: |
$bytes = [Convert]::FromBase64String("${{ secrets.SIGNING_CERTIFICATE }}")
[IO.File]::WriteAllBytes("cert.pfx", $bytes)
- name: 构建MSIX
run: |
dotnet publish -c Release -p:PublishProfile=MSIX
signtool sign /fd SHA256 /f cert.pfx /p "${{ secrets.CERT_PASSWORD }}" MyApp.msix
- name: 上传制品
uses: actions/upload-artifact@v4
with:
name: msix-package
path: '**/*.msix'
最佳实践
- 使用正确的发布者标识:与证书匹配
- 包含所有必需的资源:所有尺寸的所有显示比例
- 在多个Windows版本上测试:MinVersion很重要
- 使用受信任的证书签名:用于生产分发
- 最小化配置功能:只请求需要的权限
- 测试旁加载部署:在商店提交之前
相关技能
windows-authenticode-signer- 代码签名wpf-mvvm-scaffold- 应用程序设置desktop-build-pipelineprocess - CI/CD
相关代理
windows-platform-expert- Windows专业知识release-manager- 发布工作流