路径在VS2010项目资源文件 [英] Path to resource files in a VS2010 project

查看:394
本文介绍了路径在VS2010项目资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS 2010和.NET 4.0。

I'm using VS 2010 and .NET 4.0.

我创建了一个解决方案,用一个单一的控制台的C#项目。我已经通过上下文菜单中的项目添加项目的几个文件夹>添加>新建文件夹。然后,我把一些文件在里面。

I've created a solution, with a single console C# project. I've added a few folders in the project via context menu on project > Add > New folder. Then I put some files in there.

我现在希望得到的路径(或文件句柄),以这些资源之一。有没有一个很好的方式来获得它的路径?

I now wish to get the path (or file handle) to one of those resources. Is there a nice way to getting its path?

注1:该项目是在源头控制,所以我需要将工作在不同的文件路径的方式

NOTE 1: The project is on a source control, so I need a way that will work on different file paths.

注2:如果可以的话,我不想使用 Directory.GetCurrentDirectory() System.Reflection.Assembly.GetExecutingAssembly() .Location

NOTE 2: If possible, I don't want to use Directory.GetCurrentDirectory() nor System.Reflection.Assembly.GetExecutingAssembly().Location.

编辑:

看来,我想直接回答这个的问题#1。我想要的项目目录,没有斌\调试

It seems, I'd like the direct answer to this Stackoverflow question. I want the project directory, without the "bin\Debug"

推荐答案

从MSDN

string path = System.IO.Path.GetDirectoryName( 
  System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

另外,请查阅的#1的答案。

这篇关于路径在VS2010项目资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆