Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Sep 17, 2025

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.

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Sep 17, 2025
/// Overriding default (implicit) properties of file-based apps from custom SDKs.
/// </summary>
[Fact]
public void DefaultProps_CustomSdk()
Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

@jjonescz jjonescz added this to the 10.0.1xx milestone Sep 17, 2025
@jjonescz jjonescz marked this pull request as ready for review September 17, 2025 14:58
@jjonescz jjonescz requested review from a team and Copilot September 17, 2025 14:58
Copy link
Contributor

@Copilot Copilot AI left a 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

@jjonescz jjonescz requested a review from MiYanni September 18, 2025 07:57
@jjonescz
Copy link
Member Author

@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($"""
Copy link
Member

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.

Copy link
Member Author

@jjonescz jjonescz Sep 22, 2025

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.

@baronfel baronfel enabled auto-merge (squash) September 22, 2025 13:33
@jjonescz jjonescz disabled auto-merge September 23, 2025 10:33
@jjonescz jjonescz changed the base branch from release/10.0.1xx to release/10.0.1xx-rc2 September 23, 2025 10:35
@jjonescz jjonescz merged commit 8a23772 into dotnet:release/10.0.1xx-rc2 Sep 23, 2025
29 of 30 checks passed
@jjonescz jjonescz deleted the sprint-default-props branch September 23, 2025 15:33
@jjonescz
Copy link
Member Author

/backport to release/10.0.1xx

Copy link
Contributor

Started backporting to release/10.0.1xx: https://github.com/dotnet/sdk/actions/runs/18003925004

Copy link
Contributor

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-run-file Items related to the "dotnet run <file>" effort Servicing-approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants