F# Can't install nugets because doesn't find default nuget source - f#

I'm trying to install some nuget packages using vs code in F# interactive (fsx script). It has worked before because I have successfully installed FSharp.Data, but it seems to not work (anymore).
Following error
No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, nuget.org (vs code)
Code
open System.IO
open System
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
#r "nuget:System.Data.Linq.dll"
#r "nuget:FSharp.Data.SqlClient.dll"
A related issue says to list the nuget sources through commandline:
Visual Studio 2019 F# NU1101 Unable to find package FSharp.core
When I do this I get a correct response:
So what is going on here?

When You use nuget prefix in the #r directive, you don't have to add ".dll" extension at the end of package name. It is required only when you are referencing local dlls.
https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/

Related

Visual Studio 2019 F# NU1101 Unable to find package FSharp.core

I'm just starting with Microsoft Visual Studio and F#.
I have followed their tutorial as close as I can but when I try to run the code they tell me to I get the error:
NU1101: Unable to find package FSharp.Core. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages
the entire code I have in the file looks like:
module HelloSquare
let square x = x * x
[<EntryPoint>]
let main argv =
printfn "%d squared is: %d!" 12 (square 12)
0 // Return an integer exit code
How can i fix this? Any help would be appreciated and I absolutely am willing to provide more info if it will help tackle the problem.
edit:
its a .NET core project
here's the tutorial I'm following:
https://learn.microsoft.com/en-us/dotnet/fsharp/get-started/get-started-visual-studio
here is the installation tutorial i followed I did the visual studio section, not the visual studio code, mac, or servers sections:
https://learn.microsoft.com/en-us/dotnet/fsharp/get-started/install-fsharp#install-f-with-visual-studio
How would I switch to online nuget source?
Check that you have at least one nuget source configured using:
dotnet nuget list source
it should return something like:
Registered Sources:
1. nuget.org [Enabled]
https://api.nuget.org/v3/index.json
If you don't have any sources configured then use dotnet nuget add source to add one.
e.g.:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
I think this may be an issue with current version of dotnet core (5.0.6)

Cannot create Q# projects

I'm new to quantum computing and I've been trying to follow instructions on https://learn.microsoft.com/en-us/azure/quantum/install-command-line-qdk?tabs=tabid-vscode to dive into this field, but I've run into a problem. Every time I'm trying to create a new Q# application project, I get the following error message
The project file cannot be opened. Unable to find package Microsoft.Quantum.Sdk. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages C:\Program Files\dotnet\sdk\5.0.202\Sdks\Microsoft.Quantum.Sdk\Sdk not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.
and I can't find that package myself either.
I've tried to install Microsoft.Quantum.Development.Kit-0.16.2104.138035 several times, with both .NET 3.1.408 and 5.0.202. I'm using VS 2019 16.9.4 Community Edition on Windows 10.
Looks like nuget.org is not listed as a valid package source in your computer, so dotnet can't find the QDK packages online.
Try running this command:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
And then try building your Q# project again.
It's unclear to me why nuget.org is not listed as a source, though; it should be included by default when you install the .NET Core.

Installing F# in visual studio code

I am trying to install F# with Visual studio code in Windows 10. I have installed dotnet framework first.
Then I have installed lonide-fsharp in visual studio code.
Then I have included the path of fsi in visual studio by clicking the Preferences->extensions->selected F# and Included the path.
Now in the visual studio code I typed ctrl+shift+p then I have typed fsi start, I am getting an error.
I tried with '/' and '\'. in the path. Every time I change I uninstalled the lonide and installed it again.
When I do fsi start ,F# should get started or what are all the other ways that I can make F# to start.
What is happening here is 'C:/Program Files/dotnet/sdk/3.0.100/FSharp/fsi the path does not exist'.
First, make sure you have the latest version of VS Code and Ionide.
Then, if you install the .NET Core 3.0 SDK from https://dotnet.microsoft.com/download, then it should install fsi.exe to that path. And then F# Interactive should just work with Ionide without any other configuration needed.

Can't load nuget package written with .NET Core

I have recently attempted to migrate my open source project GeographicLib.FSharp (https://github.com/SpiegelSoft/GeographicLib) to .NET Standard. I can build the project, package it and upload it to nuget, but when I try to load the nuget package into an external .NET Standard Library, I obtain mixed results.
Creating an F# library using dotnet new classlib -lang f# and adding the Nuget package via Visual Studio works on the face of it, but I cannot access any of the types I defined in the GeographicLib.FSharp library.
If I create a C# .NET Standard library using the Class Library (.NET Standard) template, then upgrade this package to .NET Standard 1.6, I can add the GeographicLib.FSharp nuget package and access the types as normal.
It appears that importing types from Nuget packages in F# .NET Standard Libraries is broken.
Is there a fix or a workaround for this?
Visual Studio F# extension doesn't yet support .NET Standard or .NET Core projects.
See https://blogs.msdn.microsoft.com/dotnet/2017/08/14/f-and-net-core-roadmap-update/ for more info and roadmap
If you think is an issue, please open a bug in Visual F# repository https://github.com/Microsoft/visualfsharp/issues
These project build, but doesnt load intellisense in Visual Studio.
Meanwhile you can use other ide/editors, like:
Visual Studio Code with Ionide extension
JetBrains Rider
vim
emacs
Visual Studio for Mac

Can I install/reference packages from within an fsx file?

I'm trying to find a simple solution that isn't so much manual work to reference packages. inside a .fsx file.
LinqPad 4 lets me simply add nuget packages
no intellisense or autocompletion
deletes package after download for certain types of packages (templatus for example)
LinqPad 5 beta lets me add nuget packages
deletes package after download for certain types of packages (templatus for example)
with frequent failures (intellisense and compilation)
VS2015 doesn't let you download/install packages for an fsx file (only into projects)
VSCode doesn't let you download/install nuget or paket packages for an fsx file.
So I wind up having to use .fsx in VS2015, while using linqpad to get packages downloaded (which still fails for packages like templatus where it downloads an exe not a dll). Then I have I can reference them as
#I #"..\LINQPad\NuGet.FW46\FParsec\FParsec.1.0.2\lib\net40-client\" // references AppData\local\ ... since . is %localappdata%\TEMP
doesn't match up with the relative pathing for intellisense/autocompletion engine in VSCode so I can't remove VS from the equation.
doesn't work outside of a machine that already has that package in that location
wind up doing a bunch of code that doesn't span .fsx files very well and has to be worked out per package reference
I don't want to create a project. I have a ton of individual scripts that are to be individually maintained and usable by others on-demand.
Is there an IDE (or fix/extension for one of these mentioned) that will give me intellisense, autocomplete, and package management for F# .fsx files that can work easily from user to user, machine to machine?
The Ionide plugins for VsCode and Atom have the functionality you're looking for
VsCode Instructions
Use the command palette to install the Ionide extensions ionide-fsharp and ionide-paket
You'll need to add your F# installation to your PATH
(on windows Rapid Enivornment Editor is my goto for PATH editing)
For F# 4.0 add C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0
Open the work folder that will hold your .fsx files
Executing paket commands through the command palette will be your primary interface for working with nuget packages
make a new .fsx file, (I recommend using the Advanced New File extension over the standard VsCode method)
The first step is to run paket init which is necessary to use paket to manage your packages
If you click the open button on the notification popups you can view the the output from paket in a side panel
After using the add nuget package command and entering extcorefor the package you should see the work tree
updated to
Then all you need to do is reference the package in the script and you'll get the auto-completion you're looking for
As of F# 5.0 you can now use the #r "nuget: Package" (ref):
#r "nuget: Newtonsoft.Json"
// Optionally, specify a version explicitly
// #r "nuget: Newtonsoft.Json,11.0.1"
open Newtonsoft.Json
let o = {| X = 2; Y = "Hello" |}
printfn "%s" (JsonConvert.SerializeObject o)

Resources