From 6b2508e3a1cfb172f2519f51eb751271aa369524 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Thu, 1 Jun 2023 21:42:31 +0100 Subject: [PATCH] Run as win service --- .github/workflows/createrelease.yml | 9 ++------- .github/workflows/nightlybuild.yml | 5 ----- .github/workflows/pullrequest.yml | 5 ----- .github/workflows/pushtomaster.yml | 5 ----- TransactionProcessor/Program.cs | 7 ++++--- TransactionProcessor/TransactionProcessor.csproj | 1 + 6 files changed, 7 insertions(+), 25 deletions(-) diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml index 5f40e1ae..eced1293 100644 --- a/.github/workflows/createrelease.yml +++ b/.github/workflows/createrelease.yml @@ -18,12 +18,7 @@ jobs: - name: Get the version id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} - - - name: Install NET 7 - uses: actions/setup-dotnet@v2 - with: - dotnet-version: '7.0.x' - + - name: Restore Nuget Packages run: dotnet restore TransactionProcessor.sln --source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/transactionprocessing/api/v3/index.json @@ -57,7 +52,7 @@ jobs: - name: Publish API if: ${{ github.event.release.prerelease == false }} - run: dotnet publish "TransactionProcessor\TransactionProcessor.csproj" --configuration Release --output publishOutput + run: dotnet publish "TransactionProcessor\TransactionProcessor.csproj" --configuration Release --output publishOutput -r win-x64 --self-contained - name: Install Octopus CLI if: ${{ github.event.release.prerelease == false }} diff --git a/.github/workflows/nightlybuild.yml b/.github/workflows/nightlybuild.yml index 3d836fed..0905458a 100644 --- a/.github/workflows/nightlybuild.yml +++ b/.github/workflows/nightlybuild.yml @@ -44,11 +44,6 @@ jobs: - name: Set Up Variables run: echo "action_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV - - name: Install NET 7 - uses: actions/setup-dotnet@v2 - with: - dotnet-version: '7.0.101' - - name: Restore Nuget Packages run: dotnet restore TransactionProcessor.sln --source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/transactionprocessing/api/v3/index.json diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 2aedb691..8936c7c8 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -16,11 +16,6 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - - name: Install NET 7 - uses: actions/setup-dotnet@v2 - with: - dotnet-version: '7.0.x' - - name: Restore Nuget Packages run: dotnet restore TransactionProcessor.sln --source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/transactionprocessing/api/v3/index.json diff --git a/.github/workflows/pushtomaster.yml b/.github/workflows/pushtomaster.yml index db456227..d344e82c 100644 --- a/.github/workflows/pushtomaster.yml +++ b/.github/workflows/pushtomaster.yml @@ -19,11 +19,6 @@ jobs: with: fetch-depth: 0 - - name: Install NET 7 - uses: actions/setup-dotnet@v2 - with: - dotnet-version: '7.0.x' - - name: Restore Nuget Packages run: dotnet restore TransactionProcessor.sln --source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/transactionprocessing/api/v3/index.json diff --git a/TransactionProcessor/Program.cs b/TransactionProcessor/Program.cs index 52a0ec7c..3a0fd524 100644 --- a/TransactionProcessor/Program.cs +++ b/TransactionProcessor/Program.cs @@ -32,15 +32,16 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) { - Console.Title = "Transaction Processor"; - //At this stage, we only need our hosting file for ip and ports - IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) + FileInfo fi = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); + + IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(fi.Directory.FullName) .AddJsonFile("hosting.json", optional: true) .AddJsonFile("hosting.development.json", optional: true) .AddEnvironmentVariables().Build(); IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args); + hostBuilder.UseWindowsService(); hostBuilder.UseLamar(); hostBuilder.ConfigureWebHostDefaults(webBuilder => { diff --git a/TransactionProcessor/TransactionProcessor.csproj b/TransactionProcessor/TransactionProcessor.csproj index 9f9e2e69..7adca1a9 100644 --- a/TransactionProcessor/TransactionProcessor.csproj +++ b/TransactionProcessor/TransactionProcessor.csproj @@ -43,6 +43,7 @@ +