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

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

问题描述

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");

Update:

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 ??

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

解决方案

You can't.

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

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.

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天全站免登陆