从一个 RoslynPad 脚本引用另一个脚本
Reference one RoslynPad script from another
我想做的是从一个脚本中引用另一个脚本。
实现这一目标的一种方法可能是使用程序集。 RoslynPad 允许将脚本编译成程序集。这是我到目前为止尝试过的方法。
脚本A,编译为SOME_PATH\thing.dll
class Thing
{
public string Name { get; set; }
}
脚本 B
#r "SOME_PATH\thing.dll"
using static Program;
var t = new Thing();
t.Name = "TEST";
t.Name.Dump();
这给出了错误 "The type or namespace 'Thing' could not be found..." 所以我尝试了以下方法。
#r "SOME_PATH\thing.dll"
var t = new Program.Thing();
t.Name = "TEST";
t.Name.Dump();
这给出了以下错误 "The type name 'Thing' does not exist in the type 'Program'"。
有没有办法 "Compile and Save assembly" 然后从另一个脚本引用它?或者,有没有更直接的方式在脚本之间进行交叉引用?
您要查找的是 #load
指令:
#load "Path\To\ScriptA.csx"
var t = new Thing();
您可以在 Roslyn wiki 中阅读有关 C# 脚本变体的更多信息。请注意,并非所有内容都与 RoslynPad 相关,与 C# Interactive window 不同,它不是 REPL。
我想做的是从一个脚本中引用另一个脚本。
实现这一目标的一种方法可能是使用程序集。 RoslynPad 允许将脚本编译成程序集。这是我到目前为止尝试过的方法。
脚本A,编译为SOME_PATH\thing.dll
class Thing
{
public string Name { get; set; }
}
脚本 B
#r "SOME_PATH\thing.dll"
using static Program;
var t = new Thing();
t.Name = "TEST";
t.Name.Dump();
这给出了错误 "The type or namespace 'Thing' could not be found..." 所以我尝试了以下方法。
#r "SOME_PATH\thing.dll"
var t = new Program.Thing();
t.Name = "TEST";
t.Name.Dump();
这给出了以下错误 "The type name 'Thing' does not exist in the type 'Program'"。
有没有办法 "Compile and Save assembly" 然后从另一个脚本引用它?或者,有没有更直接的方式在脚本之间进行交叉引用?
您要查找的是 #load
指令:
#load "Path\To\ScriptA.csx"
var t = new Thing();
您可以在 Roslyn wiki 中阅读有关 C# 脚本变体的更多信息。请注意,并非所有内容都与 RoslynPad 相关,与 C# Interactive window 不同,它不是 REPL。