Merge pull request #3413 from sokket/cycle

Adding check for self-referencing projects
This commit is contained in:
Jonathan Miller 2016-06-07 16:16:54 -07:00
commit 30ba1a1a61
6 changed files with 47 additions and 1 deletions

View file

@ -0,0 +1,12 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,16 @@
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"TestProjectWithSelfReferencingDependency": {
"target": "project"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}

View file

@ -43,7 +43,7 @@ namespace Microsoft.DotNet.Tools.Build
foreach (var dependency in project.Dependencies)
{
LibraryDescription libraryDescription;
if (lookup.TryGetValue(dependency.Name, out libraryDescription))
if ((lookup.TryGetValue(dependency.Name, out libraryDescription)) && (!libraryDescription.Identity.Name.Equals(project.Identity.Name)))
{
if (libraryDescription.Resolved && libraryDescription.Identity.Type.Equals(LibraryType.Project))
{

View file

@ -19,5 +19,11 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
args = $"restore {args}";
return base.ExecuteWithCapturedOutput(args);
}
}
}

View file

@ -351,6 +351,18 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
buildResult.StdErr.Should().Contain("The project has not been restored or restore failed - run `dotnet restore`");
}
[Fact]
private void App_WithSelfReferencingDependency_FailsBuild()
{
var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
var testInstance = testAssetsManager.CreateTestInstance("TestProjectWithSelfReferencingDependency")
.WithLockFiles();
var restoreResult = new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.ExecuteWithCapturedOutput();
restoreResult.Should().Fail();
restoreResult.StdOut.Should().Contain("error: Cycle detected");
}
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
{
// copy all the files to temp dir