Miguel Moura
Miguel Moura

Reputation: 39474

How to include project references in .NET Interactive Notebooks?

Using NET 6 I have the following project structure:

nuget.config
project.code-workspace
- Core
  Core.csproj
- Api
  Api.csproj
- Sim
  notebook.ipynb

Where notebook.ipynb is for now just:

#i "nuget:https://api.nuget.org/v3/index.json"

#r "nuget:Microsoft.Data.Analysis,0.*"

using System;
using Microsoft.Data.Analysis;

Console.WriteLine("Hello World!");

How to include a project reference to Core and Api projects in notebook.ipynb?

I need to use some of the Core and Api project classes in notebook.ipynb.

Upvotes: 6

Views: 1467

Answers (1)

Guru Stron
Guru Stron

Reputation: 142963

Currently that is not supported out of the box. See this issue. I've tried to use dotnet pack and install created package from local folder but failed. The only I've managed to make work is to build solution and add .dll manually:

Assuming next solution structure:

connect_solution.ipynb
- ClassLib\ClassLib.csproj (contains SomeDep.cs)
- Api\Api.csproj (references ClassLib.csproj, contains WeatherForecast)
#!pwsh 
dotnet build .\Api\Api.csproj --verbosity quiet
#r ".\Api\bin\Debug\net6.0\Api.dll"
using ClassLib;
using Api;
new SomeDep().Display();
new WeatherForecast()

Upvotes: 8

Related Questions