Skip to content

Commit cd37824

Browse files
Merge pull request #143 from TransactionProcessing/task/#141_runaswindowsservice
Allow running as windows service
2 parents 88d273c + 5cc7105 commit cd37824

File tree

6 files changed

+9
-26
lines changed

6 files changed

+9
-26
lines changed

.github/workflows/createrelease.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ jobs:
1414

1515
steps:
1616
- uses: actions/[email protected]
17-
18-
- name: Install NET 7
19-
uses: actions/setup-dotnet@v2
20-
with:
21-
dotnet-version: '7.0.x'
22-
17+
2318
- name: Get the version
2419
id: get_version
2520
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
@@ -53,7 +48,7 @@ jobs:
5348
5449
- name: Publish API
5550
if: ${{ github.event.release.prerelease == false }}
56-
run: dotnet publish "MessagingService\MessagingService.csproj" --configuration Release --output publishOutput
51+
run: dotnet publish "MessagingService\MessagingService.csproj" --configuration Release --output publishOutput -r win-x64 --self-contained
5752

5853
- name: Install Octopus CLI
5954
if: ${{ github.event.release.prerelease == false }}

.github/workflows/nightlybuild.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ jobs:
4141

4242
steps:
4343
- uses: actions/[email protected]
44-
45-
- name: Install NET 7
46-
uses: actions/setup-dotnet@v3
47-
with:
48-
dotnet-version: '7.0.101'
4944

5045
- name: Set Up Variables
5146
run: echo "action_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV

.github/workflows/pullrequest.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ jobs:
1616
steps:
1717
- uses: actions/[email protected]
1818

19-
- name: Install NET 7
20-
uses: actions/setup-dotnet@v2
21-
with:
22-
dotnet-version: '7.0.x'
23-
2419
- name: Restore Nuget Packages
2520
run: dotnet restore MessagingService.sln --source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/transactionprocessing/api/v3/index.json
2621

.github/workflows/pushtomaster.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ jobs:
1919
with:
2020
fetch-depth: 0
2121

22-
- name: Install NET 7
23-
uses: actions/setup-dotnet@v2
24-
with:
25-
dotnet-version: '7.0.x'
26-
2722
- name: Restore Nuget Packages
2823
run: dotnet restore MessagingService.sln --source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/transactionprocessing/api/v3/index.json
2924

MessagingService/MessagingService.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
1717
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0" />
1818
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
1920
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
2021
<PackageReference Include="Shared" Version="2023.1.0" />
2122
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
@@ -27,6 +28,7 @@
2728
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.4.0" />
2829
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.4.0" />
2930
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.4.0" />
31+
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="7.0.0" />
3032
</ItemGroup>
3133

3234
<ItemGroup>

MessagingService/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ public static void Main(string[] args)
2020

2121
public static IHostBuilder CreateHostBuilder(string[] args)
2222
{
23-
Console.Title = "Messaging Service";
24-
2523
//At this stage, we only need our hosting file for ip and ports
26-
IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
27-
.AddJsonFile("hosting.json", optional: true)
24+
FileInfo fi = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
25+
26+
IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(fi.Directory.FullName)
27+
.AddJsonFile("hosting.json", optional: false)
2828
.AddJsonFile("hosting.development.json", optional: true)
2929
.AddEnvironmentVariables().Build();
3030

3131
IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args);
32+
hostBuilder.UseWindowsService();
3233
hostBuilder.UseLamar();
3334
hostBuilder.ConfigureLogging(logging =>
3435
{

0 commit comments

Comments
 (0)