Add references and debug code snippets in Rider C# Interactive
We have made some updates to the C# Interactive tool window in the latest Rider 2018.2 EAP build! It’s now much easier to add project and assembly references to the current C# Interactive session. And once a project reference is added, we can attach the debugger and debug code snippets we are working on! Let’s see how this all works.
Add project and assembly references in C# Interactive
csi.exe tool (or the
csharp tool on Mono) both support referencing additional assemblies. This can be done using the reference syntax.
// C# Interactive csi.exe #r "C:\Users\Maarten\.nuget\packages\newtonsoft.json\11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll" // Mono csharp executable LoadAssembly ("C:\Users\Maarten\.nuget\packages\newtonsoft.json\11.0.2\lib\netstandard2.0\Newtonsoft.Json.dll");
While not rocket science, it’s not very convenient to have to look up the full path to an assembly that is being used by our project, and then write out the full command to load it.
In Rider 2018.2, we are making this easier: for projects and assemblies, a new Reference in C# Interactive context menu is available which will do just that: reference the selected project or assembly in C# Interactive. Rider will generate the load statement for us, and execute it at once.
The C# Interactive tool window also comes with its own toolbar button to help reference projects in the current solution. This makes it easy to reference a specific project and write some interactive code against it.
By default, Rider will use the currently built version of the project’s assembly. To make sure the referenced project assembly is always up-to-date, we can configure Rider (under Languages & Frameworks | C# Interactive) to build the project when using the Reference in C# Interactive action.
Debugging code snippets with C# Interactive
C# Interactive is very useful to quickly run C# statements in a read-eval-print loop (REPL) without having to wait for full compilation, and get immediate feedback on what a given expression will return. And when referencing our own project, we can easily create classes and invoke methods from our own code base and see what they return.
Things get trickier if we want to see what happens during execution. Did we step into that
if statement in our code? What is the value of the variable
who during execution? Rider 2018.2 now supports attaching the debugger to C# Interactive and step through our own code when invoked from C# Interactive!
Note this only works on Windows for now. And perhaps also good to know is that this is not an Immediate Window for debugging our application process, as the debugger is attached to C# Interactive and not to our running application.
No more need to write a console application or a unit test to quickly debug a snippet of code. All we have to do is reference our project and start debugging it with C# Interactive!
There’s one thing still missing here right now: code completion in the C# Interactive tool window. We’re working on that, and hope to make it available in one of our next EAP builds.
Download Rider 2018.2 EAP and give it a try! We’d love to hear your feedback!
Subscribe to Blog updates
Thanks, we've got you!
Visualize Entity Framework Relationships and Additional Query Analysis in ReSharper 2023.3
A lot of teams are using Entity Framework or EF Core to work with their database. As an Object-Relational Mapper (ORM), it bridges objects in code to a relational database model, so that as a developer you don’t have to worry too much about the actual database. We all know: that’s not entirely tr…
Automatically Analyze ASP.NET Core Performance With Dynamic Program Analysis
Slow web pages may make your users or customers abandon your web application, even before they’ve had a proper look at it. You’ve likely also been frustrated working with a web application that is slow to load. The good news is that the latest versions of ReSharper and JetBrains Rider’s Dynamic P…
OSS Power-Ups: MassTransit – Webinar Recording
The recording of our webinar, OSS Power-Ups: MassTransit, with Chris Patterson, is available. This was the thirteenth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webinars.…
Eager, Lazy and Explicit Loading with Entity Framework Core
Entity Framework Core (EF Core) supports a number of ways to load related data. There’s eager loading, lazy loading, and explicit loading. Each of these approaches have their own advantages and drawbacks. In this post, let’s have a quick look at each of these ways to load data for navigational prope…