LINQPad脚本目录? [英] LINQPad script directory?
问题描述
有人知道如何掌握LINQPad脚本文件(.linq)所在目录的路径吗?
Does anyone know how to get hold of the path to the directory where the LINQPad script file (.linq) resides?
或者是脚本本身.
请注意,我并不是在说我的查询"文件夹的位置,该文件夹显示在LINQPad内.
Note that I'm not talking about the location of the "My Queries" folder, the one shown inside LINQPad.
我可以将.linq文件保存在磁盘上的任何位置,然后双击打开它.
I can save a .linq file anywhere on disk, and open it by double-clicking on it.
例如,如果我将文件保存到C:\Temp\Test.linq
,然后执行程序,我想使用C:\Temp
或C:\Temp\Test.linq
.
For instance, if I save the file to C:\Temp\Test.linq
, and execute the program, I'd like to have either C:\Temp
or C:\Temp\Test.linq
.
基本上,我想要类似于Environment.CurrentDirectory
或Assembly.GetEntryAssembly().Location
的东西,仅用于.linq文件.
Basically I'd like something akin to Environment.CurrentDirectory
or Assembly.GetEntryAssembly().Location
, just for the .linq file.
我尝试过的事情:
- 浏览环境变量
- 浏览给我脚本的LINQPad程序集
- 引发异常并查看stacktrace(在其他地方包含指向我脚本的临时副本的链接)
-
Environment.CommandLine.Dump();
-提供LINQPad可执行文件 -
Environment.CurrentDirectory.Dump();
-给出C:\ windows \ system32 -
Assembly.GetExecutingAssembly().Location.Dump();
-给出临时目录
- Looking through environment variables
- Looking through the LINQPad assembly that is given to my script
- Throwing an exception and looking at the stacktrace (contains a link to a temporary copy of my script somewhere else)
Environment.CommandLine.Dump();
- gives LINQPad executableEnvironment.CurrentDirectory.Dump();
- gives C:\windows\system32Assembly.GetExecutingAssembly().Location.Dump();
- gives temp directory
推荐答案
我刚刚添加了一个功能来解决此问题.您现在可以通过下载 2.27.1或4.27.1 beta版本进行测试.
I've just added a feature to address this. You can test it now by downloading the 2.27.1 or 4.27.1 beta build.
要获取当前查询的文件夹,请使用以下表达式:
To get the current query's folder, use the following expression:
Path.GetDirectoryName (Util.CurrentQueryPath)
这篇关于LINQPad脚本目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!