From f4beb4fbadaa792f5c4cbc1ac2d2e78eb74c2cc7 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 23 Jun 2015 11:12:59 -0700 Subject: [PATCH] Make global.json accept project directories in 'projects' property --- .../ProjectResolver.cs | 4 +-- .../ProjectResolverTests.cs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Framework.Runtime/ProjectResolver.cs b/src/Microsoft.Framework.Runtime/ProjectResolver.cs index bd2892daf..882182e7f 100644 --- a/src/Microsoft.Framework.Runtime/ProjectResolver.cs +++ b/src/Microsoft.Framework.Runtime/ProjectResolver.cs @@ -79,9 +79,9 @@ private void Initialize(string projectPath, string rootPath) // Resolve all of the potential projects _projects = _searchPaths.Select(path => new DirectoryInfo(path)) - .Distinct(new DirectoryInfoFullPathComparator()) .Where(d => d.Exists) - .SelectMany(d => d.EnumerateDirectories()) + .SelectMany(d => new[] { d }.Concat(d.EnumerateDirectories())) + .Distinct(new DirectoryInfoFullPathComparator()) .Select(dirInfoToProjectInfo) .ToLookup(d => d.Name); } diff --git a/test/Microsoft.Framework.Runtime.FunctionalTests/ProjectResolverTests.cs b/test/Microsoft.Framework.Runtime.FunctionalTests/ProjectResolverTests.cs index 058c1410e..a73a0a6a9 100644 --- a/test/Microsoft.Framework.Runtime.FunctionalTests/ProjectResolverTests.cs +++ b/test/Microsoft.Framework.Runtime.FunctionalTests/ProjectResolverTests.cs @@ -194,5 +194,36 @@ public void ProjectResolverDoesNotThrowWhenThereAreDuplicatedEntriesInGlobalJson Assert.NotNull(project); } } + + [Fact] + public void CanSpecifyProjectDirectoryInGlobalJson() + { + var solutionStructure = @"{ + 'global.json': '', + 'src': { + 'ProjectA': { + 'project.json': '{}' + } + }, + 'ProjectB': { + 'project.json': '{}' + } +}"; + + using (var solutionPath = new DisposableDir()) + { + DirTree.CreateFromJson(solutionStructure) + .WithFileContents("global.json", @"{ + ""projects"": [""src"", ""ProjectB""] +}") + .WriteTo(solutionPath); + + var resolutionRoot = Path.Combine(solutionPath, "src", "ProjectA"); + + Project project; + Assert.True(new ProjectResolver(resolutionRoot).TryResolveProject("ProjectB", out project)); + Assert.NotNull(project); + } + } } }