Skip to content

Commit 301f9e9

Browse files
authored
Fail when #:project doesn't have any argument (#49711)
1 parent f0fc999 commit 301f9e9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ private CSharpDirective() { }
10541054
"sdk" => Sdk.Parse(errors, sourceFile, span, directiveKind, directiveText),
10551055
"property" => Property.Parse(errors, sourceFile, span, directiveKind, directiveText),
10561056
"package" => Package.Parse(errors, sourceFile, span, directiveKind, directiveText),
1057-
"project" => Project.Parse(errors, sourceFile, span, directiveText),
1057+
"project" => Project.Parse(errors, sourceFile, span, directiveKind, directiveText),
10581058
_ => ReportError<Named>(errors, sourceFile, span, string.Format(CliCommandStrings.UnrecognizedDirective, directiveKind, sourceFile.GetLocationString(span))),
10591059
};
10601060
}
@@ -1213,8 +1213,13 @@ public sealed class Project : Named
12131213
{
12141214
private Project() { }
12151215

1216-
public static Project Parse(ImmutableArray<SimpleDiagnostic>.Builder? errors, SourceFile sourceFile, TextSpan span, string directiveText)
1216+
public static new Project? Parse(ImmutableArray<SimpleDiagnostic>.Builder? errors, SourceFile sourceFile, TextSpan span, string directiveKind, string directiveText)
12171217
{
1218+
if (directiveText.IsWhiteSpace())
1219+
{
1220+
return ReportError<Project?>(errors, sourceFile, span, string.Format(CliCommandStrings.MissingDirectiveName, directiveKind, sourceFile.GetLocationString(span)));
1221+
}
1222+
12181223
try
12191224
{
12201225
// If the path is a directory like '../lib', transform it to a project file path like '../lib/lib.csproj'.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ public void Directives_Empty()
810810

811811
[Theory, CombinatorialData]
812812
public void Directives_EmptyName(
813-
[CombinatorialValues("sdk", "property", "package")] string directive,
813+
[CombinatorialValues("sdk", "property", "package", "project")] string directive,
814814
[CombinatorialValues(" ", "")] string value)
815815
{
816816
VerifyConversionThrows(

0 commit comments

Comments
 (0)