Skip to content

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 a team and Copilot 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

{
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