"dotnet test project.json" fails in a directory with a test project.json in it
When the current directory contains a valid project.json, and the user just says `dotnet test project.json`, normalizing the path fails becuase we end up calling Path.GetFullPath with an empty string. To fix this, if the directory of the file is empty, use the current directory. Fixing this for all "dotnet XXX" commands. Fix #2691
This commit is contained in:
parent
3a2a789b1c
commit
a070976671
2 changed files with 37 additions and 24 deletions
|
@ -64,10 +64,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
public static Project GetProject(string projectPath, ProjectReaderSettings settings = null)
|
public static Project GetProject(string projectPath, ProjectReaderSettings settings = null)
|
||||||
{
|
{
|
||||||
if (!projectPath.EndsWith(Project.FileName))
|
projectPath = NormalizeProjectFilePath(projectPath);
|
||||||
{
|
|
||||||
projectPath = Path.Combine(projectPath, Project.FileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
var name = Path.GetFileName(Path.GetDirectoryName(projectPath));
|
var name = Path.GetFileName(Path.GetDirectoryName(projectPath));
|
||||||
|
|
||||||
|
@ -236,6 +233,38 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static string NormalizeProjectDirectoryPath(string path)
|
||||||
|
{
|
||||||
|
if (File.Exists(path) &&
|
||||||
|
string.Equals(Path.GetFileName(path), Project.FileName, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
string directoryName = Path.GetDirectoryName(path);
|
||||||
|
if (string.IsNullOrEmpty(directoryName))
|
||||||
|
{
|
||||||
|
directoryName = Directory.GetCurrentDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Path.GetFullPath(directoryName);
|
||||||
|
}
|
||||||
|
else if (Directory.Exists(path) &&
|
||||||
|
File.Exists(Path.Combine(path, Project.FileName)))
|
||||||
|
{
|
||||||
|
return Path.GetFullPath(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string NormalizeProjectFilePath(string path)
|
||||||
|
{
|
||||||
|
if (!path.EndsWith(Project.FileName))
|
||||||
|
{
|
||||||
|
path = Path.Combine(path, Project.FileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Path.GetFullPath(path);
|
||||||
|
}
|
||||||
|
|
||||||
private static NuGetVersion SpecifySnapshot(string version, string snapshotValue)
|
private static NuGetVersion SpecifySnapshot(string version, string snapshotValue)
|
||||||
{
|
{
|
||||||
if (version.EndsWith("-*"))
|
if (version.EndsWith("-*"))
|
||||||
|
|
|
@ -107,7 +107,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
public void AddProject(string path)
|
public void AddProject(string path)
|
||||||
{
|
{
|
||||||
var projectPath = NormalizeProjectPath(path);
|
var projectPath = ProjectReader.NormalizeProjectDirectoryPath(path);
|
||||||
|
|
||||||
if (projectPath != null)
|
if (projectPath != null)
|
||||||
{
|
{
|
||||||
|
@ -228,7 +228,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
public ProjectContextCollection GetProjectContextCollection(string projectPath)
|
public ProjectContextCollection GetProjectContextCollection(string projectPath)
|
||||||
{
|
{
|
||||||
var normalizedPath = NormalizeProjectPath(projectPath);
|
var normalizedPath = ProjectReader.NormalizeProjectDirectoryPath(projectPath);
|
||||||
if (normalizedPath == null)
|
if (normalizedPath == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -242,7 +242,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
private FileModelEntry<Project> GetProjectCore(string projectDirectory)
|
private FileModelEntry<Project> GetProjectCore(string projectDirectory)
|
||||||
{
|
{
|
||||||
var normalizedPath = NormalizeProjectPath(projectDirectory);
|
var normalizedPath = ProjectReader.NormalizeProjectDirectoryPath(projectDirectory);
|
||||||
if (normalizedPath == null)
|
if (normalizedPath == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -256,7 +256,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
private LockFile GetLockFile(string projectDirectory)
|
private LockFile GetLockFile(string projectDirectory)
|
||||||
{
|
{
|
||||||
var normalizedPath = NormalizeProjectPath(projectDirectory);
|
var normalizedPath = ProjectReader.NormalizeProjectDirectoryPath(projectDirectory);
|
||||||
if (normalizedPath == null)
|
if (normalizedPath == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -441,22 +441,6 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string NormalizeProjectPath(string path)
|
|
||||||
{
|
|
||||||
if (File.Exists(path) &&
|
|
||||||
string.Equals(Path.GetFileName(path), Project.FileName, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
return Path.GetFullPath(Path.GetDirectoryName(path));
|
|
||||||
}
|
|
||||||
else if (Directory.Exists(path) &&
|
|
||||||
File.Exists(Path.Combine(path, Project.FileName)))
|
|
||||||
{
|
|
||||||
return Path.GetFullPath(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<string> ResolveProjectPath(string projectPath)
|
private static List<string> ResolveProjectPath(string projectPath)
|
||||||
{
|
{
|
||||||
if (File.Exists(projectPath))
|
if (File.Exists(projectPath))
|
||||||
|
|
Loading…
Reference in a new issue