Skip to content

Expand MSBuild properties across launch profiles - #56074

Merged
tannergooding merged 7 commits into
dotnet:mainfrom
tannergooding:tannergooding-handle-pr-56051-feedback
Sep 4, 2026
Merged

Expand MSBuild properties across launch profiles#56074
tannergooding merged 7 commits into
dotnet:mainfrom
tannergooding:tannergooding-handle-pr-56051-feedback

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Expands MSBuild properties consistently across all supported launch-profile string fields using the same token replacement behavior as Visual Studio. This covers Project and Executable profiles for project and file-based dotnet run, plus MTP test launches; Native AOT defers before launch when selected values require MSBuild.

This follows up #56051 and addresses the post-merge feedback.

cc @baronfel @jjonescz

Note

This pull request was drafted with GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 1, 2026 15:56
@tannergooding
tannergooding requested review from a team as code owners September 1, 2026 15:56
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 2 Medium severity

New issues introduced by this change (2)
Severity Finding
Medium severity src/​Microsoft.DotNet.ProjectTools/​LaunchSettings/​LaunchProfileParser.cs — MSBuildPropertyRegex (\$\([^)]+\)) treats the first ) as the end of the token, which breaks…
Medium severity src/​Microsoft.DotNet.ProjectTools/​LaunchSettings/​LaunchSettings.csReadProfileSettingsFromFile only catches JsonException/IOException, but…
What changed in this PR

Expands launch-profile MSBuild property evaluation beyond commandLineArgs, so dotnet run (project + file-based) and MTP test launches consistently expand MSBuild properties in supported launch-profile string fields, aligning with Visual Studio’s token replacement behavior. Adds Native AOT guards to fall back to managed execution when MSBuild evaluation would be required.

Changes:

  • Plumbs an optional expandMSBuildProperty callback through launch profile discovery/parsing and expands MSBuild properties across additional fields (executable path, working directory, applicationUrl/launchUrl, env vars).
  • Updates dotnet run to lazily evaluate the project only when launch settings contain MSBuild property tokens.
  • Adds/updates integration and unit tests for project, executable, file-based run, MTP, and Native AOT fallback behavior.
File Description
test/​dotnet.Tests/​ProjectTools/​LaunchSettingsParserTests.cs Adds unit coverage for MSBuild expansion in executable/project profile fields.
test/​dotnet.Tests/​CommandTests/​Test/​GivenDotnetTestBuildsAndRunsTests.cs Updates MTP test launch scenario to validate MSBuild property expansion via evaluated props.
test/​dotnet.Tests/​CommandTests/​Run/​RunFileTests_BuildCommands.cs Adds file-based dotnet run test validating MSBuild property expansion in .run.json.
test/​dotnet.Tests/​CommandTests/​Run/​RunCommandTests.cs Extends run command tests to validate env var + property-function expansion and executable profile expansion.
test/​dotnet.Tests/​CommandTests/​Run/​GivenDotnetRunBuildsCsProj.cs Updates applicationUrl test to validate MSBuild property expansion feeding ASPNETCORE_URLS.
test/​dotnet-aot.Tests/​AotRunCommandTests.cs Adds Native AOT fallback tests when MSBuild expansion is required by launch profile fields.
src/​Microsoft.DotNet.ProjectTools/​LaunchSettings/​ProjectLaunchProfileParser.cs Expands MSBuild properties in additional Project profile fields (args/url/env vars).
src/​Microsoft.DotNet.ProjectTools/​LaunchSettings/​LaunchSettings.cs Threads expandMSBuildProperty through file-based profile reading and provider parsing.
src/​Microsoft.DotNet.ProjectTools/​LaunchSettings/​LaunchProfileParser.cs Introduces MSBuild property detection + expansion helper using a regex-based replacer.
src/​Microsoft.DotNet.ProjectTools/​LaunchSettings/​ExecutableLaunchProfileParser.cs Expands MSBuild properties in executable path/args/working dir/env vars.
src/​Cli/​dotnet/​Commands/​Test/​MTP/​SolutionAndProjectUtility.cs Enables MSBuild property expansion in MTP launch profile parsing via project.ExpandString.
src/​Cli/​dotnet/​Commands/​Run/​RunCommand.cs Lazily supplies MSBuild expansion callback (evaluates project on demand for expansion).
src/​Cli/​dotnet/​Commands/​Run/​CommonRunHelpers.cs Plumbs expandMSBuildProperty through shared launch-profile reader.
src/​Cli/​dotnet/​Commands/​Run/​AotRunCommand.cs Adds enforcement that MSBuild-property-containing launch profiles must fall back to managed.

Comment thread src/Microsoft.DotNet.ProjectTools/LaunchSettings/LaunchSettings.cs Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 Medium severity

New issues introduced by this change (1)
Severity Finding
Medium severity src/​Cli/​dotnet/​Commands/​Run/​RunCommand.csReadLaunchProfileSettings now passes an MSBuild expansion callback into the launch-settings…
Issues resolved since last review (2)
Severity Finding
Medium severity src/​Microsoft.DotNet.ProjectTools/​LaunchSettings/​LaunchSettings.csReadProfileSettingsFromFile only catches JsonException/IOException, but… View resolved comment
Medium severity src/​Microsoft.DotNet.ProjectTools/​LaunchSettings/​LaunchProfileParser.cs — MSBuildPropertyRegex (\$\([^)]+\)) treats the first ) as the end of the token, which breaks… View resolved comment

Comment thread src/Cli/dotnet/Commands/Run/RunCommand.cs Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread src/Cli/dotnet/Commands/Run/RunCommand.cs Outdated
Comment thread src/Microsoft.DotNet.ProjectTools/LaunchSettings/ExecutableLaunchProfileParser.cs Outdated
Comment thread test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs
Comment thread src/Cli/dotnet/Commands/Run/RunCommand.cs

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found three correctness regressions in expansion timing and project selection. The inline comments cover ignored profile arguments becoming failure sources, expansion occurring before restore/ComputeRunArguments, and run --api using the wrong artifacts path during expansion.

Note

This review was generated with AI assistance.

Comment thread src/Microsoft.DotNet.ProjectTools/LaunchSettings/LaunchProfileParser.cs Outdated
Comment thread src/Cli/dotnet/Commands/Run/RunCommand.cs
Comment thread src/Cli/dotnet/Commands/Run/RunCommand.cs Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding requested a review from a team as a code owner September 2, 2026 14:12
Comment thread src/Cli/dotnet/Commands/Run/RunCommand.cs Outdated

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The revised implementation resolves the previous expansion-timing and project-selection findings. One user-visible diagnostic regression remains in the Executable-profile reparse path.

Note

This review was generated with AI assistance.

Comment thread src/Cli/dotnet/Commands/Run/RunCommand.cs
Comment thread src/Dotnet.Watch/Watch/Process/LaunchSettingsProfile.cs Outdated
Comment thread src/Microsoft.DotNet.ProjectTools/LaunchSettings/ExecutableLaunchProfileParser.cs Outdated
tannergooding and others added 2 commits September 2, 2026 11:52
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No further code issues found. I rechecked the deferred expansion paths across dotnet run, run-api, MTP, dotnet watch, and Native AOT; the prior findings are resolved and the new diagnostic-deduplication test covers the last regression.

The remaining red CI result is an unrelated macOS dotnet-new.IntegrationTests.dll.1 hang that Helix classified as InfrastructureError; the affected work item timed out after 48 minutes while unrelated template tests were running.

Note

This review was generated with AI assistance.

Comment thread test/dotnet.Tests/ProjectTools/LaunchSettingsParserTests.cs Outdated
Comment thread src/Microsoft.DotNet.ProjectTools/LaunchSettings/LaunchProfileParser.cs Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding

Copy link
Copy Markdown
Member Author

@jjonescz fixed the two nits here, should be good to merge after reapproval

@tannergooding
tannergooding merged commit c876572 into dotnet:main Sep 4, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants