我正在尝试让 ClickOnce 安装适用于 Windows 上的 MAUI,自动更新是这样做的最重要原因。它仅供内部使用,我们希望部署到文件共享(就像我们过去使用 WPF 应用程序成功完成的那样)。
为了将任何因素与真实应用程序隔离开来,我从模板 MAUI 应用程序开始(稍作调整以显示正在运行的版本)。我使用 Visual Studio 进行发布,使用下面的 .pubxml 设置,指定在启动时检查更新,并告诉它在完成时复制安装文件。我最终在文件共享上得到了一个名为“MauiAppPublishTest_1.8.13.0_Test”的文件夹,其中包含一个
.cer
一个 .msix
文件,以及一个包含运行时安装程序的 Dependencies
文件夹。
与我已经工作的 WPF ClickOnce 发布的输出相比,没有顶级
.application
文件指示要自动更新到的当前版本,所以我对它不起作用并不感到惊讶。
我将从 MSIX 文件安装,它安装并运行良好,但当我增加版本号并再次发布时,它永远不会下载更新。
我在网上找不到任何具体的示例来说明如何实现这一点。当我证明这个过程时,我使用 Visual Studio 生成的自签名密钥进行签名,我在我的计算机上信任该密钥。
我做错了什么,和/或哪里有示例显示如何使用 ClickOnce 发布具有自动更新功能的 MAUI 应用程序?
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrl>\\fileservername\SHARENAME\Apps\Dev\AppName\</PublishUrl>
<PublishDir>bin\Release\net7.0-windows10.0.19041.0\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<Platform>Any CPU</Platform>
<Configuration>Release</Configuration>
<TargetFramework>net7.0-windows10.0.19041.0</TargetFramework>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<SelfContained>True</SelfContained>
<PublishAppxPackage>true</PublishAppxPackage>
<AppxPackageDir>bin\Release\net7.0-windows10.0.19041.0\appx\</AppxPackageDir>
</PropertyGroup>
</Project>
Visual Studio 未正确生成 .appinstaller 文件,但它应该存在。 (您可以在 stackoverflow 上找到一些与此主题相关的帖子使用 MSIX 发布 .Net Maui 应用程序时未生成应用程序安装文件)
我能够通过以下方式使其适用于我的毛伊岛应用程序(希望它也适用于您):
以下是正确格式化的 .appinstaller 文件示例(将文件命名为 YOURAPPNAME.appinstaller):
<?xml version="1.0" encoding="utf-8"?>
<AppInstaller
Version="YOUR APP VERSION (0.0.0.1 for example)"
Uri="http://yourhost/YOURAPPNAME.appinstaller"
xmlns="http://schemas.microsoft.com/appx/appinstaller/2017/2">
<MainPackage
Name="APPLICATION GUID -> Check your app properties"
Publisher="publisher details"
Version="CURRENT APP VERSION"
ProcessorArchitecture="x64"
Uri="http://yourhost- pointing at your latest msix YourAppFolder_0.0.0.0_Test/YOURAPPMSIXFILE.msix" />
<Dependencies>
<Package
Version="3000.934.1904.0"
Uri="http://your host pointing at your dependencies YourAppFolder_0.0.0.0_Test/Dependencies/x64/Microsoft.WindowsAppRuntime.1.3.msix"
Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
ProcessorArchitecture="x64"
Name="Microsoft.WindowsAppRuntime.1.3" />
</Dependencies>
<UpdateSettings>
<OnLaunch
HoursBetweenUpdateChecks="0" />
<AutomaticBackgroundTask />
</UpdateSettings>
</AppInstaller>
如果您第一次通过微软工具生成 .appinstaller 会更容易,然后每次更新后您只需要修改应用程序版本(以及依赖项,如果它们发生变化)
不要期望看到旧的 clickonce 更新窗口出现,应用程序将在启动时在后台更新(有时需要额外重新启动)