mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Simplify sample code
This commit is contained in:
@@ -15,8 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionLevel", "SolutionLe
|
||||
src\Directory.Build.targets = src\Directory.Build.targets
|
||||
nuget.config = nuget.config
|
||||
README.md = README.md
|
||||
Velopack.entitlements = Velopack.entitlements
|
||||
src\SelfContained.targets = src\SelfContained.targets
|
||||
Velopack.entitlements = Velopack.entitlements
|
||||
version.json = version.json
|
||||
EndProjectSection
|
||||
EndProject
|
||||
@@ -43,7 +43,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestApp", "test\TestApp\Tes
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{3EBFA551-780C-473D-A197-0EE56F2CBA82}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
samples\Directory.Build.props = samples\Directory.Build.props
|
||||
samples\Directory.Build.targets = samples\Directory.Build.targets
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaCrossPlat", "samples\AvaloniaCrossPlat\AvaloniaCrossPlat.csproj", "{1FF6A262-13D0-45DF-B818-77AC84C52C6F}"
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
<NoWarn>$(NoWarn);IDE0161</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -14,32 +13,13 @@
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.0.9" />
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.0.9" />
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.0.9" />
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration. Keep it in your app.-->
|
||||
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- For test build scripts which target the local Velopack project instead of the NuGet package -->
|
||||
<Choose>
|
||||
<When Condition=" $(UseLocalVelopack) != '' ">
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Velopack\Velopack.csproj" />
|
||||
<!--Condition below is only needed to test this sample project against the local projects instead of the NuGet package. Remove it in your app.-->
|
||||
<PackageReference Include="Velopack" Version="0.*" Condition="$(UseLocalVelopack) == ''" />
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Velopack" Version="0.*" />
|
||||
</ItemGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
|
||||
<!-- For demonstrating updates, so the installed application can find the Release directory -->
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
||||
<_Parameter1>AvaloniaSampleReleaseDir</_Parameter1>
|
||||
<_Parameter2>$(MSBuildThisFileDirectory)releases</_Parameter2>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<!--<Import Project="..\..\src\Velopack.Build\Velopack.Build.targets" Condition=" $(UseLocalVelopack) != '' " />-->
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -16,7 +16,10 @@ public partial class MainWindow : Window
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
_um = new UpdateManager(Program.UpdateUrl, logger: Program.Log);
|
||||
|
||||
var updateUrl = SampleHelper.GetReleasesDir(); // replace with your update path/url
|
||||
_um = new UpdateManager(updateUrl, logger: Program.Log);
|
||||
|
||||
TextLog.Text = Program.Log.ToString();
|
||||
Program.Log.LogUpdated += LogUpdated;
|
||||
UpdateStatus();
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Avalonia;
|
||||
using Velopack;
|
||||
|
||||
@@ -8,8 +6,6 @@ namespace AvaloniaCrossPlat;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static string UpdateUrl { get; private set; }
|
||||
|
||||
public static MemoryLogger Log { get; private set; }
|
||||
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
@@ -24,19 +20,12 @@ class Program
|
||||
|
||||
// It's important to Run() the VelopackApp as early as possible in app startup.
|
||||
VelopackApp.Build()
|
||||
.WithFirstRun((v) => { /* Your first run code here */ })
|
||||
.Run(Log);
|
||||
|
||||
// This is purely for demonstration purposes, we get the update URL from a
|
||||
// property defined by MSBuild, so we can locate the local releases directory.
|
||||
// In your production app, this should point to your update server.
|
||||
UpdateUrl = Assembly.GetEntryAssembly()
|
||||
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||
.Where(x => x.Key == "AvaloniaSampleReleaseDir")
|
||||
.Single().Value;
|
||||
|
||||
// Now it's time to run Avalonia
|
||||
BuildAvaloniaApp()
|
||||
.StartWithClassicDesktopLifetime(args);
|
||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||
|
||||
} catch (Exception ex) {
|
||||
string message = "Unhandled exception: " + ex.ToString();
|
||||
Console.WriteLine(message);
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<RestoreSources>https://api.nuget.org/v3/index.json;$(RestoreSources)</RestoreSources>
|
||||
<RestoreSources Condition="Exists('$(MSBuildThisFileDirectory)..\build\$(Configuration)')">
|
||||
$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\build\$(Configuration)'));$(RestoreSources)
|
||||
</RestoreSources>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
32
samples/Directory.Build.targets
Normal file
32
samples/Directory.Build.targets
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<NoWarn>$(NoWarn);IDE0161</NoWarn>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
||||
<_Parameter1>VelopackSampleReleaseDir</_Parameter1>
|
||||
<_Parameter2>$(MSBuildThisFileDirectory)$(ProjectName)/releases</_Parameter2>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\SampleHelper.cs" Link="SampleHelper.cs" Visible="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="$(UseLocalVelopack) != ''">
|
||||
<RestoreSources>https://api.nuget.org/v3/index.json;$(RestoreSources)</RestoreSources>
|
||||
<RestoreSources Condition="Exists('$(MSBuildThisFileDirectory)..\build\$(Configuration)')">
|
||||
$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\build\$(Configuration)'));$(RestoreSources)
|
||||
</RestoreSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="$(UseLocalVelopack) != ''">
|
||||
<ProjectReference Include="..\..\src\Velopack\Velopack.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
10
samples/SampleHelper.cs
Normal file
10
samples/SampleHelper.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
internal static class SampleHelper
|
||||
{
|
||||
public static string GetReleasesDir() => Assembly.GetEntryAssembly()
|
||||
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||
.Where(x => x.Key == "VelopackSampleReleaseDir")
|
||||
.Single().Value;
|
||||
}
|
||||
@@ -13,7 +13,10 @@ namespace VeloWpfSample
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
_um = new UpdateManager(Program.UpdateUrl, logger: Program.Log);
|
||||
|
||||
string updateUrl = SampleHelper.GetReleasesDir(); // replace with your update url
|
||||
_um = new UpdateManager(updateUrl, logger: Program.Log);
|
||||
|
||||
TextLog.Text = Program.Log.ToString();
|
||||
Program.Log.LogUpdated += LogUpdated;
|
||||
UpdateStatus();
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using Velopack;
|
||||
|
||||
namespace VeloWpfSample
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static bool WasFirstRun { get; private set; }
|
||||
|
||||
public static bool WasJustUpdated { get; private set; }
|
||||
|
||||
public static string UpdateUrl { get; private set; }
|
||||
|
||||
public static MemoryLogger Log { get; private set; }
|
||||
|
||||
// Since WPF has an "automatic" Program.Main, we need to create our own.
|
||||
// In order for this to work, you must also add the following to your .csproj:
|
||||
// <StartupObject>VeloWpfSample.Program</StartupObject>
|
||||
public class Program
|
||||
{
|
||||
public static MemoryLogger Log { get; private set; }
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
@@ -26,22 +19,14 @@ namespace VeloWpfSample
|
||||
|
||||
// It's important to Run() the VelopackApp as early as possible in app startup.
|
||||
VelopackApp.Build()
|
||||
.WithRestarted((v) => WasJustUpdated = true)
|
||||
.WithFirstRun((v) => WasFirstRun = true)
|
||||
.WithFirstRun((v) => { /* Your first run code here */ })
|
||||
.Run(Log);
|
||||
|
||||
// This is purely for demonstration purposes, we get the update URL from a
|
||||
// property defined by MSBuild, so we can locate the local releases directory.
|
||||
// In your production app, this should point to your update server.
|
||||
UpdateUrl = Assembly.GetEntryAssembly()
|
||||
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||
.Where(x => x.Key == "WpfSampleReleaseDir")
|
||||
.Single().Value;
|
||||
|
||||
// We can now launch the WPF application as normal.
|
||||
var app = new App();
|
||||
app.InitializeComponent();
|
||||
app.Run();
|
||||
|
||||
} catch (Exception ex) {
|
||||
MessageBox.Show("Unhandled exception: " + ex.ToString());
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net48</TargetFramework>
|
||||
<ImplicitUsings>true</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<NoWarn>$(NoWarn);IDE0161</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
@@ -16,15 +13,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Velopack" Version="0.*" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Used for demonstrating updates, so the installed application can find the Release directory, remove in your app -->
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
||||
<_Parameter1>WpfSampleReleaseDir</_Parameter1>
|
||||
<_Parameter2>$(MSBuildThisFileDirectory)releases</_Parameter2>
|
||||
</AssemblyAttribute>
|
||||
<!--Condition below is only needed to test this sample project against the local projects instead of the NuGet package. Remove it in your app.-->
|
||||
<PackageReference Include="Velopack" Version="0.*" Condition="$(UseLocalVelopack) == ''" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user