Do not add duplicate solution folders or project directories (#5377)
* Do not add duplicate solution folders or project directories * Fix the algorithm for removing empty solution folders * Improving code by adding description methods. To address PR comments.
This commit is contained in:
parent
6bb76cf20e
commit
b2c51b7269
10 changed files with 270 additions and 70 deletions
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.26006.2
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App", "src\App\App.csproj", "{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}"
|
||||||
|
EndProject
|
||||||
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{72BFCA87-B033-4721-8712-4D12166B4A39}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Release|x64.Build.0 = Release|x64
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}.Release|x86.Build.0 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(NestedProjects) = preSolution
|
||||||
|
{DDF3765C-59FB-4AA6-BE83-779ED13AA64A} = {72BFCA87-B033-4721-8712-4D12166B4A39}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
|
@ -0,0 +1,15 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\src\Lib\Lib.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello from the main app");
|
||||||
|
Console.WriteLine(Lib.Library.GetMessage());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard1.4</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="NETStandard.Library" Version="1.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Lib
|
||||||
|
{
|
||||||
|
public class Library
|
||||||
|
{
|
||||||
|
public static string GetMessage()
|
||||||
|
{
|
||||||
|
return "Message from Lib";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,34 +10,18 @@ namespace Microsoft.DotNet.Tools.Common
|
||||||
{
|
{
|
||||||
public static class SlnProjectCollectionExtensions
|
public static class SlnProjectCollectionExtensions
|
||||||
{
|
{
|
||||||
public static HashSet<string> GetReferencedSolutionFolders(this SlnProjectCollection projects)
|
public static IEnumerable<SlnProject> GetProjectsByType(
|
||||||
|
this SlnProjectCollection projects,
|
||||||
|
string typeGuid)
|
||||||
{
|
{
|
||||||
var referencedSolutionFolders = new HashSet<string>();
|
return projects.Where(p => p.TypeGuid == typeGuid);
|
||||||
|
|
||||||
var solutionFolderProjects = projects
|
|
||||||
.Where(p => p.TypeGuid == ProjectTypeGuids.SolutionFolderGuid)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (solutionFolderProjects.Any())
|
|
||||||
{
|
|
||||||
var nonSolutionFolderProjects = projects
|
|
||||||
.Where(p => p.TypeGuid != ProjectTypeGuids.SolutionFolderGuid)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
foreach (var project in nonSolutionFolderProjects)
|
|
||||||
{
|
|
||||||
var solutionFolders = project.GetSolutionFoldersFromProject();
|
|
||||||
foreach (var solutionFolder in solutionFolders)
|
|
||||||
{
|
|
||||||
if (!referencedSolutionFolders.Contains(solutionFolder))
|
|
||||||
{
|
|
||||||
referencedSolutionFolders.Add(solutionFolder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return referencedSolutionFolders;
|
public static IEnumerable<SlnProject> GetProjectsNotOfType(
|
||||||
|
this SlnProjectCollection projects,
|
||||||
|
string typeGuid)
|
||||||
|
{
|
||||||
|
return projects.Where(p => p.TypeGuid != typeGuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,17 +12,44 @@ namespace Microsoft.DotNet.Tools.Common
|
||||||
{
|
{
|
||||||
public static IList<string> GetSolutionFoldersFromProject(this SlnProject project)
|
public static IList<string> GetSolutionFoldersFromProject(this SlnProject project)
|
||||||
{
|
{
|
||||||
var currentDirString = $".{Path.DirectorySeparatorChar}";
|
var solutionFolders = new List<string>();
|
||||||
|
|
||||||
var directoryPath = Path.GetDirectoryName(project.FilePath);
|
var projectFilePath = project.FilePath;
|
||||||
if (directoryPath.StartsWith(currentDirString))
|
if (IsPathInTreeRootedAtSolutionDirectory(projectFilePath))
|
||||||
{
|
{
|
||||||
directoryPath = directoryPath.Substring(currentDirString.Length);
|
var currentDirString = $".{Path.DirectorySeparatorChar}";
|
||||||
|
if (projectFilePath.StartsWith(currentDirString))
|
||||||
|
{
|
||||||
|
projectFilePath = projectFilePath.Substring(currentDirString.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return directoryPath.StartsWith("..")
|
var projectDirectoryPath = TrimProject(projectFilePath);
|
||||||
? new List<string>()
|
if (!string.IsNullOrEmpty(projectDirectoryPath))
|
||||||
: new List<string>(directoryPath.Split(Path.DirectorySeparatorChar));
|
{
|
||||||
|
var solutionFoldersPath = TrimProjectDirectory(projectDirectoryPath);
|
||||||
|
if (!string.IsNullOrEmpty(solutionFoldersPath))
|
||||||
|
{
|
||||||
|
solutionFolders.AddRange(solutionFoldersPath.Split(Path.DirectorySeparatorChar));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return solutionFolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsPathInTreeRootedAtSolutionDirectory(string path)
|
||||||
|
{
|
||||||
|
return !path.StartsWith("..");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string TrimProject(string path)
|
||||||
|
{
|
||||||
|
return Path.GetDirectoryName(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string TrimProjectDirectory(string path)
|
||||||
|
{
|
||||||
|
return Path.GetDirectoryName(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,8 +163,18 @@ namespace Microsoft.DotNet.Tools.Sln.Add
|
||||||
"NestedProjects",
|
"NestedProjects",
|
||||||
SlnSectionType.PreProcess);
|
SlnSectionType.PreProcess);
|
||||||
|
|
||||||
|
var pathToGuidMap = GetSolutionFolderPaths(slnFile, nestedProjectsSection.Properties);
|
||||||
|
|
||||||
string parentDirGuid = null;
|
string parentDirGuid = null;
|
||||||
|
var solutionFolderHierarchy = string.Empty;
|
||||||
foreach (var dir in solutionFolders)
|
foreach (var dir in solutionFolders)
|
||||||
|
{
|
||||||
|
solutionFolderHierarchy = Path.Combine(solutionFolderHierarchy, dir);
|
||||||
|
if (pathToGuidMap.ContainsKey(solutionFolderHierarchy))
|
||||||
|
{
|
||||||
|
parentDirGuid = pathToGuidMap[solutionFolderHierarchy];
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
var solutionFolder = new SlnProject
|
var solutionFolder = new SlnProject
|
||||||
{
|
{
|
||||||
|
@ -182,9 +192,32 @@ namespace Microsoft.DotNet.Tools.Sln.Add
|
||||||
}
|
}
|
||||||
parentDirGuid = solutionFolder.Id;
|
parentDirGuid = solutionFolder.Id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nestedProjectsSection.Properties[slnProject.Id] = parentDirGuid;
|
nestedProjectsSection.Properties[slnProject.Id] = parentDirGuid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IDictionary<string, string> GetSolutionFolderPaths(SlnFile slnFile, SlnPropertySet nestedProjects)
|
||||||
|
{
|
||||||
|
var solutionFolderPaths = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
var solutionFolderProjects = slnFile.Projects.GetProjectsByType(ProjectTypeGuids.SolutionFolderGuid);
|
||||||
|
foreach (var slnProject in solutionFolderProjects)
|
||||||
|
{
|
||||||
|
var path = slnProject.FilePath;
|
||||||
|
var id = slnProject.Id;
|
||||||
|
while (nestedProjects.ContainsKey(id))
|
||||||
|
{
|
||||||
|
id = nestedProjects[id];
|
||||||
|
var parentSlnProject = solutionFolderProjects.Where(p => p.Id == id).Single();
|
||||||
|
path = Path.Combine(parentSlnProject.FilePath, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
solutionFolderPaths[path] = slnProject.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return solutionFolderPaths;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,10 +126,8 @@ namespace Microsoft.DotNet.Tools.Sln.Remove
|
||||||
|
|
||||||
private void RemoveEmptySolutionFolders(SlnFile slnFile)
|
private void RemoveEmptySolutionFolders(SlnFile slnFile)
|
||||||
{
|
{
|
||||||
var referencedSolutionFolders = slnFile.Projects.GetReferencedSolutionFolders();
|
|
||||||
|
|
||||||
var solutionFolderProjects = slnFile.Projects
|
var solutionFolderProjects = slnFile.Projects
|
||||||
.Where(p => p.TypeGuid == ProjectTypeGuids.SolutionFolderGuid)
|
.GetProjectsByType(ProjectTypeGuids.SolutionFolderGuid)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
if (solutionFolderProjects.Any())
|
if (solutionFolderProjects.Any())
|
||||||
|
@ -138,9 +136,13 @@ namespace Microsoft.DotNet.Tools.Sln.Remove
|
||||||
"NestedProjects",
|
"NestedProjects",
|
||||||
SlnSectionType.PreProcess);
|
SlnSectionType.PreProcess);
|
||||||
|
|
||||||
|
var solutionFoldersInUse = GetSolutionFoldersThatContainProjectsInItsHierarchy(
|
||||||
|
slnFile,
|
||||||
|
nestedProjectsSection.Properties);
|
||||||
|
|
||||||
foreach (var solutionFolderProject in solutionFolderProjects)
|
foreach (var solutionFolderProject in solutionFolderProjects)
|
||||||
{
|
{
|
||||||
if (!referencedSolutionFolders.Contains(solutionFolderProject.Name))
|
if (!solutionFoldersInUse.Contains(solutionFolderProject.Id))
|
||||||
{
|
{
|
||||||
slnFile.Projects.Remove(solutionFolderProject);
|
slnFile.Projects.Remove(solutionFolderProject);
|
||||||
nestedProjectsSection.Properties.Remove(solutionFolderProject.Id);
|
nestedProjectsSection.Properties.Remove(solutionFolderProject.Id);
|
||||||
|
@ -153,5 +155,27 @@ namespace Microsoft.DotNet.Tools.Sln.Remove
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashSet<string> GetSolutionFoldersThatContainProjectsInItsHierarchy(
|
||||||
|
SlnFile slnFile,
|
||||||
|
SlnPropertySet nestedProjects)
|
||||||
|
{
|
||||||
|
var solutionFoldersInUse = new HashSet<string>();
|
||||||
|
|
||||||
|
var nonSolutionFolderProjects = slnFile.Projects.GetProjectsNotOfType(
|
||||||
|
ProjectTypeGuids.SolutionFolderGuid);
|
||||||
|
|
||||||
|
foreach (var nonSolutionFolderProject in nonSolutionFolderProjects)
|
||||||
|
{
|
||||||
|
var id = nonSolutionFolderProject.Id;
|
||||||
|
while (nestedProjects.ContainsKey(id))
|
||||||
|
{
|
||||||
|
id = nestedProjects[id];
|
||||||
|
solutionFoldersInUse.Add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return solutionFoldersInUse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,6 @@ VisualStudioVersion = 15.0.26006.2
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""App"", ""App\App.csproj"", ""{7072A694-548F-4CAE-A58F-12D257D5F486}""
|
Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""App"", ""App\App.csproj"", ""{7072A694-548F-4CAE-A58F-12D257D5F486}""
|
||||||
EndProject
|
EndProject
|
||||||
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Lib"", ""Lib"", ""__LIB_FOLDER_GUID__""
|
|
||||||
EndProject
|
|
||||||
Project(""{13B669BE-BB05-4DDF-9536-439F39A36129}"") = ""Lib"", ""Lib\Lib.csproj"", ""__LIB_PROJECT_GUID__""
|
Project(""{13B669BE-BB05-4DDF-9536-439F39A36129}"") = ""Lib"", ""Lib\Lib.csproj"", ""__LIB_PROJECT_GUID__""
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
@ -77,9 +75,6 @@ Global
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
|
||||||
__LIB_PROJECT_GUID__ = __LIB_FOLDER_GUID__
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
EndGlobal
|
||||||
";
|
";
|
||||||
|
|
||||||
|
@ -88,8 +83,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26006.2
|
VisualStudioVersion = 15.0.26006.2
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Lib"", ""Lib"", ""__LIB_FOLDER_GUID__""
|
|
||||||
EndProject
|
|
||||||
Project(""{13B669BE-BB05-4DDF-9536-439F39A36129}"") = ""Lib"", ""Lib\Lib.csproj"", ""__LIB_PROJECT_GUID__""
|
Project(""{13B669BE-BB05-4DDF-9536-439F39A36129}"") = ""Lib"", ""Lib\Lib.csproj"", ""__LIB_PROJECT_GUID__""
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
@ -115,9 +108,6 @@ Global
|
||||||
__LIB_PROJECT_GUID__.Release|x86.ActiveCfg = Release|x86
|
__LIB_PROJECT_GUID__.Release|x86.ActiveCfg = Release|x86
|
||||||
__LIB_PROJECT_GUID__.Release|x86.Build.0 = Release|x86
|
__LIB_PROJECT_GUID__.Release|x86.Build.0 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
|
||||||
__LIB_PROJECT_GUID__ = __LIB_FOLDER_GUID__
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
EndGlobal
|
||||||
";
|
";
|
||||||
|
|
||||||
|
@ -130,8 +120,6 @@ Project(""{9A19103F-16F7-4668-BE54-9A1E7A4F7556}"") = ""App"", ""App.csproj"", "
|
||||||
EndProject
|
EndProject
|
||||||
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""src"", ""src"", ""__SRC_FOLDER_GUID__""
|
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""src"", ""src"", ""__SRC_FOLDER_GUID__""
|
||||||
EndProject
|
EndProject
|
||||||
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Lib"", ""Lib"", ""__LIB_FOLDER_GUID__""
|
|
||||||
EndProject
|
|
||||||
Project(""{13B669BE-BB05-4DDF-9536-439F39A36129}"") = ""Lib"", ""src\Lib\Lib.csproj"", ""__LIB_PROJECT_GUID__""
|
Project(""{13B669BE-BB05-4DDF-9536-439F39A36129}"") = ""Lib"", ""src\Lib\Lib.csproj"", ""__LIB_PROJECT_GUID__""
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
@ -173,8 +161,7 @@ Global
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
__LIB_FOLDER_GUID__ = __SRC_FOLDER_GUID__
|
__LIB_PROJECT_GUID__ = __SRC_FOLDER_GUID__
|
||||||
__LIB_PROJECT_GUID__ = __LIB_FOLDER_GUID__
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
";
|
";
|
||||||
|
@ -345,6 +332,70 @@ EndGlobal
|
||||||
.Should().BeVisuallyEquivalentTo(expectedSlnContents);
|
.Should().BeVisuallyEquivalentTo(expectedSlnContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WhenProjectDirectoryIsAddedSolutionFoldersAreNotCreated()
|
||||||
|
{
|
||||||
|
var projectDirectory = TestAssets
|
||||||
|
.Get("TestAppWithSlnAndCsprojFiles")
|
||||||
|
.CreateInstance()
|
||||||
|
.WithSourceFiles()
|
||||||
|
.Root
|
||||||
|
.FullName;
|
||||||
|
|
||||||
|
var projectToAdd = Path.Combine("Lib", "Lib.csproj");
|
||||||
|
var cmd = new DotnetCommand()
|
||||||
|
.WithWorkingDirectory(projectDirectory)
|
||||||
|
.ExecuteWithCapturedOutput($"sln App.sln add {projectToAdd}");
|
||||||
|
cmd.Should().Pass();
|
||||||
|
|
||||||
|
var slnFile = SlnFile.Read(Path.Combine(projectDirectory, "App.sln"));
|
||||||
|
var solutionFolderProjects = slnFile.Projects.Where(
|
||||||
|
p => p.TypeGuid == ProjectTypeGuids.SolutionFolderGuid);
|
||||||
|
solutionFolderProjects.Count().Should().Be(0);
|
||||||
|
slnFile.Sections.GetSection("NestedProjects").Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(".")]
|
||||||
|
[InlineData("")]
|
||||||
|
public void WhenSolutionFolderExistsItDoesNotGetAdded(string firstComponent)
|
||||||
|
{
|
||||||
|
var projectDirectory = TestAssets
|
||||||
|
.Get("TestAppWithSlnAndSolutionFolders")
|
||||||
|
.CreateInstance()
|
||||||
|
.WithSourceFiles()
|
||||||
|
.Root
|
||||||
|
.FullName;
|
||||||
|
|
||||||
|
var projectToAdd = Path.Combine($"{firstComponent}", "src", "src", "Lib", "Lib.csproj");
|
||||||
|
var cmd = new DotnetCommand()
|
||||||
|
.WithWorkingDirectory(projectDirectory)
|
||||||
|
.ExecuteWithCapturedOutput($"sln App.sln add {projectToAdd}");
|
||||||
|
cmd.Should().Pass();
|
||||||
|
|
||||||
|
var slnFile = SlnFile.Read(Path.Combine(projectDirectory, "App.sln"));
|
||||||
|
slnFile.Projects.Count().Should().Be(4);
|
||||||
|
|
||||||
|
var solutionFolderProjects = slnFile.Projects.Where(
|
||||||
|
p => p.TypeGuid == ProjectTypeGuids.SolutionFolderGuid);
|
||||||
|
solutionFolderProjects.Count().Should().Be(2);
|
||||||
|
|
||||||
|
var solutionFolders = slnFile.Sections.GetSection("NestedProjects").Properties;
|
||||||
|
solutionFolders.Count.Should().Be(3);
|
||||||
|
|
||||||
|
solutionFolders["{DDF3765C-59FB-4AA6-BE83-779ED13AA64A}"]
|
||||||
|
.Should().Be("{72BFCA87-B033-4721-8712-4D12166B4A39}");
|
||||||
|
|
||||||
|
var newlyAddedSrcFolder = solutionFolderProjects.Where(
|
||||||
|
p => p.Id != "{72BFCA87-B033-4721-8712-4D12166B4A39}").Single();
|
||||||
|
solutionFolders[newlyAddedSrcFolder.Id]
|
||||||
|
.Should().Be("{72BFCA87-B033-4721-8712-4D12166B4A39}");
|
||||||
|
|
||||||
|
var libProject = slnFile.Projects.Where(p => p.Name == "Lib").Single();
|
||||||
|
solutionFolders[libProject.Id]
|
||||||
|
.Should().Be(newlyAddedSrcFolder.Id);
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("TestAppWithSlnAndCsprojFiles", ExpectedSlnFileAfterAddingLibProj, "")]
|
[InlineData("TestAppWithSlnAndCsprojFiles", ExpectedSlnFileAfterAddingLibProj, "")]
|
||||||
[InlineData("TestAppWithSlnAndCsprojProjectGuidFiles", ExpectedSlnFileAfterAddingLibProj, "{84A45D44-B677-492D-A6DA-B3A71135AB8E}")]
|
[InlineData("TestAppWithSlnAndCsprojProjectGuidFiles", ExpectedSlnFileAfterAddingLibProj, "{84A45D44-B677-492D-A6DA-B3A71135AB8E}")]
|
||||||
|
@ -574,12 +625,6 @@ EndGlobal
|
||||||
}
|
}
|
||||||
var slnContents = slnTemplate.Replace("__LIB_PROJECT_GUID__", expectedLibProjectGuid);
|
var slnContents = slnTemplate.Replace("__LIB_PROJECT_GUID__", expectedLibProjectGuid);
|
||||||
|
|
||||||
var matchingLibFolder = slnFile.Projects
|
|
||||||
.Where((p) => p.FilePath == "Lib")
|
|
||||||
.ToList();
|
|
||||||
matchingLibFolder.Count.Should().Be(1);
|
|
||||||
slnContents = slnContents.Replace("__LIB_FOLDER_GUID__", matchingLibFolder[0].Id);
|
|
||||||
|
|
||||||
var matchingSrcFolder = slnFile.Projects
|
var matchingSrcFolder = slnFile.Projects
|
||||||
.Where((p) => p.FilePath == "src")
|
.Where((p) => p.FilePath == "src")
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue