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

nuget packages not loading #601

Closed
rsquarev opened this issue Dec 17, 2020 · 6 comments
Closed

nuget packages not loading #601

rsquarev opened this issue Dec 17, 2020 · 6 comments

Comments

@rsquarev
Copy link

Hi there,
I decided to use dotnet script instead of linqpad as most of my development is in vscode. so I started with dotnet script init.
First I got issue with .Net Script Debug. I figured that vscode is looking for .vscode folder in parent of .csx directory.
Now, I am at main.csx with following code. Inteli-sense doesn't recognize namespace System.Net.Http. Obviously omnisharp/msbuild is not restoring packages. I also tried Nuget.Config in directory where main.csx is, and also its parent directory. Nuget.config may be irrelevant as msbuild issue needs to be resolved first.

#r "nuget: System.Net.Http, 4.3.4"
using System.Net.Http;
var client=new HttpClient();
Console.WriteLine("Hello world!");

As I see in other issues, I changed omnisharp logging level to trace. I got lot of trace, but not sure what causing my issue.
I have 3 locations for msbuild. 2019, 2017 (installed from chocolatey installation) and stand alone.
I also tried to change omnisharp.json to override msbuild path like below, which didn't make any difference.

{
  "script": {
    "enableScriptNuGetReferences": true,
    "defaultTargetFramework": "net5.0"
  },
"msbuild": {
  "MSBuildSdksPath":"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin",
  "enabled": true,
  }
}

I am uploading the omnisharp log here. its quite big.
omnisharp.log

I appreciate your help!!

@filipw
Copy link
Member

filipw commented Dec 17, 2020

according to the log the your omnisharp.json is not discovered.
Is it located at the root of the workspace you are opening in VS Code?

The log shows that instead of net5.0, the CSX scripts are offered with .NET 4.6.1 desktop mode, without nuget support.

[info]: OmniSharp.Script.ScriptContextProvider
        Searching for compilation dependencies with the fallback framework of 'net461'.
[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).

@rsquarev
Copy link
Author

rsquarev commented Dec 17, 2020

Thanks for that insight @filipw. You are right about workspace. Now I moved omnisharp.json to workspace directory.
What version should I pick if net5.0 is not supported. Here is my dotnet --info. I changed it to netcore3.1 though.
it still fails.

.NET SDK (reflecting any global.json):
 Version:   5.0.100
 Commit:    5044b93829

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100\

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

.NET SDKs installed:
  3.1.402 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Here is my project structure.
image

Here is omnisharp.json

{
  "script": {
    "enableScriptNuGetReferences": true,
    "defaultTargetFramework": "netcore3.1"
  },
  "msbuild": {
    "MSBuildSdksPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin",
    "enabled": true
  }
}

Here is omnisharp log file again..
omnisharp2.log

Here is my commit if that helps: https://github.com/rsquarev/tools/commit/72288ffb8bc615411f0749ebd2b764b97ddbd00f

@filipw
Copy link
Member

filipw commented Dec 17, 2020

The TFM for .NET Core 3.1 is netcoreapp3.1 not netcore3.1.
Also, you should not set MSBuildSdksPath to VS 2017 as it uses MSBuild 15.9.
The minimum MSBuild for .NET Core 3.1 is 16.3 and for .NET 5.0 is 16.8. Leaving this to default and letting OmniSharp choose is the best option.

@filipw
Copy link
Member

filipw commented Dec 17, 2020

one more thing, you don't need to pull System.Net.Http from NuGet - it's available there by default so you can just start using it directly

@rsquarev
Copy link
Author

rsquarev commented Dec 17, 2020

I was trying as an example for System.Net.Http. Originally I wanted to get nuget: System.Net.Http.Json, 5.0.0.

I tried with netcoreapp3.1 as well. Now moved back to default net5.0 and it doesnt complain about fallback to net461.
script.csproj also created in temp folder. However, no referenced package downloaded.

[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).
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Attempting to resolve 'System.Runtime'
[dbug]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        FAILURE: Could not locate 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\System.Runtime.dll'.

I am ok with any framework. just wanted the #r "nuget: " to work. Can you point me to any sample for that?

@rsquarev
Copy link
Author

I tried with a fresh workspace and it works with net5.0 flawless. I think Nuget.Config was the issue in my old setup also. After I remove that file, even old workspace works as intended. Thank you very much for your help @filipw.

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

2 participants