Skip to content

Commit 15bdd77

Browse files
Refactor publish mode logic remove unused code (#947)
* Remove diagnostic file writing from AppEnvironment Eliminate ApplicationDiagnosticPath and all file-writing logic for diagnostics. Diagnostics are now stored only in memory, and AddDiagnostics no longer supports writing to disk. Cleans up related properties and methods. * Remove unused writable options infrastructure Removed IWritableOptions<T> interface, its WritableOptions<T> implementation, and the AddWritableOptions<T> DI extension. * Remove custom MSAL webview HTML and loader class Removed MsalSystemWebViewOptions.cs and the associated auth-msalsuccess.html and auth-msalerror.html files. This eliminates the use of custom HTML pages for MSAL authentication success and error states, along with the code that loaded and provided these pages. * Remove Debug_wwwroot config and related conditionals Clean up project files by removing the Debug_wwwroot configuration and all associated conditional logic. * Remove publishmode variable from build scripts Simplified build-bravo.yaml and publish.cmd by removing the publishmode variable and related AdditionalConstants property. The publish mode is now determined solely by the --self-contained parameter, reducing redundancy and streamlining the build process.
1 parent 183f2a3 commit 15bdd77

14 files changed

Lines changed: 26 additions & 281 deletions

File tree

.azure/pipelines/build-bravo.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ strategy:
1616
bravo-x64:
1717
arch: 'x64'
1818
selfcontained: 'true'
19-
publishmode: 'SELFCONTAINED'
2019
artifact: 'Bravo.$(AppVersionMajor).$(AppVersionMinor).$(AppVersionPatch).x64'
2120
bravo-x64-frameworkdependent:
2221
arch: 'x64'
2322
selfcontained: 'false'
24-
publishmode: 'FRAMEWORKDEPENDENT'
2523
artifact: 'Bravo.$(AppVersionMajor).$(AppVersionMinor).$(AppVersionPatch).x64-frameworkdependent'
2624

2725
pool:
@@ -75,7 +73,7 @@ steps:
7573
displayName: dotnet info
7674
- script: dotnet restore "$(csproj)" --runtime "win-$(arch)" --verbosity "${{ parameters.verbosity }}"
7775
displayName: dotnet restore
78-
- script: dotnet publish "$(csproj)" --configuration "$(configuration)" --no-restore --runtime "win-$(arch)" --self-contained "$(selfcontained)" --output "$(Build.BinariesDirectory)" --verbosity "${{ parameters.verbosity }}" /p:ContinuousIntegrationBuild="true" /p:AdditionalConstants="$(publishmode)"
76+
- script: dotnet publish "$(csproj)" --configuration "$(configuration)" --no-restore --runtime "win-$(arch)" --self-contained "$(selfcontained)" --output "$(Build.BinariesDirectory)" --verbosity "${{ parameters.verbosity }}" /p:ContinuousIntegrationBuild="true"
7977
displayName: dotnet publish
8078
- script: dotnet tool install --global AzureSignTool
8179
displayName: dotnet install AzureSignTool

Bravo.sln

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bravo.Tests", "test\Bravo.T
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12-
Debug_wwwroot|Any CPU = Debug_wwwroot|Any CPU
1312
Debug|Any CPU = Debug|Any CPU
1413
Release|Any CPU = Release|Any CPU
1514
EndGlobalSection
1615
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17-
{3D49664E-E100-4EFF-A709-A59D03F4663E}.Debug_wwwroot|Any CPU.ActiveCfg = Debug_wwwroot|Any CPU
18-
{3D49664E-E100-4EFF-A709-A59D03F4663E}.Debug_wwwroot|Any CPU.Build.0 = Debug_wwwroot|Any CPU
1916
{3D49664E-E100-4EFF-A709-A59D03F4663E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2017
{3D49664E-E100-4EFF-A709-A59D03F4663E}.Debug|Any CPU.Build.0 = Debug|Any CPU
2118
{3D49664E-E100-4EFF-A709-A59D03F4663E}.Release|Any CPU.ActiveCfg = Release|Any CPU
2219
{3D49664E-E100-4EFF-A709-A59D03F4663E}.Release|Any CPU.Build.0 = Release|Any CPU
23-
{6EECEE30-9DD6-4CF4-8E0E-7773C2DED2CF}.Debug_wwwroot|Any CPU.ActiveCfg = Debug_wwwroot|Any CPU
24-
{6EECEE30-9DD6-4CF4-8E0E-7773C2DED2CF}.Debug_wwwroot|Any CPU.Build.0 = Debug_wwwroot|Any CPU
2520
{6EECEE30-9DD6-4CF4-8E0E-7773C2DED2CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2621
{6EECEE30-9DD6-4CF4-8E0E-7773C2DED2CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
2722
{6EECEE30-9DD6-4CF4-8E0E-7773C2DED2CF}.Release|Any CPU.ActiveCfg = Release|Any CPU

publish.cmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ IF %ERRORLEVEL% NEQ 0 (
1616

1717
SET arch=x64
1818
SET selfcontained=true
19-
SET publishmode=SELFCONTAINED
2019
SET configuration=Release
2120
SET version="0.0.0.999-DEV"& :: Do not change, see also <InformationalVersion> on Bravo.csproj
2221
SET verbosity="Minimal"& :: Minimal,Normal,Diagnostic,Detailed
@@ -31,7 +30,7 @@ REM ***
3130
SET publishfolder=%~dp0src\bin\_publish
3231
CD /d "%~dp0src"
3332
IF EXIST %publishfolder% RMDIR /s /q %publishfolder%
34-
dotnet publish Bravo.csproj --configuration %configuration% --output %publishfolder% --runtime win-%arch% --self-contained %selfcontained% --verbosity %verbosity% --nologo /p:AdditionalConstants=%publishmode% || GOTO :error
33+
dotnet publish Bravo.csproj --configuration %configuration% --output %publishfolder% --runtime win-%arch% --self-contained %selfcontained% --verbosity %verbosity% --nologo || GOTO :error
3534

3635
REM ***
3736
ECHO *** BRAVO INSTALLER ***

src/Bravo.csproj

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<GenerateDocumentationFile>True</GenerateDocumentationFile>
1616
<NoWarn>$(NoWarn);1591</NoWarn>
1717
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
18-
<Configurations>$(Configurations);Debug_wwwroot</Configurations>
1918
<AnalysisLevel>latest</AnalysisLevel>
2019
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
2120
<IsPackable>false</IsPackable>
@@ -31,18 +30,9 @@
3130
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
3231
</PropertyGroup>
3332

34-
<Choose>
35-
<When Condition=" '$(Configuration)' == 'Debug_wwwroot' ">
36-
<PropertyGroup>
37-
<DefineConstants>$(AdditionalConstants);DEBUG</DefineConstants>
38-
</PropertyGroup>
39-
</When>
40-
<Otherwise>
41-
<PropertyGroup>
42-
<DefineConstants>$(AdditionalConstants)</DefineConstants>
43-
</PropertyGroup>
44-
</Otherwise>
45-
</Choose>
33+
<PropertyGroup Condition="'$(SelfContained)' == 'true'">
34+
<DefineConstants>$(DefineConstants);PUBLISHMODE_SELFCONTAINED</DefineConstants>
35+
</PropertyGroup>
4636

4737
<PropertyGroup>
4838
<!-- Don't change version here -->
@@ -131,7 +121,7 @@
131121
<ClientAssetsDirectory Condition="'$(ClientAssetsDirectory)' == ''">Scripts\</ClientAssetsDirectory>
132122
<ClientAssetsRestoreInputs Condition="'$(ClientAssetsRestoreInputs)' == ''">$(ClientAssetsDirectory)package-lock.json;$(ClientAssetsDirectory)package.json</ClientAssetsRestoreInputs>
133123
<ClientAssetsRestoreOutputs Condition="'$(ClientAssetsRestoreOutputs)' == ''">$(ClientAssetsDirectory)node_modules\.package-lock.json</ClientAssetsRestoreOutputs>
134-
<ClientAssetsEnabled Condition="'$(Configuration)' != 'Debug_wwwroot'">true</ClientAssetsEnabled>
124+
<ClientAssetsEnabled>true</ClientAssetsEnabled>
135125
</PropertyGroup>
136126

137127
<ItemGroup>

src/Infrastructure/AppEnvironment.cs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ static AppEnvironment()
9292

9393
ApplicationDataPath = Path.Combine(Environment.GetFolderPath(DeploymentMode == AppDeploymentMode.Packaged ? Environment.SpecialFolder.UserProfile : Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), ApplicationName);
9494
ApplicationTempPath = Path.Combine(ApplicationDataPath, ".temp");
95-
ApplicationDiagnosticPath = Path.Combine(ApplicationDataPath, ".diagnostic");
9695
UserSettingsFilePath = Path.Combine(ApplicationDataPath, "usersettings.json");
9796
MsalTokenCacheFilePath = Path.Combine(ApplicationDataPath, ".msalcache");
9897
WebView2VersionInfo = WebView2Helper.GetRuntimeVersionInfo();
@@ -120,12 +119,10 @@ public static AppPublishMode PublishMode
120119
{
121120
get
122121
{
123-
#if SELFCONTAINED
122+
#if PUBLISHMODE_SELFCONTAINED
124123
return AppPublishMode.SelfContained;
125-
#elif FRAMEWORKDEPENDENT
126-
return AppPublishMode.FrameworkDependent;
127124
#else
128-
return AppPublishMode.None;
125+
return AppPublishMode.FrameworkDependent;
129126
#endif
130127
}
131128
}
@@ -160,8 +157,6 @@ public static RegistryKey? ApplicationInstallerRegistryHKey
160157

161158
public static string ApplicationTempPath { get; }
162159

163-
public static string ApplicationDiagnosticPath { get; }
164-
165160
public static string UserSettingsFilePath { get; }
166161

167162
public static string MsalTokenCacheFilePath { get; }
@@ -182,16 +177,11 @@ public static void AddDiagnostics(string name, Exception exception, DiagnosticMe
182177
AddDiagnostics(DiagnosticMessageType.Text, name, content, severity);
183178
}
184179

185-
public static void AddDiagnostics(DiagnosticMessageType type, string name, string content, DiagnosticMessageSeverity severity = DiagnosticMessageSeverity.None, bool writeFile = false)
180+
public static void AddDiagnostics(DiagnosticMessageType type, string name, string content, DiagnosticMessageSeverity severity = DiagnosticMessageSeverity.None)
186181
{
187182
var message = DiagnosticMessage.Create(type, severity, name, content);
188183

189184
_= Diagnostics.TryAdd(message, message);
190-
191-
if (writeFile)
192-
{
193-
WriteDiagnosticFile(message);
194-
}
195185
}
196186

197187
private static void AddEnvironmentDiagnosticInfo()
@@ -220,44 +210,13 @@ private static void AddEnvironmentDiagnosticInfo()
220210
ApplicationProductVersion,
221211
ApplicationDataPath,
222212
ApplicationTempPath,
223-
ApplicationDiagnosticPath,
224213
ApplicationUserSettingsFilePath = UserSettingsFilePath,
225214
//ApplicationFileVersionInfo = VersionInfo,
226215
};
227216

228217
AddDiagnostics(DiagnosticMessageType.Json, name: $"{nameof(AppEnvironment)}.EnvironmentInfo", content: JsonSerializer.Serialize(info));
229218
}
230219

231-
private static void WriteDiagnosticFile(DiagnosticMessage message)
232-
{
233-
if (IsDiagnosticLevelVerbose)
234-
{
235-
try
236-
{
237-
Directory.CreateDirectory(ApplicationDiagnosticPath);
238-
239-
var extension = message.Type switch
240-
{
241-
DiagnosticMessageType.Text => "txt",
242-
DiagnosticMessageType.Json => "json",
243-
_ => "bin",
244-
};
245-
246-
BravoUnexpectedException.ThrowIfNull(message.Name);
247-
248-
var name = Path.ChangeExtension(message.Name, extension);
249-
var safeName = name.ReplaceInvalidFileNameChars();
250-
var path = Path.Combine(ApplicationDiagnosticPath, safeName);
251-
252-
File.WriteAllText(path, message.Content);
253-
}
254-
catch (Exception ex)
255-
{
256-
ExceptionHelper.WriteToEventLog(ex, EventLogEntryType.Warning, throwOnError: false);
257-
}
258-
}
259-
}
260-
261220
private static AppDeploymentMode GetDeploymentMode()
262221
{
263222
if (DesktopBridgeHelper.IsRunningAsMsixPackage())
@@ -308,8 +267,18 @@ public enum AppDeploymentMode
308267

309268
public enum AppPublishMode
310269
{
311-
None = 0,
270+
/// <summary>
271+
/// Published as a framework-dependent application that relies on a shared system-wide
272+
/// version of the .NET runtime. The application will not include the .NET runtime and
273+
/// will require it to be installed on the host machine to run.
274+
/// </summary>
275+
FrameworkDependent = 0,
276+
277+
/// <summary>
278+
/// Published as a self-contained application that includes a private copy of the .NET runtime.
279+
/// The application will not rely on a shared system-wide version of the .NET runtime and
280+
/// can run on a host machine even if the .NET runtime is not installed.
281+
/// </summary>
312282
SelfContained = 1,
313-
FrameworkDependent = 2,
314283
}
315284
}

src/Infrastructure/AppWindow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ private async void InitializeWebViewAsync()
113113
/* ICoreWebView2Settings4 */ WebView2Helper.TryAndIgnoreUnsupportedError(() => WebView.CoreWebView2.Settings.IsGeneralAutofillEnabled = false);
114114
/* ICoreWebView2Settings5 */ WebView2Helper.TryAndIgnoreUnsupportedError(() => WebView.CoreWebView2.Settings.IsPinchZoomEnabled = false);
115115
/* ICoreWebView2Settings6 */ WebView2Helper.TryAndIgnoreUnsupportedError(() => WebView.CoreWebView2.Settings.IsSwipeNavigationEnabled = false);
116-
#if DEBUG_WWWROOT
117-
WebView.CoreWebView2.OpenDevToolsWindow();
116+
117+
//WebView.CoreWebView2.OpenDevToolsWindow();
118118
//WebView.CoreWebView2.OpenTaskManagerWindow();
119119
//WebView.CoreWebView2.NavigationStarting += OnWebViewNavigationStarting;
120120
//WebView.CoreWebView2.NavigationCompleted += OnWebViewNavigationCompleted;
121121
//WebView.CoreWebView2.ContentLoading += OnWebViewContentLoading;
122122
//WebView.CoreWebView2.WebMessageReceived += OnWebViewWebWebMessageReceived;
123123
//WebView.CoreWebView2.WebResourceResponseReceived += OnWebViewWebResourceResponseReceived;
124-
#endif
124+
125125
/* ICoreWebView2_2 */ WebView.CoreWebView2.DOMContentLoaded += OnWebViewDOMContentLoaded;
126126
/* ICoreWebView2 */ WebView.CoreWebView2.WebResourceRequested += OnWebViewWebResourceRequested;
127127
/* ICoreWebView2 */ WebView.CoreWebView2.PermissionRequested += OnWebViewPermissionRequested;

src/Infrastructure/Authentication/MsalSystemWebViewOptions.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Infrastructure/Configuration/Options/IWritableOptions.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Infrastructure/Configuration/Options/WritableOptions.cs

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/Infrastructure/Configuration/StartupConfiguration.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ private static void ConfigureProxy()
3434

3535
private static void ConfigureDirectories()
3636
{
37-
#if !DEBUG_WWWROOT
38-
Directory.SetCurrentDirectory(System.AppContext.BaseDirectory);
39-
#endif
37+
Directory.SetCurrentDirectory(AppContext.BaseDirectory);
4038
Directory.CreateDirectory(AppEnvironment.ApplicationDataPath);
4139
Directory.CreateDirectory(AppEnvironment.ApplicationTempPath);
4240
}

0 commit comments

Comments
 (0)