diff --git a/src/Microsoft.Extensions.SecretManager.Tools/Program.cs b/src/Microsoft.Extensions.SecretManager.Tools/Program.cs
index 0da29bd..b8d3e9f 100644
--- a/src/Microsoft.Extensions.SecretManager.Tools/Program.cs
+++ b/src/Microsoft.Extensions.SecretManager.Tools/Program.cs
@@ -151,6 +151,11 @@ namespace Microsoft.Extensions.SecretManager.Tools
var fileInfo = new PhysicalFileInfo(new FileInfo(projectPath));
+ if (!fileInfo.Exists)
+ {
+ throw new GracefulException(Resources.FormatError_ProjectPath_NotFound(projectPath));
+ }
+
Logger.LogDebug(Resources.Message_Project_File_Path, fileInfo.PhysicalPath);
return ReadUserSecretsId(fileInfo);
}
diff --git a/src/Microsoft.Extensions.SecretManager.Tools/Properties/Resources.Designer.cs b/src/Microsoft.Extensions.SecretManager.Tools/Properties/Resources.Designer.cs
index c79e6e1..d9ae9fe 100644
--- a/src/Microsoft.Extensions.SecretManager.Tools/Properties/Resources.Designer.cs
+++ b/src/Microsoft.Extensions.SecretManager.Tools/Properties/Resources.Designer.cs
@@ -58,6 +58,22 @@ namespace Microsoft.Extensions.SecretManager.Tools
return GetString("Error_No_Secrets_Found");
}
+ ///
+ /// The project file '{path}' does not exist.
+ ///
+ internal static string Error_ProjectPath_NotFound
+ {
+ get { return GetString("Error_ProjectPath_NotFound"); }
+ }
+
+ ///
+ /// The project file '{path}' does not exist.
+ ///
+ internal static string FormatError_ProjectPath_NotFound(object path)
+ {
+ return string.Format(CultureInfo.CurrentCulture, GetString("Error_ProjectPath_NotFound", "path"), path);
+ }
+
///
/// Project file path {project}.
///
diff --git a/src/Microsoft.Extensions.SecretManager.Tools/Resources.resx b/src/Microsoft.Extensions.SecretManager.Tools/Resources.resx
index 13c953c..76631de 100644
--- a/src/Microsoft.Extensions.SecretManager.Tools/Resources.resx
+++ b/src/Microsoft.Extensions.SecretManager.Tools/Resources.resx
@@ -126,6 +126,9 @@
No secrets configured for this application.
+
+ The project file '{path}' does not exist.
+
Project file path {project}.
diff --git a/test/Microsoft.Extensions.SecretManager.Tools.Tests/SecretManagerTests.cs b/test/Microsoft.Extensions.SecretManager.Tools.Tests/SecretManagerTests.cs
index 4618b5a..038bb0d 100644
--- a/test/Microsoft.Extensions.SecretManager.Tools.Tests/SecretManagerTests.cs
+++ b/test/Microsoft.Extensions.SecretManager.Tools.Tests/SecretManagerTests.cs
@@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration.UserSecrets.Tests;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
+using Microsoft.Extensions.SecretManager.Tools.Internal;
namespace Microsoft.Extensions.SecretManager.Tools.Tests
{
@@ -22,6 +23,17 @@ namespace Microsoft.Extensions.SecretManager.Tools.Tests
_logger = new TestLogger(output);
}
+ [Fact]
+ public void Error_Project_DoesNotExist()
+ {
+ var projectPath = Path.Combine(Path.GetTempPath(), "dne", Guid.NewGuid().ToString(), "project.json");
+ var secretManager = new Program(Console.Out, Directory.GetCurrentDirectory()) { Logger = _logger };
+
+ var ex = Assert.Throws(() => secretManager.RunInternal("list", "--project", projectPath));
+
+ Assert.Equal(ex.Message, Resources.FormatError_ProjectPath_NotFound(projectPath));
+ }
+
[Theory]
[InlineData(true)]
[InlineData(false)]