Skip to content

Handle versioned #:sdk being first #49807

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

Merged
merged 1 commit into from
Jul 22, 2025

Conversation

jjonescz
Copy link
Member

Fixes #49797.

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Jul 16, 2025
@jjonescz jjonescz marked this pull request as ready for review July 16, 2025 14:19
@jjonescz jjonescz requested review from Copilot and a team July 16, 2025 14:19
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 fixes issue 49797 by ensuring versioned #:sdk directives at the top of a C# script are handled correctly for both dotnet run and dotnet project convert.

  • Added SdkReference_VersionedSdkFirst test in RunFileTests.cs
  • Added Directives_VersionedSdkFirst test in DotnetProjectConvertTests.cs
  • Updated VirtualProjectBuildingCommand to split SDK name and version, adjust imports, and remove the old ToSlashDelimitedString method

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
test/dotnet.Tests/CommandTests/Run/RunFileTests.cs New fact validating build when a versioned #:sdk is first
test/dotnet.Tests/CommandTests/Project/Convert/...ConvertTests.cs New fact validating conversion when a versioned #:sdk is first
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs Logic to correctly handle first versioned SDK directive and adjust import statements

@jjonescz
Copy link
Member Author

@RikkiGibson @jaredpar please review a small but important bugfix, thanks

@jjonescz
Copy link
Member Author

@RikkiGibson @333fred for reviews, thanks

}
else
{
string slashDelimited = firstSdkVersion is null
? firstSdkName
: $"{firstSdkName}/{firstSdkVersion}";
Copy link
Member

Choose a reason for hiding this comment

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

More of an abstract question, but given that this is a syntax that project files support today, it seems reasonable that users may expect to write #:sdk MySdk/1.0. Is that something we support or plan to support?

Copy link
Member Author

Choose a reason for hiding this comment

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

We used to support that but we unified on a single separator in #48841 to avoid having different syntaxes in the wild leading to confusions. If user writes #:sdk MySdk/1.0 they should get an error message which tells them to use @ instead.

@jjonescz jjonescz merged commit ab9e137 into dotnet:main Jul 22, 2025
30 checks passed
@jjonescz jjonescz deleted the sprint-sdk-version-first branch July 22, 2025 16:34
@jjonescz
Copy link
Member Author

/backport to release/10.0.1xx-preview7

Copy link
Contributor

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

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dotnet app.cs #:sdk directive pinned version results in The SDK 'Sdk/Version' specified could not be found.
4 participants