diff --git a/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Dir/App.sln b/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Dir/App.sln new file mode 100644 index 000000000000..8eca2536691f --- /dev/null +++ b/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Dir/App.sln @@ -0,0 +1,5 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26006.2 +MinimumVisualStudioVersion = 10.0.40219.1 diff --git a/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Dir/App.slnx b/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Dir/App.slnx new file mode 100644 index 000000000000..4e2253ddceed --- /dev/null +++ b/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Dir/App.slnx @@ -0,0 +1 @@ + diff --git a/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Lib/Lib.csproj b/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Lib/Lib.csproj new file mode 100644 index 000000000000..c350d4032840 --- /dev/null +++ b/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Lib/Lib.csproj @@ -0,0 +1,7 @@ + + + + netstandard1.4 + + + diff --git a/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Lib/Library.cs b/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Lib/Library.cs new file mode 100644 index 000000000000..71a4d48322c7 --- /dev/null +++ b/test/TestAssets/TestProjects/TestAppWithSlnAndCsprojInParentDir/Lib/Library.cs @@ -0,0 +1,15 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; + +namespace Lib +{ + public class Library + { + public static string GetMessage() + { + return "Message from Lib"; + } + } +} diff --git a/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs b/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs index 6009f9c04b97..e22f2f979cda 100644 --- a/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs +++ b/test/dotnet-sln.Tests/GivenDotnetSlnAdd.cs @@ -1096,6 +1096,29 @@ public void WhenSolutionFolderIsPassedWithDirectorySeparatorFolderStructureIsCor .Should().BeVisuallyEquivalentTo(expectedSlnContents); } + [Theory] + [InlineData("sln", ".sln")] + [InlineData("sln", ".slnx")] + [InlineData("solution", ".sln")] + [InlineData("solution", ".slnx")] + public async Task WhenAddingProjectOutsideDirectoryItShouldNotAddSolutionFolders(string solutionCommand, string solutionExtension) + { + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppWithSlnAndCsprojInParentDir", identifier: $"GivenDotnetSlnAdd-{solutionCommand}{solutionExtension}") + .WithSource() + .Path; + var projectToAdd = Path.Combine("..", "Lib", "Lib.csproj"); + var cmd = new DotnetCommand(Log) + .WithWorkingDirectory(Path.Join(projectDirectory, "Dir")) + .Execute(solutionCommand, $"App{solutionExtension}", "add", projectToAdd); + cmd.Should().Pass(); + // Should have no solution folders + ISolutionSerializer serializer = SolutionSerializers.GetSerializerByMoniker(Path.Join(projectDirectory, "Dir", $"App{solutionExtension}")); + SolutionModel solution = await serializer.OpenAsync(Path.Join(projectDirectory, "Dir", $"App{solutionExtension}"), CancellationToken.None); + solution.SolutionProjects.Count.Should().Be(1); + solution.SolutionFolders.Count.Should().Be(0); + } + private string GetExpectedSlnContents( string slnPath, string slnTemplateName,