From 638ea657cc9b98d4608439f2d7df012973e76071 Mon Sep 17 00:00:00 2001 From: Pablo Monteiro Date: Mon, 20 May 2024 23:53:58 -0300 Subject: [PATCH] feat: adding alternative for single file publish --- README.md | 13 ++++++++++++ .../Environment/EnvironmentVariables.cs | 1 + src/Buildalyzer/ProjectAnalyzer.cs | 20 ++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 50203fa3..1e976205 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,19 @@ If you want to change the configured properties before loading or compiling the Be careful though, you may break the ability to load, compile, or interpret the project if you change the MSBuild properties. + +## Publish SingleFile +If your application's output is a single file, you will need to provide the path to the following DLLs: + +-MsBuildPipeLogger.Logger.dll +-Buildalyzer.logger.dll + +Variable name: LoggerPathDll + +See related issue [224](https://github.com/phmonte/Buildalyzer/issues/224) +msbuild needs the physical address of the logger, for this reason it is not possible to use single file publish without informing this route. + +Remembering that if the files are in the root where the project is running, it is not necessary to inform the path. ## Binary Log Files Buildalyzer can also read [MSBuild binary log files](http://msbuildlog.com/): diff --git a/src/Buildalyzer/Environment/EnvironmentVariables.cs b/src/Buildalyzer/Environment/EnvironmentVariables.cs index 69955989..67bae3fd 100644 --- a/src/Buildalyzer/Environment/EnvironmentVariables.cs +++ b/src/Buildalyzer/Environment/EnvironmentVariables.cs @@ -14,4 +14,5 @@ public static class EnvironmentVariables public const string MSBUILDDISABLENODEREUSE = nameof(MSBUILDDISABLENODEREUSE); public const string MSBuildExtensionsPath = nameof(MSBuildExtensionsPath); public const string MSBuildSDKsPath = nameof(MSBuildSDKsPath); + public const string LoggerPathDll = nameof(LoggerPathDll); } \ No newline at end of file diff --git a/src/Buildalyzer/ProjectAnalyzer.cs b/src/Buildalyzer/ProjectAnalyzer.cs index 776daaca..7cfa405e 100644 --- a/src/Buildalyzer/ProjectAnalyzer.cs +++ b/src/Buildalyzer/ProjectAnalyzer.cs @@ -279,7 +279,8 @@ private string GetCommand( } // Get the logger arguments (/l) - string loggerPath = typeof(BuildalyzerLogger).Assembly.Location; + string loggerPath = GetLoggerPath(); + bool logEverything = _buildLoggers.Count > 0; string loggerArgStart = "/l"; // in case of MSBuild.exe use slash as parameter prefix for logger if (isDotNet) @@ -312,6 +313,23 @@ private string GetCommand( return fileName; } + private static string GetLoggerPath() + { + string loggerPath = typeof(BuildalyzerLogger).Assembly.Location; + if (!string.IsNullOrEmpty(loggerPath)) + { + return loggerPath; + } + + string? loggerDllPathEnv = System.Environment.GetEnvironmentVariable(Environment.EnvironmentVariables.LoggerPathDll); + if (string.IsNullOrEmpty(loggerDllPathEnv)) + { + throw new ArgumentException($"The dll of {nameof(BuildalyzerLogger)} is required"); + } + + return loggerDllPathEnv; + } + private static string FormatArgument(string argument) { // Escape inner quotes