Do not add duplicate projects (#5698)

This commit is contained in:
Justin Goshi 2017-02-14 13:47:06 -10:00 committed by Piotr Puszkiewicz
parent 4d9e7f959a
commit 149a4590b5
14 changed files with 231 additions and 5 deletions

View file

@ -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

View file

@ -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>

View file

@ -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());
}
}

View file

@ -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>

View file

@ -0,0 +1,12 @@
using System;
namespace Lib
{
public class Library
{
public static string GetMessage()
{
return "Message from Lib";
}
}
}

View file

@ -0,0 +1,36 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26006.2
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App", "App\App.csproj", "{7072A694-548F-4CAE-A58F-12D257D5F486}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lib", "Lib\\Lib.csproj", "{B38B1FA5-B4C9-456A-8B71-8FCD62ACF400}"
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
{7072A694-548F-4CAE-A58F-12D257D5F486}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7072A694-548F-4CAE-A58F-12D257D5F486}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7072A694-548F-4CAE-A58F-12D257D5F486}.Debug|x64.ActiveCfg = Debug|x64
{7072A694-548F-4CAE-A58F-12D257D5F486}.Debug|x64.Build.0 = Debug|x64
{7072A694-548F-4CAE-A58F-12D257D5F486}.Debug|x86.ActiveCfg = Debug|x86
{7072A694-548F-4CAE-A58F-12D257D5F486}.Debug|x86.Build.0 = Debug|x86
{7072A694-548F-4CAE-A58F-12D257D5F486}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7072A694-548F-4CAE-A58F-12D257D5F486}.Release|Any CPU.Build.0 = Release|Any CPU
{7072A694-548F-4CAE-A58F-12D257D5F486}.Release|x64.ActiveCfg = Release|x64
{7072A694-548F-4CAE-A58F-12D257D5F486}.Release|x64.Build.0 = Release|x64
{7072A694-548F-4CAE-A58F-12D257D5F486}.Release|x86.ActiveCfg = Release|x86
{7072A694-548F-4CAE-A58F-12D257D5F486}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lib\Lib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.3" />
</ItemGroup>
</Project>

View file

@ -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());
}
}

View file

@ -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>

View file

@ -0,0 +1,12 @@
using System;
namespace Lib
{
public class Library
{
public static string GetMessage()
{
return "Message from Lib";
}
}
}

View file

@ -274,7 +274,8 @@ namespace Microsoft.DotNet.Cli.Sln.Internal
}
set
{
_filePath = PathUtility.GetPathWithDirectorySeparator(value);
_filePath = PathUtility.RemoveExtraPathSeparators(
PathUtility.GetPathWithDirectorySeparator(value));
}
}

View file

@ -261,6 +261,32 @@ namespace Microsoft.DotNet.Tools.Common
}
}
public static string RemoveExtraPathSeparators(string path)
{
if (string.IsNullOrEmpty(path))
{
return path;
}
var components = path.Split(Path.DirectorySeparatorChar);
var result = string.Empty;
foreach (var component in components)
{
if (!string.IsNullOrEmpty(component))
{
result = Path.Combine(result, component);
}
}
if (path[path.Length-1] == Path.DirectorySeparatorChar)
{
result += Path.DirectorySeparatorChar;
}
return result;
}
public static bool HasExtension(string filePath, string extension)
{
var comparison = StringComparison.Ordinal;

View file

@ -172,7 +172,7 @@ namespace Microsoft.DotNet.Tools.Common
this SlnFile slnFile,
SlnPropertySet nestedProjects)
{
var solutionFolderPaths = new Dictionary<string, string>();
var solutionFolderPaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var solutionFolderProjects = slnFile.Projects.GetProjectsByType(ProjectTypeGuids.SolutionFolderGuid);
foreach (var slnProject in solutionFolderProjects)

View file

@ -502,11 +502,13 @@ EndGlobal
.Count().Should().Be(1, $"Lib {reasonString}");
}
[Fact]
public void WhenSolutionAlreadyContainsProjectItDoesntDuplicate()
[Theory]
[InlineData("TestAppWithSlnAndExistingCsprojReferences")]
[InlineData("TestAppWithSlnAndExistingCsprojReferencesWithEscapedDirSep")]
public void WhenSolutionAlreadyContainsProjectItDoesntDuplicate(string testAsset)
{
var projectDirectory = TestAssets
.Get("TestAppWithSlnAndExistingCsprojReferences")
.Get(testAsset)
.CreateInstance()
.WithSourceFiles()
.Root
@ -606,6 +608,28 @@ EndGlobal
nonSolutionFolderProjects.Single().TypeGuid.Should().Be(expectedTypeGuid);
}
[Fact]
private void WhenSlnContainsSolutionFolderWithDifferentCasingItDoesNotCreateDuplicate()
{
var projectDirectory = TestAssets
.Get("TestAppWithSlnAndCaseSensitiveSolutionFolders")
.CreateInstance()
.WithSourceFiles()
.Root
.FullName;
var projectToAdd = Path.Combine("src", "Lib", "Lib.csproj");
var cmd = new DotnetCommand()
.WithWorkingDirectory(projectDirectory)
.Execute($"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(1);
}
private string GetExpectedSlnContents(
string slnPath,
string slnTemplate,