Fixing #2480 to produce an InvalidProjectException when attempting to publish a
project folder that does not contain a project.json file
This commit is contained in:
parent
ef982d120e
commit
a71e4a5128
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) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -412,6 +412,16 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
|
|
||||||
private IEnumerable<ProjectContext> SelectContexts(string projectPath, NuGetFramework framework, string runtime)
|
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 ?
|
var allContexts = framework == null ?
|
||||||
ProjectContext.CreateContextForEachFramework(projectPath) :
|
ProjectContext.CreateContextForEachFramework(projectPath) :
|
||||||
new[] { ProjectContext.Create(projectPath, framework) };
|
new[] { ProjectContext.Create(projectPath, framework) };
|
||||||
|
|
|
@ -294,5 +294,26 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
||||||
var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe));
|
var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe));
|
||||||
command.Execute("").Should().ExitWith(0);
|
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…
Add table
Add a link
Reference in a new issue