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

Cannot add NuGet packages #584

Closed
AndiRudi opened this issue Oct 14, 2020 · 6 comments
Closed

Cannot add NuGet packages #584

AndiRudi opened this issue Oct 14, 2020 · 6 comments

Comments

@AndiRudi
Copy link

I am trying to use a NuGet package with dotnet-script. I have initialized a new script project as explained and added this into the main.csx file and restarted omnisharp. The using directive is always underlined with "Type or namespace could not be found". I even do not see that any NuGet packages were downloaded.

#!/usr/bin/env dotnet-script
#r "nuget:GraphQlClientGenerator,0.7.3"
using GraphQLClientGenerator;

Here is the log

Starting OmniSharp server at 10/14/2020, 2:23:52 PM
    Target: /Users/x/repos/integration-service/Source/Clients/x/Generate

OmniSharp server started.
    Path: /Users/x/.vscode/extensions/ms-dotnettools.csharp-1.23.3/.omnisharp/1.37.2/run
    PID: 50143

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on MacOS 10.15.6 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 16.8.0 - "/Users/x/.vscode/extensions/ms-dotnettools.csharp-1.23.3/.omnisharp/1.37.2/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/Users/x/.vscode/extensions/ms-dotnettools.csharp-1.23.3/.omnisharp/1.37.2/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 16.8.0 - "/Users/x/.vscode/extensions/ms-dotnettools.csharp-1.23.3/.omnisharp/1.37.2/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /Users/x/.vscode/extensions/ms-dotnettools.csharp-1.23.3/.omnisharp/1.37.2/omnisharp/.msbuild/Current/Bin
            CscToolPath = /Users/x/.vscode/extensions/ms-dotnettools.csharp-1.23.3/.omnisharp/1.37.2/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /Users/x/.vscode/extensions/ms-dotnettools.csharp-1.23.3/.omnisharp/1.37.2/omnisharp/.msbuild
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/Users/x/repos/integration-service/Source/Clients/x/Generate'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        No solution files found in '/Users/x/repos/integration-service/Source/Clients/x/Generate'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/Users/x/repos/integration-service/Source/Clients/x/Generate'.
[info]: OmniSharp.Script.ScriptProjectSystem
        Found 1 CSX files.
[info]: OmniSharp.Script.ScriptContextProvider
        Searching for compilation dependencies with the fallback framework of 'netcoreapp3.1'.
[fail]: OmniSharp.Script.ScriptContextProvider
        Failed to resolve compilation dependencies
[info]: OmniSharp.Script.ScriptContextProvider
        Unable to find dependency context for CSX files. Will default to non-context usage (Desktop CLR scripts).
[info]: OmniSharp.Script.ScriptProjectSystem
        Added CSX project '/Users/x/repos/integration-service/Source/Clients/x/Generate/main.csx' to the workspace.
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/Users/x/repos/integration-service/Source/Clients/x/Generate' on host 49973.
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
        Solution initialized -> queue all documents for code analysis. Initial document count: 1.
@seesharper
Copy link
Collaborator

Try replacing

using GraphQLClientGenerator;

with

using GraphQlClientGenerator;

@AndiRudi
Copy link
Author

Thanks for the tip, sadly it doesn't make a difference...

@filipw
Copy link
Member

filipw commented Oct 14, 2020

you have an error

[fail]: OmniSharp.Script.ScriptContextProvider
        Failed to resolve compilation dependencies

can you set omnisharp log level to trace and capture the output again?

@AndiRudi
Copy link
Author

Thanks for the hint. I think I found two possible bugs....

  1. For some reason it's looking into parent directories to find a NuGet.config. I opened the solution in vscode at the level .../Source/Clients/x but it found the NuGet.Config in my project in parent folders .../Source/NuGet.Config.

  2. This NuGet config points to some custom NuGet streams and it also seems, that in this case it ignores the official NuGet stream so it can't find the GraphQlClientGenerator package.

[dbug]: OmniSharp.Script.Dotnet.Script.DependencyModel.Process.CommandRunner
        Executing 'dotnet restore "/Users/x/Library/Caches/dotnet-script/Users/x/repos/integration-service/Source/Clients/x/Generate/netcoreapp3.1/script.csproj" -r osx-x64  --configfile "/Users/x/repos/integration-service/Source/NuGet.Config"'

[dbug]: OmniSharp.Script.Dotnet.Script.DependencyModel.Process.CommandRunner
        /Users/x/Library/Caches/dotnet-script/Users/x/repos/integration-service/Source/Clients/x/Generate/netcoreapp3.1/script.csproj : error NU1101: Unable to find package GraphQlClientGenerator. No packages exist with this id in source(s): HangfirePro, MyGet

[dbug]: OmniSharp.Script.Dotnet.Script.DependencyModel.Process.CommandRunner
        /Users/x/Library/Caches/dotnet-script/Users/x/repos/integration-service/Source/Clients/x/Generate/netcoreapp3.1/script.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Runtime.osx-x64. No packages exist with this id in source(s): HangfirePro, MyGet

[dbug]: OmniSharp.Script.Dotnet.Script.DependencyModel.Process.CommandRunner
          Restore failed in 620.09 ms for /Users/x/Library/Caches/dotnet-script/Users/x/repos/integration-service/Source/Clients/x/Generate/netcoreapp3.1/script.csproj.

@AndiRudi
Copy link
Author

I have added the official package source and it works. Not sure if above are still bugs to look at or if we can close this.

<packageSources>
    <add key="HangfirePro" value="..." />
    <add key="MyGet" value="..." />
    <add key="NuGet official package source" value="https://nuget.org/api/v2/" />
 </packageSources>

@filipw
Copy link
Member

filipw commented Oct 14, 2020

This is by design. dotnet-script will respect nuget.config to give you the ability to point to custom nuget feeds. Since NuGet 3.4 the nuget behavior is such that it will look in the project's directory or "or any folder up to the drive root" to locate the config file https://docs.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior

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

No branches or pull requests

3 participants