In trying to add NuGet packages to a Console workbook some packages fail to be added and no error or failure message is displayed.
Packages in question target just NF4.6.2 & NetStandard2.0 so I assume it's a targeting issue.
This is because your .NET Framework support is explicitly for 4.6.2, and the .NET Framework workbook apps (Console and WPF) are 4.6.1. So from the workbook's point of view, there is no assembly that can be referenced.
If you instead create a .NET Core Console workbook, then your .NET Standard 2.0 assembly will get referenced. This is the #r
that gets generated in that case: #r "ApiAnalysis.SimpleJsonAnalyzer"
.
Alternatively, you could reduce your package's .NET Framework requirement from 4.6.2 to 4.5 or 4.6.
Answers
You probably need to be using Workbooks 1.3. An RC is available for download at https://developer.xamarin.com/releases/interactive/interactive-1.3/ (or you can switch your update channel to alpha or beta).
Using v1.3 RC2 I can now add the reference to the package in the workbook but I still can't use it.
It's my own NuGet package and I want to use WorkBooks to create some docs but can't.
ApiAnalysis.SimpleJsonAnalyzer version: 1.1.0
In the code block, I get a red underline on the #r line with the message "Metadata file ApiAnalysis could not be found."
The library works fine when referenced in NetCore2 apps and libraries (and the NF462 version works fine there) but I can't reference and use it in a workbook.
What do I need to get it to work in a workbook?
This is because your .NET Framework support is explicitly for 4.6.2, and the .NET Framework workbook apps (Console and WPF) are 4.6.1. So from the workbook's point of view, there is no assembly that can be referenced.
If you instead create a .NET Core Console workbook, then your .NET Standard 2.0 assembly will get referenced. This is the
#r
that gets generated in that case:#r "ApiAnalysis.SimpleJsonAnalyzer"
.Alternatively, you could reduce your package's .NET Framework requirement from 4.6.2 to 4.5 or 4.6.
(And yes, we should and will improve the user experience around users installing NuGet packages that can't be referenced in the current workbook)
Another option would be to totally drop the NF462 assembly, and then any app targeting .NET Framework 4.6.1 or later would just automatically reference the .NET Standard assembly.
I find it strange that NuGet won't fall back to the .NET Standard assembly in the existing package, but I tested in VS 15.3 and it has similar behavior. The install errors-out because "the package does not contain any assembly references or content files that are compatible with that framework". In Workbooks, we allow package installs like this to "succeed", because we do support changing your target platform. But as I said, this is clearly not in the best UX place yet.
Thanks for bringing this scenario to our attention!
I added a version of the package targeting .Net 4.5 and now it works great. Thanks.
Glad to hear it!