Files
velopack/samples/UnoSample/README.md
Kevin Bost 4484734be7 WIP getting an Uno sample working
Getting Uno WinUI entry point working

Starting README with Uno app description

Updating Uno sample with a README
2024-06-11 08:39:04 +01:00

63 lines
3.6 KiB
Markdown

# Uno with Velopack
This solution contains an Uno Desktop application that targets both Windows and macOS. Because Velopack does not currently support mobile or web platforms, those are not included.
## Prerequisites
This solution will publish the application out to the Velopack Flow service. To test the full publish you will need to create a [Velopack Flow account](https://app.velopack.io).
The solution assumes that you have downloaded and installed the Velopack CLI (`vpk`) global tool. This tool can be installed by running `dotnet tool install -g vpk`. You will then need ot authenticate with the Velopack Flow servie by running `vpk login` and signing in with your Velopack Flow account.
## The Application
Inside of `Presentation` the `MainPage.xaml` contains the main UI for viewing the current version, checking for updates, and applying the latest update.
The `MainViewModel.cs` contains the logic for checking for updates and applying them. The key piece of the setup is the initialization of the `UpdateManager` with the `VelopackFlowUpdateSource` which provides the interaction with the Velopack Flow service.
The `Main` methods in the `Platforms\Desktop\Program.cs` has been updated to contain the [Velopack application startup hook](https://docs.velopack.io/integrating/overview).
The `Main` methods in the `Platforms\MacCatalyst\Main.maccatalyst.cs` has been updated to contain the [Velopack application startup hook](https://docs.velopack.io/integrating/overview).
Finally, for the WinUI platform, a little more work is needed as the `Main` method is auto-generated by default.
First, the generation of the `Main` method needs to be disabled by defining `DISABLE_XAML_GENERATED_MAIN` constant in the csproj.
```xml
<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-windows10.0.19041'">
<DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_MAIN</DefineConstants>
</PropertyGroup>
```
Next the `Main` method needs to be added so a new `Platforms\Windows\Program.cs` file is added with a standard content, and the [Velopack application startup hook](https://docs.velopack.io/integrating/overview):
```csharp
[STAThread]
public static void Main(string[] args)
{
// It's important to Run() the VelopackApp as early as possible in app startup.
VelopackApp.Build()
.WithFirstRun((v) => { /* Your first run code here */ })
.Run();
WinRT.ComWrappersSupport.InitializeComWrappers();
Application.Start((p) =>
{
var context = new DispatcherQueueSynchronizationContext(
DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
new App();
});
}
```
### Updating the Project file
There are two properties to set in the `csproj` file to enable the Velopack Flow integration. These are:
```xml
<VelopackPushOnPublish>true</VelopackPushOnPublish>
<VelopackPackId>Velopack.UnoSample</VelopackPackId>
```
`VelopackPackId` is the unique identifier for the application. This is used to identify the application in the Velopack Flow service. It must be unique among all applications.
`VelopackPushOnPublish` is a boolean value that determines if the application should be pushed to the Velopack Flow service when it is published. This should be set to `true` to enable the integration.
### Building installers
To build the local installers run the following command replacing `<Version>` with the desired version number.
The `-f` option is used to specify the target framework. This can be any of the desktop frameworks specified in the `csproj` file.
```bash
dotnet publish -c Release -f net8.0-desktop -p:Version=<Version>
```