8000 Allow `@` as separator in `#:package` (#48542) · Forgind/sdk@600b00d · GitHub
[go: up one dir, main page]

Skip to content

Commit 600b00d

Browse files
authored
Allow @ as separator in #:package (dotnet#48542)
1 parent 7532b5d commit 600b00d

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

documentation/general/dotnet-run-file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Other directives result in a warning, reserving them for future use.
186186
#:sdk Microsoft.NET.Sdk.Web
187187
#:property TargetFramework net11.0
188188
#:property LangVersion preview
189-
#:package System.CommandLine 2.0.0-*
189+
#:package System.CommandLine@2.0.0-*
190190
```
191191

192192
The value must be separated from the name of the directive by white space and any leading and trailing white space is not considered part of the value.

src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#nullable enable
55

6+
using System.Buffers;
67
using System.Collections.Immutable;
78
using System.Diagnostics;
89
using System.Security;
@@ -814,9 +815,11 @@ public static CSharpDirective Parse(SourceFile sourceFile, TextSpan span, string
814815
};
815816
}
816817

817-
private static (string, string?) ParseOptionalTwoParts(SourceFile sourceFile, TextSpan span, string directiveKind, string directiveText)
818+
private static (string, string?) ParseOptionalTwoParts(SourceFile sourceFile, TextSpan span, string directiveKind, string directiveText, SearchValues<char>? separators = null)
818819
{
819-
var i = directiveText.IndexOf(' ', StringComparison.Ordinal);
820+
var i = separators != null
821+
? directiveText.AsSpan().IndexOfAny(separators)
822+
: directiveText.IndexOf(' ', StringComparison.Ordinal);
820823
var firstPart = checkFirstPart(i < 0 ? directiveText : directiveText[..i]);
821824
var secondPart = i < 0 ? [] : directiveText.AsSpan((i + 1)..).TrimStart();
822825
if (i < 0 || secondPart.IsWhiteSpace())
@@ -912,14 +915,16 @@ private Property() { }
912915
/// </summary>
913916
public sealed class Package : CSharpDirective
914917
{
918+
private static readonly SearchValues<char> s_separators = SearchValues.Create(' ', '@');
919+
915920
private Package() { }
916921

917922
public required string Name { get; init; }
918923
public string? Version { get; init; }
919924

920925
public static new Package Parse(SourceFile sourceFile, TextSpan span, string directiveKind, string directiveText)
921926
{
922-
var (packageName, packageVersion) = ParseOptionalTwoParts(sourceFile, span, directiveKind, directiveText);
927+
var (packageName, packageVersion) = ParseOptionalTwoParts(sourceFile, span, directiveKind, directiveText, s_separators);
923928

924929
return new Package
925930
{

test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ public void Directives_Separators()
407407
#:sdk Third 3.0=a/b
408408
#:package P1 1.0/a=b
409409
#:package P2 2.0/a=b
410+
#:package P3@1.0 ab
410411
""",
411412
expectedProject: $"""
412413
<Project Sdk="First/1.0=a/b">
@@ -429,6 +430,7 @@ public void Directives_Separators()
429430
<ItemGroup>
430431
<PackageReference Include="P1" Version="1.0/a=b" />
431432
<PackageReference Include="P2" Version="2.0/a=b" />
433+
<PackageReference Include="P3" Version="1.0 ab" />
432434
</ItemGroup>
433435
434436
</Project>

0 commit comments

Comments
 (0)
0