Added --framework arg to "dotnet format" to set TFM #53202
Added --framework arg to "dotnet format" to set TFM #53202Hextaku wants to merge 3 commits intodotnet:mainfrom
Conversation
- Alias -f is set - does only work without --folder
|
@dotnet-policy-service agree |
Passing a target framework to `dotnet restore` causes the dotnet CLI in SDK 10.0.x to emit a bare --framework switch in its internal MSBuild.dll invocation. MSBuild does not recognise that switch and exits with MSB1001. The framework argument is unnecessary for restore: dotnet restore on a solution or project already restores all target frameworks. Framework filtering is handled downstream by MSBuildWorkspaceLoader, which sets the TargetFramework MSBuild property when opening the workspace.
| </trans-unit> | ||
| <trans-unit id="Cannot_specify_the_folder_option_with_framework"> | ||
| <source>Cannot specify the '--folder' option with '--framework'.</source> | ||
| <target state="translated">Non è possibile specificare l'opzione '--folder' con '--framework'.</target> |
There was a problem hiding this comment.
Please remove these translations. Our translation team will handle it.
| { | ||
| internal static class DotNetHelper | ||
| { | ||
| internal static string BuildRestoreArguments(string workspaceFilePath) |
There was a problem hiding this comment.
Make this a local function of PerformRestoreAsync after the return
There was a problem hiding this comment.
Actually just revert this change and remove the added tests for it.
|
The original bug called out running into merge conflict issues as a motivation for this flag; is that the motivation here now, or is this needed for some other reason? I can imagine some other needs, but if the only motivation was the merge conflicts, then I'd hope that isn't something we can just address directly. |
My main motivation here were the merge conflicts. But looking at the problem, I quickly realized that it's also preferable to reduce the target frameworks to only one a lot of times. Aside from that, I think it could be quite useful in some CI cases, but there's currently no need on my side. |
I was really annoyed by #41899 which describes a problem with "dotnet format" when projects have multiple target frameworks, so I added support for a --framework argument to it to specify a single TFM.
Implemented Solution:
New argument "--framework" with alias "-f" which takes a TFM and restricts restore and analysis to the specified framework only.
Unit tests similar to existing dotnet format tests.
Remarks