format icon indicating copy to clipboard operation
format copied to clipboard

Do not throw "Both a MSBuild project file and solution file found" when the solution is just pointing to a single project file

Open xPaw opened this issue 10 months ago • 2 comments

... or always format the solution. I don't see why it needs to throw this error at all when presumably it accepts the solution file pointing to multiple projects as long as they are in other folders.

xPaw avatar Feb 07 '25 09:02 xPaw

Looks like MSBuild will take the solution when they both have the same name. See https://github.com/dotnet/msbuild/blob/a51113d69ff0667528ca5dc8e2775f3c912f2e65/src/MSBuild/XMake.cs#L3577

JoeRobich avatar Feb 08 '25 00:02 JoeRobich

This doesn't seem to work for me:

-a---          03/02/2025    14:43           2218 SteamDatabaseBackend.csproj
-a---          07/11/2024    13:20           2777 SteamDatabaseBackend.sln


$ dotnet format
Unhandled exception: System.IO.FileNotFoundException: Both a MSBuild project file and solution file found in x. Specify which to use with the <workspace> argument
   at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindWorkspace(String searchDirectory, String workspacePath)
   at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindWorkspace(String searchDirectory, String workspacePath)
   at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.ParseWorkspaceOptions(ParseResult parseResult, FormatOptions formatOptions)
   at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
   at System.CommandLine.Invocation.InvocationPipeline.InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)

$ dotnet --version
9.0.102

xPaw avatar Feb 08 '25 09:02 xPaw

Is there a workaround while we wait for this to be changed?

BrBill avatar May 02 '25 23:05 BrBill

@BrBill simply reference one or the other. In the example from above dotnet format SteamDatabaseBackend.sln would work.

JoeRobich avatar May 03 '25 00:05 JoeRobich