diff --git a/.gitattributes b/.gitattributes
index 50950c656..4422d1501 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -51,4 +51,5 @@
*.vbproj text=auto
*.fsproj text=auto
*.dbproj text=auto
+*.xlf text=auto
*.sln text=auto eol=crlf
\ No newline at end of file
diff --git a/TestAssets/NonRestoredTestProjects/DotnetAddP2PProjects/Empty/README b/TestAssets/NonRestoredTestProjects/DotnetAddP2PProjects/Empty/README
new file mode 100644
index 000000000..439cfe9c7
--- /dev/null
+++ b/TestAssets/NonRestoredTestProjects/DotnetAddP2PProjects/Empty/README
@@ -0,0 +1,2 @@
+This directory is intentionally empty.
+
diff --git a/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Empty/README b/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Empty/README
new file mode 100644
index 000000000..439cfe9c7
--- /dev/null
+++ b/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Empty/README
@@ -0,0 +1,2 @@
+This directory is intentionally empty.
+
diff --git a/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Multiple/First.csproj b/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Multiple/First.csproj
new file mode 100644
index 000000000..9f5c4f4ab
--- /dev/null
+++ b/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Multiple/First.csproj
@@ -0,0 +1,7 @@
+
+
+
+ netstandard2.0
+
+
+
diff --git a/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Multiple/Second.csproj b/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Multiple/Second.csproj
new file mode 100644
index 000000000..9f5c4f4ab
--- /dev/null
+++ b/TestAssets/TestProjects/TestAppWithSlnAndCsprojFiles/Multiple/Second.csproj
@@ -0,0 +1,7 @@
+
+
+
+ netstandard2.0
+
+
+
diff --git a/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Empty/README b/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Empty/README
new file mode 100644
index 000000000..439cfe9c7
--- /dev/null
+++ b/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Empty/README
@@ -0,0 +1,2 @@
+This directory is intentionally empty.
+
diff --git a/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Multiple/First.csproj b/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Multiple/First.csproj
new file mode 100644
index 000000000..9f5c4f4ab
--- /dev/null
+++ b/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Multiple/First.csproj
@@ -0,0 +1,7 @@
+
+
+
+ netstandard2.0
+
+
+
diff --git a/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Multiple/Second.csproj b/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Multiple/Second.csproj
new file mode 100644
index 000000000..9f5c4f4ab
--- /dev/null
+++ b/TestAssets/TestProjects/TestAppWithSlnAndCsprojToRemove/Multiple/Second.csproj
@@ -0,0 +1,7 @@
+
+
+
+ netstandard2.0
+
+
+
diff --git a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs
index e0ad71840..32620e0d5 100644
--- a/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs
+++ b/src/Microsoft.DotNet.Cli.Utils/PathUtility.cs
@@ -330,13 +330,14 @@ namespace Microsoft.DotNet.Tools.Common
public static void EnsureAllPathsExist(
IReadOnlyCollection paths,
- string pathDoesNotExistLocalizedFormatString)
+ string pathDoesNotExistLocalizedFormatString,
+ bool allowDirectories = false)
{
var notExisting = new List();
foreach (var p in paths)
{
- if (!File.Exists(p))
+ if (!File.Exists(p) && (!allowDirectories || !Directory.Exists(p)))
{
notExisting.Add(p);
}
diff --git a/src/dotnet/CommonLocalizableStrings.resx b/src/dotnet/CommonLocalizableStrings.resx
index d165ca59e..e51b2a473 100644
--- a/src/dotnet/CommonLocalizableStrings.resx
+++ b/src/dotnet/CommonLocalizableStrings.resx
@@ -345,9 +345,6 @@
Specified solution file {0} does not exist, or there is no solution file in the directory.
-
- Reference {0} does not exist.
-
Reference `{0}` is invalid.
@@ -384,6 +381,9 @@
Project `{0}` added to the solution.
+
+ Project `{0}` removed from the solution.
+
Solution {0} already contains project {1}.
diff --git a/src/dotnet/SlnFileExtensions.cs b/src/dotnet/SlnFileExtensions.cs
index 789318476..84ce82b0d 100644
--- a/src/dotnet/SlnFileExtensions.cs
+++ b/src/dotnet/SlnFileExtensions.cs
@@ -221,7 +221,7 @@ namespace Microsoft.DotNet.Tools.Common
if (projectsToRemove.Count == 0)
{
Reporter.Output.WriteLine(string.Format(
- CommonLocalizableStrings.ProjectReferenceCouldNotBeFound,
+ CommonLocalizableStrings.ProjectNotFoundInTheSolution,
projectPath));
}
else
@@ -244,7 +244,7 @@ namespace Microsoft.DotNet.Tools.Common
slnFile.Projects.Remove(slnProject);
Reporter.Output.WriteLine(
- string.Format(CommonLocalizableStrings.ProjectReferenceRemoved, slnProject.FilePath));
+ string.Format(CommonLocalizableStrings.ProjectRemovedFromTheSolution, slnProject.FilePath));
}
foreach (var project in slnFile.Projects)
diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs
index e79ebfc0c..31d1f716f 100644
--- a/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs
+++ b/src/dotnet/commands/dotnet-add/dotnet-add-reference/Program.cs
@@ -45,9 +45,9 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
var frameworkString = _appliedCommand.ValueOrDefault("framework");
- PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.ReferenceDoesNotExist);
+ PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true);
List refs = _appliedCommand.Arguments
- .Select((r) => MsbuildProject.FromFile(projects, r))
+ .Select((r) => MsbuildProject.FromFileOrDirectory(projects, r))
.ToList();
if (frameworkString == null)
@@ -90,9 +90,10 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference
}
}
- var relativePathReferences = _appliedCommand.Arguments.Select((r) =>
- Path.GetRelativePath(msbuildProj.ProjectDirectory, Path.GetFullPath(r)))
- .ToList();
+ var relativePathReferences = refs.Select((r) =>
+ Path.GetRelativePath(
+ msbuildProj.ProjectDirectory,
+ r.ProjectRootElement.FullPath)).ToList();
int numberOfAddedReferences = msbuildProj.AddProjectToProjectReferences(
frameworkString,
diff --git a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs
index e813dda3a..4f8fabb61 100644
--- a/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs
+++ b/src/dotnet/commands/dotnet-remove/dotnet-remove-reference/Program.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
+using System.IO;
using System.Linq;
using Microsoft.Build.Evaluation;
using Microsoft.DotNet.Cli;
@@ -42,10 +43,22 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference
public override int Execute()
{
var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), _fileOrDirectory);
+ var references = _appliedCommand.Arguments.Select(p => {
+ var fullPath = Path.GetFullPath(p);
+ if (!Directory.Exists(fullPath))
+ {
+ return p;
+ }
+
+ return Path.GetRelativePath(
+ msbuildProj.ProjectRootElement.FullPath,
+ MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName
+ );
+ });
int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences(
_appliedCommand.ValueOrDefault("framework"),
- _appliedCommand.Arguments);
+ references);
if (numberOfRemovedReferences != 0)
{
diff --git a/src/dotnet/commands/dotnet-sln/add/Program.cs b/src/dotnet/commands/dotnet-sln/add/Program.cs
index 9ce0a7d09..d49398ba1 100644
--- a/src/dotnet/commands/dotnet-sln/add/Program.cs
+++ b/src/dotnet/commands/dotnet-sln/add/Program.cs
@@ -40,11 +40,14 @@ namespace Microsoft.DotNet.Tools.Sln.Add
throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneProjectToAdd);
}
- PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.ProjectDoesNotExist);
+ PathUtility.EnsureAllPathsExist(_appliedCommand.Arguments, CommonLocalizableStrings.CouldNotFindProjectOrDirectory, true);
- var fullProjectPaths = _appliedCommand.Arguments
- .Select(Path.GetFullPath)
- .ToList();
+ var fullProjectPaths = _appliedCommand.Arguments.Select(p => {
+ var fullPath = Path.GetFullPath(p);
+ return Directory.Exists(fullPath) ?
+ MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName :
+ fullPath;
+ }).ToList();
var preAddProjectCount = slnFile.Projects.Count;
diff --git a/src/dotnet/commands/dotnet-sln/remove/Program.cs b/src/dotnet/commands/dotnet-sln/remove/Program.cs
index 973294c6e..4952b7c24 100644
--- a/src/dotnet/commands/dotnet-sln/remove/Program.cs
+++ b/src/dotnet/commands/dotnet-sln/remove/Program.cs
@@ -40,11 +40,16 @@ namespace Microsoft.DotNet.Tools.Sln.Remove
{
SlnFile slnFile = SlnFileFactory.CreateFromFileOrDirectory(_fileOrDirectory);
- var relativeProjectPaths = _appliedCommand.Arguments.Select(p =>
- Path.GetRelativePath(
- PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory),
- Path.GetFullPath(p)))
- .ToList();
+ var baseDirectory = PathUtility.EnsureTrailingSlash(slnFile.BaseDirectory);
+ var relativeProjectPaths = _appliedCommand.Arguments.Select(p => {
+ var fullPath = Path.GetFullPath(p);
+ return Path.GetRelativePath(
+ baseDirectory,
+ Directory.Exists(fullPath) ?
+ MsbuildProject.GetProjectFileFromDirectory(fullPath).FullName :
+ fullPath
+ );
+ });
bool slnChanged = false;
foreach (var path in relativeProjectPaths)
diff --git a/src/dotnet/xlf/CommonLocalizableStrings.cs.xlf b/src/dotnet/xlf/CommonLocalizableStrings.cs.xlf
index 56caa7e29..ccc70ef3d 100644
--- a/src/dotnet/xlf/CommonLocalizableStrings.cs.xlf
+++ b/src/dotnet/xlf/CommonLocalizableStrings.cs.xlf
@@ -97,11 +97,6 @@
Aplikace
-
- Reference {0} does not exist.
- Odkaz na {0} neexistuje.
-
-
Reference `{0}` added to the project.
Odkaz na {0} byl přidán do projektu.
@@ -674,6 +669,11 @@
Při spuštění příkazu neprovede implicitní obnovení.
+
+ Project `{0}` removed from the solution.
+ Project `{0}` removed from the solution.
+
+