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

dotnet fsi fail to load nuget package in dotnet SDK 7.0.302 #15294

Closed
albertwoo opened this issue Jun 2, 2023 · 13 comments
Closed

dotnet fsi fail to load nuget package in dotnet SDK 7.0.302 #15294

albertwoo opened this issue Jun 2, 2023 · 13 comments
Assignees
Labels
Area-FSI Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone

Comments

@albertwoo
Copy link

dotnet fsi fail to load nuget pacakge in donet SDK 7.0.302, I also tried the dotnet 8 preview 4, and the error is the same. It worked in 7.0.203 and older versions.

Repro steps

  1. Make sure you are using 7.0.302: dotent --version

  2. Run: dotnet fsi

  3. Run: #r "nuget:NBomber";;

    Or try other nuget packages, like Fun.Build

You will get below error:

#r "nuget:NBomber"
^^^^^^^^^^^^^^^^^^
stdin(1,1): error FS3217: C:\Users\woo.packagemanagement\nuget\Projects\1220--24e02601-e93e-4b40-a9bf-33a26d273aa0\Project.fsproj : error NU1101: 找不到包 NBomber。源 C:\Program Files\dotnet\library-packs, C:\Program Files\dotnet\sdk\8.0.100-preview.4.23260.5\FSharp\library-packs 中不存在具有此 ID 的包

Expected behavior

Should work as before

Actual behavior

Throw error

Known workarounds

Sometimes, if you attach specific version it may work, but not always. And if you are using dotnet fsi xxx.fsx and the nuget package is used in the fsx file, then most of the chance it will not work.

Related information

Provide any related information (optional):

  • Windows 11 and MacOS
  • dotnet sdk 7.0.302
@vzarytovskii
Copy link
Member

vzarytovskii commented Jun 5, 2023

I cannot reproduce it. It seems it doesn't see your nuget.config, or it's overridden locally.

@vlza ➜ test-global-json cat .\global.json
{
  "sdk": {
    "version": "7.0.302"
  }
}
@vlza ➜ test-global-json dotnet --version
7.0.302
@vlza ➜ test-global-json dotnet fsi --nologo

> #r "nuget:NBomber";;
[Loading C:\Users\vlza\.packagemanagement\nuget\Projects\109832--268686bf-5006-4736-adb8-f45c6464592f\Project.fsproj.fsx]
module FSI_0002.Project.fsproj

>
@vlza ➜ test-global-json

@0101
Copy link
Contributor

0101 commented Jun 5, 2023

This is suspicious C:\Users\woo.packagemanagement\nuget\Projects\... it's like there's a slash missing before .packagemanagement.

@0101 0101 added Area-FSI Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. and removed Needs-Triage labels Jun 5, 2023
@KevinRansom KevinRansom moved this from Not Planned to Planned in F# Compiler and Tooling Jun 5, 2023
@KevinRansom KevinRansom modified the milestones: Backlog, June-2023 Jun 5, 2023
@KevinRansom
Copy link
Member

KevinRansom commented Jun 5, 2023

This is suspicious C:\Users\woo.packagemanagement\nuget\Projects\... it's like there's a slash missing before .packagemanagement.

I fully expect that is an issue, however, this is where that path is created:

Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile), ".packagemanagement", "nuget")

It seems as if there are circumstances where path.Combine assumes the ".packagemanagement" is an extension.

So that is going to mess up the caching, but wouldn't fail the resolution.

@albertwoo
I believe that the default nuget.config file found at:

C:\Users\woo\AppData\Roaming\NuGet\NuGet.Config

has become corrupted:

The contents of the file should include a link to the global nuget source:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

@albertwoo
Copy link
Author

@KevinRansom the NuGet.Config should not be corrupted. The first time I found this issue, is when I help a college to set her fresh Mac for dotnet. Then I tried on my owen Mac with the 7.0.302 SDK, and reproduced this issue. When I create a globaljson to pin the version to 7.0.203, the build script worked as normal. I also tried to switch back to 7.0.302 again, and found the issue happens again. That is why I report this issue.

But today, on my Windows PC, I can not reproduce this issue anymore. And also tried on WSL with Ubuntu 20. I can also not able to reproduce. Maybe it is related to nuget.org which cannot find the package without a specific version. And now it works.

Sorry to bother, I will close this issue for now.

@github-project-automation github-project-automation bot moved this from Planned to Done in F# Compiler and Tooling Jun 6, 2023
@0xBruceLiao
Copy link

I'm having the same problem, after updating Visual Studio on my two Windows 11, I got the latest version of NET

.NET version to " 7.0.302 [C:\Program Files\dotnet\sdk]".

Once I use"#r "nuget:xxx"", it reports an error, switching back to 7.0.203 [C:\Program Files\dotnet\sdk] has no problem.

The error content is the same as @albertwoo

Microsoft(R) F# Interactive Window Version F# 7.0 12.5.0.0
Copyright(C) Microsoft Corporation. all rights reserved.

To get help, type #help;.

> #r "nuget:FsHttp";.

  #r "nuget:FsHttp";.
  ^^^^^^^^^^^^^^^^^

stdin(1,1): error FS3217: C:\Users\bruce\.packagemanagement\nuget\Projects\21156--ba817e33-5ab3-4250-bea3-fa4b9c8b2eda\Project.fsproj : error NU1101: package FsHttp not found. source C:\Program Files\dotnet\library-packs, C:\Program Files\dotnet\sdk\7.0.302\FSharp\library-packs does not exist in the package with this ID

I don't have this problem with Ubuntu, macOS, but I have this problem with both of my Windows 11 operating systems.

@0xBruceLiao
Copy link

I'm having the same problem, after updating Visual Studio on my two Windows 11, I got the latest version of NET

.NET version to " 7.0.302 [C:\Program Files\dotnet\sdk]".

Once I use"#r "nuget:xxx"", it reports an error, switching back to 7.0.203 [C:\Program Files\dotnet\sdk] has no problem.

The error content is the same as @albertwoo

Microsoft(R) F# Interactive Window Version F# 7.0 12.5.0.0
Copyright(C) Microsoft Corporation. all rights reserved.

To get help, type #help;.

> #r "nuget:FsHttp";.

  #r "nuget:FsHttp";.
  ^^^^^^^^^^^^^^^^^

stdin(1,1): error FS3217: C:\Users\bruce\.packagemanagement\nuget\Projects\21156--ba817e33-5ab3-4250-bea3-fa4b9c8b2eda\Project.fsproj : error NU1101: package FsHttp not found. source C:\Program Files\dotnet\library-packs, C:\Program Files\dotnet\sdk\7.0.302\FSharp\library-packs does not exist in the package with this ID

I don't have this problem with Ubuntu, macOS, but I have this problem with both of my Windows 11 operating systems.

7.0.302 The NuGet.config generated in.packagemanagement\nuget\Projects\is problematic:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />

  </packageSources>
</configuration>

Apparently the nuget.org source is not inserted correctly,I don't have this problem when I switch back to any version as long as I don't use version 7.0.302

@albertwoo
Copy link
Author

Then I will reopen it. 😂

@albertwoo albertwoo reopened this Jun 6, 2023
@github-project-automation github-project-automation bot moved this from Done to In Progress in F# Compiler and Tooling Jun 6, 2023
@0xBruceLiao
Copy link

I'm having the same problem, after updating Visual Studio on my two Windows 11, I got the latest version of NET

.NET version to " 7.0.302 [C:\Program Files\dotnet\sdk]".

Once I use"#r "nuget:xxx"", it reports an error, switching back to 7.0.203 [C:\Program Files\dotnet\sdk] has no problem.

The error content is the same as @albertwoo

Microsoft(R) F# Interactive Window Version F# 7.0 12.5.0.0
Copyright(C) Microsoft Corporation. all rights reserved.

To get help, type #help;.

> #r "nuget:FsHttp";.

  #r "nuget:FsHttp";.
  ^^^^^^^^^^^^^^^^^

stdin(1,1): error FS3217: C:\Users\bruce\.packagemanagement\nuget\Projects\21156--ba817e33-5ab3-4250-bea3-fa4b9c8b2eda\Project.fsproj : error NU1101: package FsHttp not found. source C:\Program Files\dotnet\library-packs, C:\Program Files\dotnet\sdk\7.0.302\FSharp\library-packs does not exist in the package with this ID

I don't have this problem with Ubuntu, macOS, but I have this problem with both of my Windows 11 operating systems.

I briefly analyzed it and guessed that it was a problem introduced by Commit

FSharp.DependencyManager.fs#L401

The code means that a new Nuget.config file will be generated when the project file is generated, regardless of whether the Nuget.Config file exists in theRoaming\Nugetdirectory,

Written from FSharp.DependencyManager.ProjectFile.fs#L19

    let generateProjectNugetConfigFile =
        """<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
$(NUGET_SOURCES)
  </packageSources>
</configuration>
    """

Then,Replace "$(nuget_sources)" in the file (FSharp.DependencyManager.fs#L393)[https://github.com/dotnet/fsharp/blob/main/src/FSharp.DependencyManager.Nuget/FSharp.DependencyManager.fs#L393]

 let generateProjectNugetConfigFile =
                generateProjectNugetConfigFile.Replace("$(NUGET_SOURCES)", generatedNugetSources)

And ,generatedNugetSources From generateSourcesFromNugetConfigs Function, Take a look at this regular expression

 let pattern =
                @"(\s*\d+\.+\s*)(?'name'\S*)(\s*)\[(?'enabled'Enabled|Disabled)\](\s*)$(\s*)(?'uri'\S*)"

And look at the results of my command prompt:

C:\>dotnet nuget list source --format detailed
注册的源:
  1.  nuget.org [已启用]
      https://api.nuget.org/v3/index.json
  2.  Microsoft Visual Studio Offline Packages [已启用]
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

C:\>

So I summarize as follows:

The regular expression to match is "Enabled" in English, while mine is "已启用" in Chinese,So it fails and returns the empty string, which is why the source of Nuget.config in the project directory is empty @vzarytovskii @albertwoo

@vzarytovskii
Copy link
Member

vzarytovskii commented Jun 6, 2023

@0xBruceLiao thanks for the great analysis, @KevinRansom as we thought yesterday, culture is the problem when we collecting sources.
Need to probably set it to default one when running the process, and match on something else, and mot English word in regex.

@psfinaki psfinaki changed the title dotnet fsi fail to load nuget pacakge in donet SDK 7.0.302 dotnet fsi fail to load nuget package in dotnet SDK 7.0.302 Jun 6, 2023
@KevinRansom
Copy link
Member

@0xBruceLiao , nice wrk on figuring out what the issue is:

Localizing the Enabled seems like a poor choice for a feature that was intended to be machine read.

could you run this command and provide the output please:

dotnet nuget list source --format short

E https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json
E https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json
E https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json
E https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json
E https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json
E https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7-transport/nuget/v3/index.json
E https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json
E https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json
E https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk-archived/nuget/v3/index.json
E https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl/nuget/v3/index.json
E https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-impl-archived/nuget/v3/index.json

@KevinRansom
Copy link
Member

KevinRansom commented Jun 6, 2023

Okay, I had to go to detailed so that we could get the name of the source associated with a uri. This is necessary to allow nuget.config authenticated sources to work which are keyed by name. Miserable the Enabled/Disabled state is authenticated.

Okay: from the nuget sources it seems that --format short is not localized, so I will run both short and detailed and union them.

https://github.com/NuGet/NuGet.Client/blob/d5bcbb2a618400be95bdbdaece27238a798b334c/src/NuGet.Core/NuGet.Commands/SourcesCommands/SourceRunners.cs#L163

@KevinRansom
Copy link
Member

KevinRansom commented Jun 6, 2023

Luckily there is a much easier way of doing this: The Sdk supports an environment variable

https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_cli_ui_language

set DOTNET_CLI_UI_LANGUAGE=en-us

@KevinRansom
Copy link
Member

Both fixes are merged:

@github-project-automation github-project-automation bot moved this from In Progress to Done in F# Compiler and Tooling Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FSI Bug Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code.
Projects
Archived in project
Development

No branches or pull requests

5 participants