From 5cc71059faa629175aee04faf6cf83056c37367b Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Thu, 1 Jun 2023 15:20:56 +0100 Subject: [PATCH] Allow running as windows service --- .github/workflows/createrelease.yml | 9 ++------- .github/workflows/nightlybuild.yml | 5 ----- .github/workflows/pullrequest.yml | 5 ----- .github/workflows/pushtomaster.yml | 5 ----- MessagingService/MessagingService.csproj | 2 ++ MessagingService/Program.cs | 9 +++++---- 6 files changed, 9 insertions(+), 26 deletions(-) diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml index 4e93cc2..1a136ac 100644 --- a/.github/workflows/createrelease.yml +++ b/.github/workflows/createrelease.yml @@ -14,12 +14,7 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - - - name: Install NET 7 - uses: actions/setup-dotnet@v2 - with: - dotnet-version: '7.0.x' - + - name: Get the version id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} @@ -53,7 +48,7 @@ jobs: - name: Publish API if: ${{ github.event.release.prerelease == false }} - run: dotnet publish "MessagingService\MessagingService.csproj" --configuration Release --output publishOutput + run: dotnet publish "MessagingService\MessagingService.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 a5a3e40..b322c22 100644 --- a/.github/workflows/nightlybuild.yml +++ b/.github/workflows/nightlybuild.yml @@ -41,11 +41,6 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - - - name: Install NET 7 - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '7.0.101' - name: Set Up Variables run: echo "action_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index a918d22..1ff87c4 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 MessagingService.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 3c41302..4ded98c 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 MessagingService.sln --source https://api.nuget.org/v3/index.json --source https://www.myget.org/F/transactionprocessing/api/v3/index.json diff --git a/MessagingService/MessagingService.csproj b/MessagingService/MessagingService.csproj index 05ba295..7bb8aa8 100644 --- a/MessagingService/MessagingService.csproj +++ b/MessagingService/MessagingService.csproj @@ -16,6 +16,7 @@ + @@ -27,6 +28,7 @@ + diff --git a/MessagingService/Program.cs b/MessagingService/Program.cs index 059c6e7..9d63297 100644 --- a/MessagingService/Program.cs +++ b/MessagingService/Program.cs @@ -20,15 +20,16 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) { - Console.Title = "Messaging Service"; - //At this stage, we only need our hosting file for ip and ports - IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("hosting.json", optional: true) + FileInfo fi = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); + + IConfigurationRoot config = new ConfigurationBuilder().SetBasePath(fi.Directory.FullName) + .AddJsonFile("hosting.json", optional: false) .AddJsonFile("hosting.development.json", optional: true) .AddEnvironmentVariables().Build(); IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args); + hostBuilder.UseWindowsService(); hostBuilder.UseLamar(); hostBuilder.ConfigureLogging(logging => {