Skip to content
This repository has been archived by the owner on Dec 26, 2020. It is now read-only.

Commit

Permalink
Fix issue with single-file-publish not being able to find appsettings…
Browse files Browse the repository at this point in the history
….json
  • Loading branch information
Oceanswave committed Sep 12, 2020
1 parent 1031175 commit 2114650
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CreateFSMosquitoClientRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

# Build FSMosquitoClient
- name: Build the application
run: dotnet publish $env:Project_Path --configuration Release --runtime win10-x64 /p:Platform=x64 /p:DeployOnBuild=true /p:PublishReadyToRun=true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:PublishProfile="Create FSMosquitoClient Release"
run: dotnet publish $env:Project_Path --configuration Release --runtime win10-x64 /p:Platform=x64 /p:DeployOnBuild=true /p:PublishReadyToRun=true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:DebugType=None /p:PublishProfile="Create FSMosquitoClient Release"

# Run WarpPacker on the built files
# This is commented right now as warp packer opens a console window prior to opening the application - unclear how to prevent this.
Expand Down
38 changes: 26 additions & 12 deletions FSMosquitoClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<ItemGroup>
<None Remove="appsettings.json" />
<None Remove="mosquito.jpg" />
</ItemGroup>

<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.8" />
Expand Down Expand Up @@ -55,16 +43,42 @@
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
<None Include="appsettings.dev.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<DependentUpon>appsettings.json</DependentUpon>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
<None Update="lib\SimConnect.dll">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</None>
</ItemGroup>

<ItemGroup>
<FluentValidationExcludedCultures Include="be;cs;cs-CZ;da;de;es;fa;fi;fr;ja;it;ko;mk;nl;pl;pt;pt-br;ru;sv;tr;uk;zh-CN;zh-CHS;zh-CHT;zh-Hans;zh-Hant;">
<InProject>false</InProject>
</FluentValidationExcludedCultures>
</ItemGroup>

<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles="lib\SimConnect.dll" DestinationFolder="$(OutDir)" />
</Target>

<Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
<Copy SourceFiles="lib\SimConnect.dll" DestinationFolder="$(PublishDir)" />
</Target>

<Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild">
<RemoveDir Directories="@(FluentValidationExcludedCultures->'$(OutDir)%(Filename)')" />
</Target>

<Target Name="RemoveTranslationsOnPublish" AfterTargets="Publish">
<RemoveDir Directories="@(FluentValidationExcludedCultures->'$(PublishDir)%(Filename)')" />
<Delete Files="$(PublishDir)appsettings.dev.json" />
</Target>
</Project>
15 changes: 13 additions & 2 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -71,7 +72,11 @@ static void Main(string[] args)
// Stand up DI
var services = new ServiceCollection();
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.SetBasePath(GetBasePath())
.AddJsonFile("appsettings.json", false)
#if DEBUG
.AddJsonFile("appsettings.dev.json", false)
#endif
.AddEnvironmentVariables();
var configuration = builder.Build();
var startup = new Startup(configuration);
Expand Down Expand Up @@ -106,7 +111,7 @@ static void Main(string[] args)
}
}

static void GlobalExceptionHandler(object sender, UnhandledExceptionEventArgs e)
private static void GlobalExceptionHandler(object sender, UnhandledExceptionEventArgs e)
{
if (_logger != null)
{
Expand All @@ -118,5 +123,11 @@ static void GlobalExceptionHandler(object sender, UnhandledExceptionEventArgs e)
Console.ReadLine();
Environment.Exit(1);
}

private static string GetBasePath()
{
using var processModule = Process.GetCurrentProcess().MainModule;
return Path.GetDirectoryName(processModule?.FileName);
}
}
}
3 changes: 3 additions & 0 deletions appsettings.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fs_mosquito_serverurl": "wss://dev.fsmosquito.com/mqtt/ws"
}
2 changes: 1 addition & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"fs_mosquito_serverurl": "wss://localhost:8443/mqtt/ws",
"fs_mosquito_serverurl": "wss://www.fsmosquito.com/mqtt/ws",
"fs_mosquito_clientid": "some_pilot",
"fs_mosquito_username": "guest",
"fs_mosquito_password": "guest"
Expand Down

0 comments on commit 2114650

Please sign in to comment.