如何获取项目csproj的默认名称空间(VS 2008) [英] How get the default namespace of project csproj (VS 2008)

查看:109
本文介绍了如何获取项目csproj的默认名称空间(VS 2008)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有VS 2008和csproj项目(C#库).

I have VS 2008 and csproj project (C# Library).

在项目的属性中,具有程序集名称和默认名称空间. 注意:每个类都有一个名称空间.

In properties of project, has an assembly name, and default namespace. Note: each class has a namespace.

是否可以在运行时获取默认名称空间的值?

Is it possible, in runtime, get the value of default namespace ??

我的目标是使用资源,我需要默认名称空间的值:

My target is use resources, and I need default namespace's value:

 Assembly assembly = Assembly.GetExecutingAssembly();

 //foreach (string resourceName in assembly.GetManifestResourceNames()){}

 Stream syntaxModeStream = assembly.GetManifestResourceStream(pathToResources
+ ".SyntaxModes.xml");

更新:

皮特说我不能.默认名称空间不存储在程序集中

Pieter said I can't. Default namespace don't stored in assembly

var resource = assembly.GetManifestResourceNames().Single(p => p.EndsWith(".SyntaxModes.Xml"))

默认的名称空间存储在哪里?

where is the default namespace stored ??

我只能使用Addins Visual Studio(DTE对象)阅读??

Only can I read using Addins Visual Studio (DTE object) ??

推荐答案

您不能.

默认名称空间未存储在程序集中的任何位置.这只是Visual Studio的项目设置.

The default namespace isn't stored anywhere within the assembly. It's just a project setting of Visual Studio.

我倾向于做的是使用程序集的名称:Assembly.GetName().Name.问题在于它仅在程序集名称未更改的情况下才有效.

What I tend to do is use the name of the assembly: Assembly.GetName().Name. The problem with this is that it only works if the assembly name has not been changed.

对于您的特定问题,您可以使用assembly.GetManifestResourceNames()并对这些名称进行一些测试,例如:

For your specific issue, you can use assembly.GetManifestResourceNames() and do some tests over those names, e.g.:

string name = assembly.GetManifestResourceNames().Single(p => p.EndsWith(".SyntaxModes.Xml"))

这篇关于如何获取项目csproj的默认名称空间(VS 2008)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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