diff --git a/src/MSBuild.UnitTests/XMake_Tests.cs b/src/MSBuild.UnitTests/XMake_Tests.cs
index bffc0ef9623..ceaf38e0326 100644
--- a/src/MSBuild.UnitTests/XMake_Tests.cs
+++ b/src/MSBuild.UnitTests/XMake_Tests.cs
@@ -1442,6 +1442,23 @@ public void ResponseFileInProjectDirectoryButCommandLineNoAutoResponseSwitch()
output.ShouldContain("[A=]");
}
+ ///
+ /// Directory.Build.rsp in the directory of the specified project/solution should be respected when searching the files (solution/proj) to build.
+ ///
+ [Fact]
+ public void ResponseFileInProjectDirectoryWithSolutionProjectDifferentNamesShouldBeRespected()
+ {
+ var directory = _env.CreateFolder();
+ var content = ObjectModelHelpers.CleanupFileContents("");
+ directory.CreateFile("projectFile.proj", content);
+ directory.CreateFile("solutionFile.sln", string.Empty);
+ directory.CreateFile("Directory.Build.rsp", "-ignoreProjectExtensions:.sln");
+
+ var msbuildParameters = "\"" + directory.Path + "\"";
+ RunnerUtilities.ExecMSBuild(msbuildParameters, out var successfulExit, _output);
+ successfulExit.ShouldBeTrue();
+ }
+
///
/// Any msbuild.rsp in the directory of the specified project/solution should be read, and should
/// take priority over any other response files. Sanity test when there isn't one.
diff --git a/src/MSBuild/XMake.cs b/src/MSBuild/XMake.cs
index 2e4733340a5..773bd785a7e 100644
--- a/src/MSBuild/XMake.cs
+++ b/src/MSBuild/XMake.cs
@@ -307,11 +307,11 @@ private static bool CanRunServerBasedOnCommandLineSwitches(
{
GatherAllSwitches(commandLine, out var switchesFromAutoResponseFile, out var switchesNotFromAutoResponseFile, out string fullCommandLine);
CommandLineSwitches commandLineSwitches = CombineSwitchesRespectingPriority(switchesFromAutoResponseFile, switchesNotFromAutoResponseFile, fullCommandLine);
- if (CheckAndGatherProjectAutoResponseFile(switchesFromAutoResponseFile, commandLineSwitches, false, fullCommandLine, out string projectFile))
+ if (CheckAndGatherProjectAutoResponseFile(switchesFromAutoResponseFile, commandLineSwitches, false, fullCommandLine))
{
commandLineSwitches = CombineSwitchesRespectingPriority(switchesFromAutoResponseFile, switchesNotFromAutoResponseFile, fullCommandLine);
}
-
+ string projectFile = ProcessProjectSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Project], commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.IgnoreProjectExtensions], Directory.GetFiles);
if (commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.Help] ||
commandLineSwitches.IsParameterizedSwitchSet(CommandLineSwitches.ParameterizedSwitch.NodeMode) ||
commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.Version] ||
@@ -2503,7 +2503,7 @@ private static bool ProcessCommandLineSwitches(
}
else
{
- bool foundProjectAutoResponseFile = CheckAndGatherProjectAutoResponseFile(switchesFromAutoResponseFile, commandLineSwitches, recursing, commandLine, out projectFile);
+ bool foundProjectAutoResponseFile = CheckAndGatherProjectAutoResponseFile(switchesFromAutoResponseFile, commandLineSwitches, recursing, commandLine);
if (foundProjectAutoResponseFile)
{
@@ -2556,6 +2556,8 @@ private static bool ProcessCommandLineSwitches(
commandLine);
}
+ projectFile = ProcessProjectSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Project], commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.IgnoreProjectExtensions], Directory.GetFiles);
+
// figure out which targets we are building
targets = ProcessTargetSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Target]);
@@ -2912,18 +2914,43 @@ private static CommandLineSwitches CombineSwitchesRespectingPriority(CommandLine
return commandLineSwitches;
}
- private static bool CheckAndGatherProjectAutoResponseFile(CommandLineSwitches switchesFromAutoResponseFile, CommandLineSwitches commandLineSwitches, bool recursing, string commandLine, out string projectFile)
+ private static string GetProjectDirectory(string[] projectSwitchParameters)
{
- bool found = false;
+ string projectDirectory = ".";
+ ErrorUtilities.VerifyThrow(projectSwitchParameters.Length <= 1, "Expect exactly one project at a time.");
- // figure out what project we are building
- projectFile = ProcessProjectSwitch(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Project], commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.IgnoreProjectExtensions], Directory.GetFiles);
+ if (projectSwitchParameters.Length == 1)
+ {
+ var projectFile = FileUtilities.FixFilePath(projectSwitchParameters[0]);
+
+ if (FileSystems.Default.DirectoryExists(projectFile))
+ {
+ // the provided argument value is actually the directory
+ projectDirectory = projectFile;
+ }
+ else
+ {
+ InitializationException.VerifyThrow(FileSystems.Default.FileExists(projectFile), "ProjectNotFoundError", projectFile);
+ projectDirectory = Path.GetDirectoryName(Path.GetFullPath(projectFile));
+ }
+ }
+
+ return projectDirectory;
+ }
+
+
+ ///
+ /// Identifies if there is rsp files near the project file
+ ///
+ /// true if there autoresponse file was found
+ private static bool CheckAndGatherProjectAutoResponseFile(CommandLineSwitches switchesFromAutoResponseFile, CommandLineSwitches commandLineSwitches, bool recursing, string commandLine)
+ {
+ bool found = false;
+
+ var projectDirectory = GetProjectDirectory(commandLineSwitches[CommandLineSwitches.ParameterizedSwitch.Project]);
if (!recursing && !commandLineSwitches[CommandLineSwitches.ParameterlessSwitch.NoAutoResponse])
{
- // gather any switches from an msbuild.rsp that is next to the project or solution file itself
- string projectDirectory = Path.GetDirectoryName(Path.GetFullPath(projectFile));
-
// gather any switches from the first Directory.Build.rsp found in the project directory or above
string directoryResponseFile = FileUtilities.GetPathOfFileAbove(directoryResponseFileName, projectDirectory);
@@ -3377,7 +3404,7 @@ internal static string ProcessProjectSwitch(
string[] projectsExtensionsToIgnore,
DirectoryGetFiles getFiles)
{
- ErrorUtilities.VerifyThrow(parameters.Length <= 1, "It should not be possible to specify more than 1 project at a time.");
+ ErrorUtilities.VerifyThrow(parameters.Length <= 1, "Expect exactly one project at a time.");
string projectFile = null;
string projectDirectory = null;