-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add warning when using --framework with solution files #51561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Added NETSDK1234 warning string in Strings.resx - Modified FrameworkOption to set _CommandLineDefinedTargetFramework property - Added _CheckForSolutionLevelTargetFramework target in Microsoft.NET.Sdk.Solution.targets - Created FrameworkOptionTests.cs with test cases for the new warning Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Manual testing confirms the feature works correctly: - Using --framework on solution shows NETSDK1234 warning - Using --property:TargetFramework does not show warning - Warning appears for build, clean, publish, and test commands Changes: - Added NETSDK1234 warning string in Strings.resx - Modified FrameworkOption to set _CommandLineDefinedTargetFramework property - Added _CheckForSolutionLevelTargetFramework target in Microsoft.NET.Sdk.Solution.targets Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
|
@baronfel in the spirit of limiting new warnings, should we only spit out this warning if the TFM is net11? People are definitely going to hit it. |
|
The problem (similar to the output path) is that we don't know at the solution-level that these targets run at if the projects target 11. We probably should create a Target similar to what Restore does and have the solution gather the TFMs of the project and flag if the TFM is present. |
|
Does this warn when |
|
Added When you commit this breaking change:
You can refer to the .NET SDK breaking change guidelines |
|
@copilot can you change the test to say "isn't recommended" rather than "isn't supported" |
|
Updated NETSDK1234 warning text per feedback to be less severe. Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Changed warning text from "isn't supported" to "isn't recommended" in commit 35d513c. Updated warning output: |
|
Cc @Youssef1313 and @nohwnd |
|
@copilot fix the merge conflict |
Resolved conflict in CommonOptions.cs by adapting to the new Option structure: - Uses Option<string> instead of DynamicForwardedOption<string> - Sets IsDynamic = true - Uses ForwardAsMany to forward both TargetFramework and _CommandLineDefinedTargetFramework properties - Maintains AddCompletions at the end
|
That sounds like a non-trivial breaking change. But as long as it applies to Build, I'm fine with applying it to everything else (test, both MTP and VSTest, publish, etc..). |
| <Target Name="_CheckForSolutionLevelTargetFramework" | ||
| BeforeTargets="Build;Publish;Clean;Store;VSTest;_MTPBuild" | ||
| Condition="'$(_CommandLineDefinedTargetFramework)' == 'true'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this condition make sense? Users will still be able to bypass that with -p:TargetFramework=...? Is it intended to allow the bypass? If yes, IMO deserves a comment saying it explicitly and demonstrating why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the bypass via -p:TargetFramework=... is intentional. Users who set the property directly are in an advanced scenario and likely understand the implications. Added a comment in commit 5184f8d explaining this design decision.
| </Target> | ||
|
|
||
| <Target Name="_CheckForSolutionLevelTargetFramework" | ||
| BeforeTargets="Build;Publish;Clean;Store;VSTest;_MTPBuild" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: for the case of dotnet test --no-build -f ..., this target isn't going to run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct. Since --no-build means the Build target doesn't run, the warning won't appear. This is the desired behavior as no building occurs that could cause the double-build issue.
|
|
||
| </Target> | ||
|
|
||
| <Target Name="_CheckForSolutionLevelTargetFramework" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need Pack as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added Pack to the BeforeTargets list in commit 5184f8d for consistency, though dotnet pack doesn't currently support the --framework option.
|
|
||
| </Target> | ||
|
|
||
| <Target Name="_CheckForSolutionLevelTargetFramework" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it fine during restore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During restore, the TargetFramework property affects dependency resolution but doesn't cause the double-build issue described in the original problem. The warning focuses on build-related targets where the issue manifests.
|
I'd love to see some tests here for the affected commands, to ensure it doesn't break with any future refactorings. |
Testing some libraries on both .NET Framework and .NET Core, and collecting the test results from different frameworks to different files so that a web UI can easily display them as separate. |
|
Also worth noting that this scenario could be quite different between VSTest and MTP per the current way it's implemented. In VSTest, we always go through the VSTest target, and there we decide if |
|
@copilot fix the merge conflict |
- Added XML comment explaining that the condition only triggers with --framework CLI option - Added explanation that -p:TargetFramework bypass is intentional for advanced scenarios - Added Pack to BeforeTargets list (though pack doesn't support --framework currently) Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
- Created FrameworkOptionTests similar to OutputPathOptionTests - Tests verify warning appears for build, clean, publish, test commands - Tests verify no warning when using --property:TargetFramework directly - Note: test command output capture may have timing issues in test harness Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Added FrameworkOptionTests in commit 79e54a7, following the same pattern as OutputPathOptionTests. The tests cover build, clean, publish, and test commands, verifying both the warning appears with
Merge conflict resolved in commit 1a2cbb7. Changed warning code from NETSDK1234 to NETSDK1235 since NETSDK1234 is now used for RoslynCompilerType deprecation warning in main. Both warnings now coexist in Strings.resx. |
NETSDK1234 is already used in main for RoslynCompilerType deprecation warning. Updated to use NETSDK1235 for the framework option warning. Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Resolved conflicts: - Updated Strings.resx to include both NETSDK1234 (RoslynCompilerType) and NETSDK1235 (framework option) - Accepted main's version for unrelated file conflicts in eng/, src/BuiltInTools/, template_feed/, and test files
Summary: Add warning when using
--frameworkwith solution filesThis PR addresses the issue where using
--frameworkon a solution build can cause referenced projects to build multiple times, leading to inconsistent builds and file locking issues.Changes Made
_CommandLineDefinedTargetFramework=trueproperty-p:TargetFrameworkis intentional for advanced scenariosImplementation Details
Similar to the existing
-o/--outputwarning (NETSDK1194), this adds warning NETSDK1235 when users specify--frameworkon a solution build.How it works:
--frameworkis used, the CLI forwards both--property:TargetFramework=<value>and--property:_CommandLineDefinedTargetFramework=true_CommandLineDefinedTargetFrameworkproperty--property:TargetFramework=<value>directly does NOT trigger the warning (intentional bypass for advanced scenarios, documented in code comments)dotnet test --no-build, the warning won't appear as the Build target doesn't run (expected behavior)Example Output
Original prompt
This section details on the original issue you should resolve
<issue_title>dotnet build --framework builds referenced project twice</issue_title>
<issue_description><!--
Please keep in mind that the GitHub issue tracker is not intended as a general support forum, but for reporting non-security bugs and feature requests.
If you believe you have an issue that affects the SECURITY of the platform, please do NOT create an issue and instead email your issue details to secure@microsoft.com. Your report may be eligible for our bug bounty but ONLY if it is reported through email.
For other types of questions, consider using StackOverflow.
-->
Describe the bug
dotnet buildwith--frameworkbuilds the same project twice in parallel, if it is referenced by a solution and a ProjectReference. Without--framework, it builds only once.To Reproduce
Dep.sln
One/One.csproj
One/Class1.cs
Two/Two.csproj
Log of
dotnet build --framework net6.0becoming unexpectedly parallel and attempting to access a locked file