Merge pull request #2538 from sokket/nrefix
Fixing #2480 to produce an InvalidProjectException for invalid projects
This commit is contained in:
commit
18ae4d4791
4 changed files with 45 additions and 0 deletions
14
src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs
Normal file
14
src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
public class InvalidProjectException : Exception
|
||||
{
|
||||
public InvalidProjectException() { }
|
||||
public InvalidProjectException(string message) : base(message) { }
|
||||
public InvalidProjectException(string message, Exception innerException) : base(message, innerException) { }
|
||||
}
|
||||
}
|
|
@ -422,6 +422,16 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
|
||||
private IEnumerable<ProjectContext> SelectContexts(string projectPath, NuGetFramework framework, string runtime)
|
||||
{
|
||||
if (projectPath.EndsWith("project.json"))
|
||||
{
|
||||
if (File.Exists(projectPath) == false)
|
||||
throw new InvalidProjectException($"'{projectPath}' does not exist");
|
||||
}
|
||||
else if (File.Exists(Path.Combine(projectPath, "project.json")) == false)
|
||||
{
|
||||
throw new InvalidProjectException($"'{projectPath}' does not contain a project.json file");
|
||||
}
|
||||
|
||||
var allContexts = framework == null ?
|
||||
ProjectContext.CreateContextForEachFramework(projectPath) :
|
||||
new[] { ProjectContext.Create(projectPath, framework) };
|
||||
|
|
|
@ -294,5 +294,26 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe));
|
||||
command.Execute("").Should().ExitWith(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PublishFailsWhenProjectRootIsEmpty()
|
||||
{
|
||||
using (var dir = new DisposableDirectory(Temp))
|
||||
{
|
||||
var command = new TestCommand("dotnet");
|
||||
command.Execute($"publish {dir.Path}").Should().Fail();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PublishFailsWhenProjectJsonDoesNotExist()
|
||||
{
|
||||
using (var dir = new DisposableDirectory(Temp))
|
||||
{
|
||||
var command = new TestCommand("dotnet");
|
||||
string temp = Path.Combine(dir.Path, "project.json");
|
||||
command.Execute($"publish {temp}").Should().Fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue