Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# interactive window won't reference my code

In Visual Studio 2017 I am trying to run some code in the c# Interactive Window. This works for very simple cases (e.g. using System) However, when I try and reference slightly more obscure libraries it fails

using Microsoft.AspNetCore.Cryptography.KeyDerivation;

(1,17): error CS0234: The type or namespace name 'AspNetCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

This is a dot net core 2.0 project, and it has been suggested that I can right click on the project and select "Initialize Interactive with Project", however this option does not appear for me on either the project or solution.

I need to know how to add references to code libraries for the interactive window.

like image 877
jazza1000 Avatar asked Sep 13 '17 13:09

jazza1000


1 Answers

You need to add a reference to any 'more obscure' libraries that you plan to use.

#r is used to reference assemblies. Below are some examples:

#r "path/MyAssembly.dll" #r "MicrosoftLibrary", e.g., #r "System.Collections.Generic" Note: The Interactive Window doesn't currently support #r'ing NuGet packages. As a temporary workaround, reference the NuGet DLL.

like image 71
mjwills Avatar answered Oct 13 '22 01:10

mjwills