diff --git a/Velopack.sln b/Velopack.sln index 5bb0dff0..f1558f2c 100644 --- a/Velopack.sln +++ b/Velopack.sln @@ -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}" diff --git a/samples/AvaloniaCrossPlat/AvaloniaCrossPlat.csproj b/samples/AvaloniaCrossPlat/AvaloniaCrossPlat.csproj index cde569b6..c6c06b59 100644 --- a/samples/AvaloniaCrossPlat/AvaloniaCrossPlat.csproj +++ b/samples/AvaloniaCrossPlat/AvaloniaCrossPlat.csproj @@ -6,7 +6,6 @@ true app.manifest true - $(NoWarn);IDE0161 @@ -14,32 +13,13 @@ - + - - - - - - - - - - - - - - - - - <_Parameter1>AvaloniaSampleReleaseDir - <_Parameter2>$(MSBuildThisFileDirectory)releases - + + - - diff --git a/samples/AvaloniaCrossPlat/MainWindow.axaml.cs b/samples/AvaloniaCrossPlat/MainWindow.axaml.cs index 9a9b1e60..ca1fd652 100644 --- a/samples/AvaloniaCrossPlat/MainWindow.axaml.cs +++ b/samples/AvaloniaCrossPlat/MainWindow.axaml.cs @@ -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(); diff --git a/samples/AvaloniaCrossPlat/Program.cs b/samples/AvaloniaCrossPlat/Program.cs index b80cee3a..da948be3 100644 --- a/samples/AvaloniaCrossPlat/Program.cs +++ b/samples/AvaloniaCrossPlat/Program.cs @@ -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() - .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); diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props deleted file mode 100644 index 7b09f03f..00000000 --- a/samples/Directory.Build.props +++ /dev/null @@ -1,9 +0,0 @@ - - - - https://api.nuget.org/v3/index.json;$(RestoreSources) - - $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\build\$(Configuration)'));$(RestoreSources) - - - diff --git a/samples/Directory.Build.targets b/samples/Directory.Build.targets new file mode 100644 index 00000000..f5ef83c6 --- /dev/null +++ b/samples/Directory.Build.targets @@ -0,0 +1,32 @@ + + + + + $(NoWarn);IDE0161 + true + latest + + + + + <_Parameter1>VelopackSampleReleaseDir + <_Parameter2>$(MSBuildThisFileDirectory)$(ProjectName)/releases + + + + + + + + + https://api.nuget.org/v3/index.json;$(RestoreSources) + + $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\build\$(Configuration)'));$(RestoreSources) + + + + + + + + diff --git a/samples/SampleHelper.cs b/samples/SampleHelper.cs new file mode 100644 index 00000000..da7d401b --- /dev/null +++ b/samples/SampleHelper.cs @@ -0,0 +1,10 @@ +using System.Linq; +using System.Reflection; + +internal static class SampleHelper +{ + public static string GetReleasesDir() => Assembly.GetEntryAssembly() + .GetCustomAttributes() + .Where(x => x.Key == "VelopackSampleReleaseDir") + .Single().Value; +} \ No newline at end of file diff --git a/samples/VeloWpfSample/MainWindow.xaml.cs b/samples/VeloWpfSample/MainWindow.xaml.cs index 9d2222a0..fda6dd08 100644 --- a/samples/VeloWpfSample/MainWindow.xaml.cs +++ b/samples/VeloWpfSample/MainWindow.xaml.cs @@ -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(); diff --git a/samples/VeloWpfSample/Program.cs b/samples/VeloWpfSample/Program.cs index 7b4644da..30ee14a6 100644 --- a/samples/VeloWpfSample/Program.cs +++ b/samples/VeloWpfSample/Program.cs @@ -1,22 +1,15 @@ -using System.Reflection; -using System.Windows; +using System.Windows; using Velopack; namespace VeloWpfSample { + // 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: + // VeloWpfSample.Program 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: - // VeloWpfSample.Program [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() - .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()); } diff --git a/samples/VeloWpfSample/VeloWpfSample.csproj b/samples/VeloWpfSample/VeloWpfSample.csproj index aae60bfd..5e6eba8d 100644 --- a/samples/VeloWpfSample/VeloWpfSample.csproj +++ b/samples/VeloWpfSample/VeloWpfSample.csproj @@ -1,13 +1,10 @@ - + WinExe net48 true true - true - latest - $(NoWarn);IDE0161 @@ -16,15 +13,8 @@ - - - - - - - <_Parameter1>WpfSampleReleaseDir - <_Parameter2>$(MSBuildThisFileDirectory)releases - + +