Skip to content
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

Shebang directive on top of the file breaks #r SDK parsing #723

Open
marvfinsy opened this issue May 19, 2023 · 10 comments
Open

Shebang directive on top of the file breaks #r SDK parsing #723

marvfinsy opened this issue May 19, 2023 · 10 comments
Labels

Comments

@marvfinsy
Copy link

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

@vladslavin
Copy link

vladslavin commented May 31, 2023

Same issue, SDK is installed 🤷‍♂️

Version             : 1.4.0
Install location    : /Users/slavin/.dotnet/tools/.store/dotnet-script/1.4.0/dotnet-script/1.4.0/tools/net7.0/any
Target framework    : net7.0
.NET Core version   : 7.0.5
Platform identifier : osx
Runtime identifier  : osx-x64

@filipw
Copy link
Member

filipw commented Jun 5, 2023

it works on my machine™️ 😀
please run dotnet script {your csx file} --verbosity d --no-cache and post the output here.

@vladslavin
Copy link

➜ dotnet script index.csx --verbosity d --no-cache

dbug: Dotnet.Script.Core.Commands.ExecuteScriptCommand[0]
      The script /Users/slavin/source/test/index.csx was executed with the '--no-cache' flag. Skipping cache.
info: Dotnet.Script.Core.ScriptCompiler[0]
      Current runtime is 'osx'.
dbug: Dotnet.Script.DependencyModel.ProjectSystem.ScriptProjectProvider[0]
      Creating project file for /Users/slavin/source/test/index.csx
dbug: Dotnet.Script.DependencyModel.ProjectSystem.ScriptParser[0]
      Parsing /Users/slavin/source/test/index.csx
dbug: Dotnet.Script.DependencyModel.ProjectSystem.ScriptProjectProvider[0]
      Project file saved to /Users/slavin/Library/Caches/dotnet-script/Users/slavin/source/test/net7.0/script.csproj
dbug: Dotnet.Script.DependencyModel.ProjectSystem.ScriptProjectProvider[0]
      <?xml version="1.0" encoding="utf-8"?>
      <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
          <OutputType>Exe</OutputType>
          <TargetFramework>net7.0</TargetFramework>
          <LangVersion>latest</LangVersion>
        </PropertyGroup>
        <ItemGroup></ItemGroup>
        <Target Name="RecordReferencePaths" AfterTargets="AfterResolveReferences">
          <WriteLinesToFile File="$(OutputPath)/ReferencePaths.txt" Lines="@(ReferencePath)" />
        </Target>
      </Project>
dbug: Dotnet.Script.DependencyModel.Context.DotnetRestorer[0]
      Restoring /Users/slavin/Library/Caches/dotnet-script/Users/slavin/source/test/net7.0/script.csproj using the dotnet cli. RuntimeIdentifier : osx-x64 NugetConfigFile: /Users/slavin/.nuget/NuGet/NuGet.Config
dbug: Dotnet.Script.DependencyModel.Context.ProfiledRestorer[0]
      Restoring /Users/slavin/Library/Caches/dotnet-script/Users/slavin/source/test/net7.0/script.csproj took 1097ms
dbug: Dotnet.Script.Core.ScriptCompiler[0]
      Configuration/Optimization mode: Debug
/Users/slavin/source/test/index.csx(5,17): error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
/Users/slavin/source/test/index.csx(7,9): error CS0103: The name 'WebApplication' does not exist in the current context

@filipw
Copy link
Member

filipw commented Jun 6, 2023

do you have the #r "sdk:Microsoft.NET.Sdk.Web" directive on top of your file?

according to the logs, the script uses <Project Sdk="Microsoft.NET.Sdk"> instead of <Project Sdk="Microsoft.NET.Sdk.Web"> which is why the ASP.NET Core dependencies cannot be found

@vladslavin
Copy link

@filipw yes, there seem to be some kind of miss match happening.
Here's the content of the script:

#!/usr/bin/env dotnet-script

#r "sdk:Microsoft.NET.Sdk.Web"

using Microsoft.AspNetCore.Builder;

var a = WebApplication.Create();
a.MapGet("/", () => "Hello world");
a.Run();

@filipw
Copy link
Member

filipw commented Jun 6, 2023

oh I see the bug now. it's the shebang on top that breaks it.
if you remove #!/usr/bin/env dotnet-script it will work.

Likely a parser problem.

@filipw filipw added bug and removed needs more info labels Jun 6, 2023
@filipw filipw changed the title Cannot run web application as described in readme. Shebang directive on top of the file breaks #r SDK parsing Jun 6, 2023
@vladslavin
Copy link

oh I see the bug now. it's the shebang on top that breaks it. if you remove #!/usr/bin/env dotnet-script it will work.

Likely a parser problem.

thanks Filip, that's exactly it 👍

@mmarvb8h
Copy link

mmarvb8h commented Jun 7, 2023

I finally got a chance to get back to this. Yes that seems to be the problem. Also i noticed that the "sdk directive" must be on the first line of the script. If i skip a line putting it on line 2, i also get the AspCore dependencies not found.

Noticed in Visual Code Intellisense complains those dependencies are not available but the code does run. Is that because the enable is missing from the .csproj file? I have another dotnet app that i removed that from the .csproj and received the same intellisense warnings but the app. runs. so i assume its the same thing.

Is there a template that's used that i can add this so when the .csproj file is being built that tag will be there?

@AraHaan
Copy link

AraHaan commented Jun 14, 2023

I would like the winforms / wpf sdk to be usable as well with this.

@alphajoza
Copy link

alphajoza commented May 5, 2024

Any fix for losing Intellisense and code completion when referencing a sdk?

2024-05-05_11-53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants