-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allow SDKs to overwrite default file-based app properties #50885
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
Allow SDKs to overwrite default file-based app properties #50885
Conversation
/// Overriding default (implicit) properties of file-based apps from custom SDKs. | ||
/// </summary> | ||
[Fact] | ||
public void DefaultProps_CustomSdk() |
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.
@DamianEdwards is the behavior captured by this test conceptually what you want to have working for aspire sdk?
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.
I think so, yes. IIUC it's demonstrating a file-based app referencing a custom SDK, and that SDK disables implicit usings, which is something explicitly defaulted to on for file-based apps. We should then be able to achieve the same thing for AOT publishing.
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, if your SDK wants to customize some properties in its Sdk.props like this, that should work.
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.
Pull Request Overview
This PR enables SDKs to override default file-based app properties by reorganizing how properties are written in generated project files. The key change is moving default properties before SDK imports so SDKs can override them through their own props files.
- Reorganized property writing order to allow SDK overrides of default properties
- Added logic to exclude overridden default properties when converting to project files
- Added comprehensive tests for both Directory.Build.props and custom SDK scenarios
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
VirtualProjectBuildingCommand.cs | Restructured project file generation to write default properties before SDK imports and added exclusion logic |
ProjectConvertCommand.cs | Added property evaluation logic to exclude overridden default properties during conversion |
RunFileTests.cs | Added new test cases and updated expected project file content to reflect new property ordering |
@MiYanni for a review, thanks |
// (and implicit build files which are imported by the default .NET SDK). | ||
foreach (var (name, value) in DefaultProperties) | ||
{ | ||
writer.WriteLine($""" |
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.
nit: IMO we shouldn't be writing raw XML project files like this. If the MSbuild in-memory object APIs don't make it convenient to create the structures we need I'd love to see issues raised calling out the pain points. Raw XML ties us to the format rather than the logical values we're trying to control.
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.
This was discussed previously: #47702 (comment)
Opened dotnet/msbuild#12553.
/backport to release/10.0.1xx |
Started backporting to release/10.0.1xx: https://github.com/dotnet/sdk/actions/runs/18003925004 |
@jjonescz backporting to "release/10.0.1xx" failed, the patch most likely resulted in conflicts: $ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Allow SDKs to overwrite default file-based app properties
Using index info to reconstruct a base tree...
M src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
M src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
M test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
CONFLICT (content): Merge conflict in src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs
Auto-merging src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
CONFLICT (content): Merge conflict in src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
Auto-merging test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
CONFLICT (content): Merge conflict in test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Allow SDKs to overwrite default file-based app properties
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
Description and customer impact
While @DamianEdwards was implementing dotnet/aspire#11445 we found that file-based apps set default properties in such a way that defaults/values from Imported SDKs can't see/act on them. We want SDKs to be able to detect and modify behavior based on file-based-app-ed-ness (that's definitely a word) and so by changing the declaration order somewhat we can preserve that ability.
Regression
No, this never worked.
Risk
Low, this is a new feature in .NET 10. Unit tests verify the behavior.