diff --git a/src/Shared/CertificateGeneration/CertificateManager.cs b/src/Shared/CertificateGeneration/CertificateManager.cs index 96e5630c43f1..491eb5adb974 100644 --- a/src/Shared/CertificateGeneration/CertificateManager.cs +++ b/src/Shared/CertificateGeneration/CertificateManager.cs @@ -328,6 +328,7 @@ public EnsureCertificateResult EnsureAspNetCoreHttpsDevelopmentCertificate( var exportDir = Path.GetDirectoryName(path); if (!string.IsNullOrEmpty(exportDir) && !Directory.Exists(exportDir)) { + result = EnsureCertificateResult.ErrorExportingTheCertificateToNonExistentDirectory; throw new InvalidOperationException($"The directory '{exportDir}' does not exist. Choose permissions carefully when creating it."); } diff --git a/src/Shared/CertificateGeneration/EnsureCertificateResult.cs b/src/Shared/CertificateGeneration/EnsureCertificateResult.cs index cb6b7e145428..5c28eaca3063 100644 --- a/src/Shared/CertificateGeneration/EnsureCertificateResult.cs +++ b/src/Shared/CertificateGeneration/EnsureCertificateResult.cs @@ -10,6 +10,7 @@ internal enum EnsureCertificateResult ErrorCreatingTheCertificate, ErrorSavingTheCertificateIntoTheCurrentUserPersonalStore, ErrorExportingTheCertificate, + ErrorExportingTheCertificateToNonExistentDirectory, FailedToTrustTheCertificate, PartiallyFailedToTrustTheCertificate, UserCancelledTrustStep, diff --git a/src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs b/src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs index 09a32825e50e..bcc2d6ef05b5 100644 --- a/src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs +++ b/src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs @@ -373,7 +373,7 @@ public void EnsureCreateHttpsCertificate_CannotExportToNonExistentDirectory() .EnsureAspNetCoreHttpsDevelopmentCertificate(now, now.AddYears(1), Path.Combine("NoSuchDirectory", CertificateName)); // Assert - Assert.Equal(EnsureCertificateResult.ErrorExportingTheCertificate, result); + Assert.Equal(EnsureCertificateResult.ErrorExportingTheCertificateToNonExistentDirectory, result); } [Fact] diff --git a/src/Tools/dotnet-dev-certs/src/Program.cs b/src/Tools/dotnet-dev-certs/src/Program.cs index 9f5407d9d3e4..9b195dbcd9fa 100644 --- a/src/Tools/dotnet-dev-certs/src/Program.cs +++ b/src/Tools/dotnet-dev-certs/src/Program.cs @@ -425,6 +425,10 @@ private static int EnsureHttpsCertificate(CommandOption exportPath, CommandOptio case EnsureCertificateResult.ErrorExportingTheCertificate: reporter.Warn("There was an error exporting the HTTPS developer certificate to a file."); return ErrorExportingTheCertificate; + case EnsureCertificateResult.ErrorExportingTheCertificateToNonExistentDirectory: + // A distinct warning is useful, but a distinct error code is probably not. + reporter.Warn("There was an error exporting the HTTPS developer certificate to a file. Please create the target directory before exporting. Choose permissions carefully when creating it."); + return ErrorExportingTheCertificate; case EnsureCertificateResult.PartiallyFailedToTrustTheCertificate: // A distinct warning is useful, but a distinct error code is probably not. reporter.Warn("There was an error trusting the HTTPS developer certificate. It will be trusted by some clients but not by others.");