dotnet-script
dotnet-script copied to clipboard
Cannot add NuGet packages
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.
Try replacing
using GraphQLClientGenerator;
with
using GraphQlClientGenerator;
Thanks for the tip, sadly it doesn't make a difference...
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?
Thanks for the hint. I think I found two possible bugs....
-
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.
-
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.
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>
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