Repository: dotnet-script/dotnet-script (csharp)

Issue:
Shebang directive on top of the file breaks #r SDK parsing
In the Specifying an sdk u show an example creating a web app:

#r "sdk:Microsoft.NET.Sdk.Web"

using Microsoft.AspNetCore.Builder;

var a = WebApplication.Create();
a.MapGet("/", () => "Hello world");
a.Run();

====

I get error  saying 'AspNetCore' does not exist in namespace 'Microsoft'.

Has this changed?

environment:
Mac osx ARM
i have Core6 and Core7 Frameworks installed. Currently using Core7.

I created project using command as shown in doc $> dotnet script init

thx ~Marvin Foster
mmarvb7@gmail.com or marvinfoster@finsync.com

Pull request description:
Fixes #723 

Also added test.

Patch:
diff --git a/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptParser.cs b/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptParser.cs
index 0d058a21..9222a220 100644
--- a/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptParser.cs
+++ b/src/Dotnet.Script.DependencyModel/ProjectSystem/ScriptParser.cs
@@ -53,7 +53,7 @@ public ParseResult ParseFromFiles(IEnumerable<string> csxFiles)
         private static string ReadSdkFromReferenceDirective(string fileContent)
         {
             const string pattern = DirectivePatternPrefix + "r" + SdkDirectivePatternSuffix;
-            var match = Regex.Match(fileContent, pattern);
+            var match = Regex.Match(fileContent, pattern, RegexOptions.Multiline);
             if (match.Success)
             {
                 var sdk = match.Groups[1].Value;


Test patch:
diff --git a/src/Dotnet.Script.Tests/ScriptProjectProviderTests.cs b/src/Dotnet.Script.Tests/ScriptProjectProviderTests.cs
index 9d87775f..fdc3bc03 100644
--- a/src/Dotnet.Script.Tests/ScriptProjectProviderTests.cs
+++ b/src/Dotnet.Script.Tests/ScriptProjectProviderTests.cs
@@ -40,5 +40,17 @@ public void ShouldUseSpecifiedSdk()
             var projectFileInfo = provider.CreateProject(TestPathUtils.GetPathToTestFixtureFolder("WebApi"), _scriptEnvironment.TargetFramework, true);
             Assert.Equal("Microsoft.NET.Sdk.Web", XDocument.Load(projectFileInfo.Path).Descendants("Project").Single().Attributes("Sdk").Single().Value);
         }
+
+        // See: https://github.com/dotnet-script/dotnet-script/issues/723
+        [Theory]
+        [InlineData("#!/usr/bin/env dotnet-script\n#r \"sdk:Microsoft.NET.Sdk.Web\"")]
+        [InlineData("#!/usr/bin/env dotnet-script\n\n#r \"sdk:Microsoft.NET.Sdk.Web\"")]
+        public void ShouldHandleShebangBeforeSdk(string code)
+        {
+            var parser = new ScriptParser(TestOutputHelper.CreateTestLogFactory());
+            var result = parser.ParseFromCode(code);
+
+            Assert.Equal("Microsoft.NET.Sdk.Web", result.Sdk);
+        }
     }
 }
\ No newline at end of file