Allow directories as project arguments to run command.
This commit is contained in:
parent
485237a8a0
commit
a4cb3fdf81
2 changed files with 42 additions and 15 deletions
|
@ -134,21 +134,12 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(Project))
|
if (string.IsNullOrWhiteSpace(Project))
|
||||||
{
|
{
|
||||||
string directory = Directory.GetCurrentDirectory();
|
Project = Directory.GetCurrentDirectory();
|
||||||
string[] projectFiles = Directory.GetFiles(directory, "*.*proj");
|
}
|
||||||
|
|
||||||
if (projectFiles.Length == 0)
|
if (Directory.Exists(Project))
|
||||||
{
|
{
|
||||||
var project = "--project";
|
Project = FindSingleProjectInDirectory(Project);
|
||||||
|
|
||||||
throw new GracefulException(LocalizableStrings.RunCommandExceptionNoProjects, directory, project);
|
|
||||||
}
|
|
||||||
else if (projectFiles.Length > 1)
|
|
||||||
{
|
|
||||||
throw new GracefulException(LocalizableStrings.RunCommandExceptionMultipleProjects, directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
Project = projectFiles[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Args == null)
|
if (Args == null)
|
||||||
|
@ -160,5 +151,23 @@ namespace Microsoft.DotNet.Tools.Run
|
||||||
_args = new List<string>(Args);
|
_args = new List<string>(Args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string FindSingleProjectInDirectory(string directory)
|
||||||
|
{
|
||||||
|
string[] projectFiles = Directory.GetFiles(directory, "*.*proj");
|
||||||
|
|
||||||
|
if (projectFiles.Length == 0)
|
||||||
|
{
|
||||||
|
var project = "--project";
|
||||||
|
|
||||||
|
throw new GracefulException(LocalizableStrings.RunCommandExceptionNoProjects, directory, project);
|
||||||
|
}
|
||||||
|
else if (projectFiles.Length > 1)
|
||||||
|
{
|
||||||
|
throw new GracefulException(LocalizableStrings.RunCommandExceptionMultipleProjects, directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectFiles[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,24 @@ namespace Microsoft.DotNet.Cli.Run.Tests
|
||||||
.And.HaveStdOutContaining("Hello World!");
|
.And.HaveStdOutContaining("Hello World!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItRunsPortableAppsFromADifferentPathSpecifyingOnlyTheDirectoryWithoutBuilding()
|
||||||
|
{
|
||||||
|
var testAppName = "MSBuildTestApp";
|
||||||
|
var testInstance = TestAssets.Get(testAppName)
|
||||||
|
.CreateInstance()
|
||||||
|
.WithSourceFiles()
|
||||||
|
.WithRestoreFiles();
|
||||||
|
|
||||||
|
var testProjectDirectory = testInstance.Root.FullName;
|
||||||
|
|
||||||
|
new RunCommand()
|
||||||
|
.WithWorkingDirectory(testInstance.Root.Parent)
|
||||||
|
.ExecuteWithCapturedOutput($"--project {testProjectDirectory}")
|
||||||
|
.Should().Pass()
|
||||||
|
.And.HaveStdOutContaining("Hello World!");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItRunsAppWhenRestoringToSpecificPackageDirectory()
|
public void ItRunsAppWhenRestoringToSpecificPackageDirectory()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue