Dzidek.Net.AutoUpgrade.Upgrader
1.0.5
dotnet add package Dzidek.Net.AutoUpgrade.Upgrader --version 1.0.5
NuGet\Install-Package Dzidek.Net.AutoUpgrade.Upgrader -Version 1.0.5
<PackageReference Include="Dzidek.Net.AutoUpgrade.Upgrader" Version="1.0.5" />
paket add Dzidek.Net.AutoUpgrade.Upgrader --version 1.0.5
#r "nuget: Dzidek.Net.AutoUpgrade.Upgrader, 1.0.5"
// Install Dzidek.Net.AutoUpgrade.Upgrader as a Cake Addin #addin nuget:?package=Dzidek.Net.AutoUpgrade.Upgrader&version=1.0.5 // Install Dzidek.Net.AutoUpgrade.Upgrader as a Cake Tool #tool nuget:?package=Dzidek.Net.AutoUpgrade.Upgrader&version=1.0.5
Windows service with auto upgrade feature
An auto-updating Windows service with the ability to send a new compressed version on demand
Packages (Dzidek.Net.AutoUpgrade.Service and Dzidek.Net.AutoUpgrade.Upgrader) allow us to implement a service with an automatic update on demand if part of our application is installed outside our servers where we do not have administrator rights or even log in
How it works
AutoUpgrade has two services (one with the ".Service" suffix and the other with the ".Upgrader" suffix). The "Service" is responsible for downloading and saving new versions in the directory. The directory where new versions are saved is watched by "Upgrader" and if a new file has been created, it stops "Service", copies new files and starts "Service".
You can control it from the outside when an update happens because it happens when you save a new version and you decide when you give a new version
Basic usage
Service
In appSettings.json:
{
"AutoUpgrade": {
"ServiceName": "AutoUpgrade"
}
}
In program.cs:
builder.Host
.UseAutoUpgradeService(builder.Configuration.GetSection("AutoUpgrade").Get<AutoUpgradeServiceConfiguration>()!);
Remember to set content root path for your windows service
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
});
Below is an example of how to use it through the API over HTTP/HTTPS. You can use it as you want
app.MapGet("/",
(IAutoUpgradeService autoUpgradeService) => $"Hello World from service '{autoUpgradeService.GetVersion()}'!");
app.MapPost("/", (IFormFile file, IAutoUpgradeService autoUpgradeService) =>
{
using var fileStream = new MemoryStream();
file.CopyTo(fileStream);
return autoUpgradeService.Upgrade(fileStream.ToArray(), file.FileName);
});
Configuration
- ServiceName - service name - should be the same in "Service" and "Updater", both add suffixes to distinguish the two services
- NewVersionDirectoryName - name of the directory where new versions will be saved. This directory will be watched by the Upgrader. This directory will be placed in the service directory
- Default value: NewVersion
- ServiceNameSuffix - service suffix name
- Default value: Service
- Example: In the example above, the service name will be "AutoUpgrade.Service"
Upgrader
In appSettings.json:
{
"AutoUpgrade": {
"ServiceName": "AutoUpgrade",
"ServicePath": "[The required path to the directory where the exe file is located]"
}
}
In program.cs:
builder.Host
.UseAutoUpgradeUpgrader(builder.Configuration.GetSection("AutoUpgrade").Get<AutoUpgradeUpgraderConfiguration>()!);
Remember to set content root path for your windows service
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
});
Configuration
- ServiceName - service name - should be the same in "Service" and "Updater", both add suffixes to distinguish the two services
- ServicePath - the required path to the directory where the exe file is located
- ServiceNameSuffix - service suffix name
- Default value: Service
- Example: In the example above, the service name will be "AutoUpgrade.Service"
- UpgraderNameSuffix - upgrader suffix name
- Default value: Upgrader
- Example: In the example above, the service name will be "AutoUpgrade.Upgrader"
- ServiceOldVersionsPath - if set, before upgrade current version will be zipped and copied to the directory
Create service in windows
You should call with admin rights. You should first create Service because Upgrader automatically starts Service
sc.exe create "AutoUpgrade.Service" binpath="[PATH]\AutoUpgrade.Service.exe" start=auto
sc.exe create "AutoUpgrade.Upgrader" binpath="[PATH]\AutoUpgrade.Upgrader.exe" start=delayed-auto
Working example
The working example is available in the GitHub repository AutoUpgrade.
For testing purposes, you need to build projects and install windows services. You can then send the new version of the service via HTTP to http://localhost:9000. You can use swagger to do this at http://localhost:9000/swagger
Changelog
- 1.0.5
- Prevent start service when package exists to upgrade
- 1.0.4
- Possibility to zip and keep old versions by setting ServiceOldVersionsPath props in upgrader
- 1.0.3
- Unzipping files with subdirectories
- 1.0.2
- Removed unnecessary dependencies
- 1.0.1
- DotNet6 Fix
- 1.0.0
- First version
Nuget packages
Service
Dzidek.Net.AutoUpgrade.Service
Upgrader
Dzidek.Net.AutoUpgrade.Upgrader
Common
Authors
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Dzidek.Net.AutoUpgrade.Common (>= 1.0.5)
- System.Management (>= 7.0.1)
-
net7.0
- Dzidek.Net.AutoUpgrade.Common (>= 1.0.5)
- System.Management (>= 7.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.5 | 3,229 | 4/16/2023 | |
1.0.5-alpha4 | 147 | 4/16/2023 | |
1.0.5-alpha2 | 115 | 4/16/2023 | |
1.0.5-alpha1 | 136 | 4/16/2023 | |
1.0.4 | 1,547 | 1/26/2023 | |
1.0.3 | 284 | 1/26/2023 | |
1.0.3-dev-1 | 147 | 1/26/2023 | |
1.0.3-dev | 141 | 1/26/2023 | |
1.0.2 | 294 | 1/24/2023 | |
1.0.1 | 265 | 1/24/2023 | |
1.0.0 | 297 | 1/24/2023 |