diff --git a/CHANGELOG.md b/CHANGELOG.md index b570625..bc88eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- When using `check-deps`, do not throw exceptions that occur before the DotNetConsoleBuilder is built + ## [5.0.0] - 2025-01-27 ### Added diff --git a/Neolution.DotNet.Console/DotNetConsoleBuilder.cs b/Neolution.DotNet.Console/DotNetConsoleBuilder.cs index 442f4d0..ceea7b7 100644 --- a/Neolution.DotNet.Console/DotNetConsoleBuilder.cs +++ b/Neolution.DotNet.Console/DotNetConsoleBuilder.cs @@ -135,14 +135,22 @@ internal static DotNetConsoleBuilder CreateBuilderInternal(Assembly assembly, Ty .ToArray(); var parsedArguments = Parser.Default.ParseArguments(args, verbTypes); - var consoleBuilder = new DotNetConsoleBuilder(builder, parsedArguments, environment, configuration); - if (args.Length == 1 && string.Equals(args[0], "check-deps", StringComparison.OrdinalIgnoreCase)) { - consoleBuilder.checkDependencies = true; - return consoleBuilder; + try + { + return new DotNetConsoleBuilder(builder, parsedArguments, environment, configuration) + { + checkDependencies = true, + }; + } + catch (Exception) + { + // Only check service dependencies, which happens when the builder is built. All other exceptions are ignored. + } } + var consoleBuilder = new DotNetConsoleBuilder(builder, parsedArguments, environment, configuration); CheckStrictVerbMatching(args, verbTypes); return consoleBuilder; }