Adding a try/catch around Path.GetTempFileName() to improve UX

This commit is contained in:
Ankit Mishra 2017-08-01 15:55:21 -07:00
parent fdedfe93b1
commit b29ee4d41a
2 changed files with 12 additions and 2 deletions

View file

@ -162,4 +162,7 @@
<data name="CmdPackageDirectory" xml:space="preserve"> <data name="CmdPackageDirectory" xml:space="preserve">
<value>PACKAGE_DIRECTORY</value> <value>PACKAGE_DIRECTORY</value>
</data> </data>
<data name="CmdDGFileIOException" xml:space="preserve">
<value>Unable to get a temp path for a dependency graph file for project '{0}'. Cannot add package reference.</value>
</data>
</root> </root>

View file

@ -67,8 +67,15 @@ namespace Microsoft.DotNet.Tools.Add.PackageReference
if (!_appliedCommand.HasOption("no-restore")) if (!_appliedCommand.HasOption("no-restore"))
{ {
// Create a Dependency Graph file for the project // Create a Dependency Graph file for the project
tempDgFilePath = Path.GetTempFileName(); try
GetProjectDependencyGraph(projectFilePath, tempDgFilePath); {
tempDgFilePath = Path.GetTempFileName();
GetProjectDependencyGraph(projectFilePath, tempDgFilePath);
}
catch (IOException ioex)
{
throw new GracefulException(string.Format(LocalizableStrings.CmdDGFileIOException, projectFilePath));
}
} }
var result = NuGetCommand.Run( var result = NuGetCommand.Run(