简体   繁体   English

在C#.Net中查找工作项目目录

[英]Find Working Project Directory in C#.Net

I have used Directory.getCurrentDirectory(); 我用过Directory.getCurrentDirectory();

its giving only C:\\Windows\\SysWOW64 它只给C:\\ Windows \\ SysWOW64

but i need to get the visual studio default project folder how can i get that ? 但是我需要获取Visual Studio默认项目文件夹,我该如何获取?

ex:C:\\Users\\knallasi\\Documents\\Visual Studio 2010\\Projects\\SampleApp 例如:C:\\ Users \\ knallasi \\ Documents \\ Visual Studio 2010 \\ Projects \\ SampleApp

how do we find that above project location ? 我们如何在项目位置上方找到该位置?

Thanks in Advance 提前致谢

I'm not sure about the PROJECT directory, but the directory of the executing assembly can be found by using 我不确定PROJECT目录,但是可以使用以下命令找到执行程序集的目录

string currentAssemblyDirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

usually, if you're executing in Visual Studio, the project directory is up two levels, you you could trim "bin\\release| or "bin\\debug" of that string to get the project directory, but that's a bit of a hack. I'm not sure there is a way to get the project directory from code. 通常,如果您在Visual Studio中执行,则项目目录有两个层次,您可以修剪该字符串的“ bin \\ release |或“ bin \\ debug”以获取项目目录,但这有点麻烦我不确定是否有办法从代码中获取项目目录。

After lots of searching I found the "dirty hack" solution for accessing things like $(ProjectDir) from within your code. 经过大量搜索,我发现了一种“肮脏的黑客”解决方案,可从您的代码中访问$(ProjectDir)之类的东西。

What's an easy way to access prebuild macros such as $(SolutionDir) and $(DevEnvDir) from code in C#? 从C#中的代码访问$(SolutionDir)和$(DevEnvDir)等预构建宏的简单方法是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM