Can the C# interactive window interact with my code?

断了今生、忘了曾经 提交于 2019-11-27 10:45:57

When using Visual Studio 2015:

You can open the Interactive window by navigating to Views > Other Windows > C# Interactive,

Then just right click your project and run Initialize Interactive with Project from the context menu.


For older versions:

To use the C# Interactive Window with your code, ensure you first compile your code, then add a reference to the resulting assembly with the #r command like so:


You can also use the Immediate Window to interact with your code as well, like so:

You can use classes from your own project.
Just right click on your solution and select "Reset Interactive from Project".

If you need more information, here is the source:
Using the C# Interactive Window that comes with Roslyn – Part 2

Just an update from the @Botz3000 answer.

The command you want to find is now called "Initialize Interactive with Project"

Also it is worth noting i could not find this command if my C# interactive window was not viewable.

beloblotskiy

Totally agree "Initialize Interactive with Project" is cool.

My approach is to push classes into a library and use //css_reference in C# script or #r in C# Interactive window

For example:

#r "D:\\dev\\DbHMonData\\LoadH2Stats\\bin\\Debug\\DbHMonStats.dll"
using DbHMonStats;

Don't forget to change class name range, to public class name.
:)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!