我如何在当前项目的代码路径中找到?(How can I find in code path of my current project?)

我如何以编程方式在我的C#代码中获取当前项目的路径?

我有任何预处理器指令吗? 或者任何宏?

注意: 我不需要当前正在执行的程序集的路径,而是需要从中编译此程序集的项目路径。

注意(2) - 我试图实现的: 我有几个文件被编译为嵌入式资源 我加载并在运行时使用它们。 我想创建一个“调试”模式,在该模式下,文件从磁盘上的原始位置加载,而不是从资源流加载。 这将使我能够快速编辑文件以进行测试,而无需重新编译程序集。 由于程序集被复制到不同的位置,在编译它的项目之外,在“调试”模式下,我无法使用相对路径加载文件。

How can I programmatically get the path of the current project in my C# code?

Do I have any preprocessor directives for this? Or any macros?

Note: I don't need the path of the current executing assembly, but rather a path of the project, from which this assembly was compiled.

Note (2) - What I'm trying to achieve: I have several files that are compiled as embedded resources. I load and use them in the runtime. I would like to create a "debug" mode, in which the files are loaded from their original location on disk and not from the resource stream. This would enable me to fast-edit the files for test purposes without the need to recompile the assembly. Since the assembly is copied to a different location, outside the project from which it was compiled, in the "debug" mode I can't load the files using relative path.

最满意答案

您可能可以使用CallerFilePathAttribute。

https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callerfilepathattribute(v=vs.110).aspx

You might be able to make use of the CallerFilePathAttribute.

https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callerfilepathattribute(v=vs.110).aspx

我如何在当前项目的代码路径中找到?(How can I find in code path of my current project?)

我如何以编程方式在我的C#代码中获取当前项目的路径?

我有任何预处理器指令吗? 或者任何宏?

注意: 我不需要当前正在执行的程序集的路径,而是需要从中编译此程序集的项目路径。

注意(2) - 我试图实现的: 我有几个文件被编译为嵌入式资源 我加载并在运行时使用它们。 我想创建一个“调试”模式,在该模式下,文件从磁盘上的原始位置加载,而不是从资源流加载。 这将使我能够快速编辑文件以进行测试,而无需重新编译程序集。 由于程序集被复制到不同的位置,在编译它的项目之外,在“调试”模式下,我无法使用相对路径加载文件。

How can I programmatically get the path of the current project in my C# code?

Do I have any preprocessor directives for this? Or any macros?

Note: I don't need the path of the current executing assembly, but rather a path of the project, from which this assembly was compiled.

Note (2) - What I'm trying to achieve: I have several files that are compiled as embedded resources. I load and use them in the runtime. I would like to create a "debug" mode, in which the files are loaded from their original location on disk and not from the resource stream. This would enable me to fast-edit the files for test purposes without the need to recompile the assembly. Since the assembly is copied to a different location, outside the project from which it was compiled, in the "debug" mode I can't load the files using relative path.

最满意答案

您可能可以使用CallerFilePathAttribute。

https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callerfilepathattribute(v=vs.110).aspx

You might be able to make use of the CallerFilePathAttribute.

https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callerfilepathattribute(v=vs.110).aspx