How get the default namespace of project csproj (VS 2008)

前端 未结 5 1577
终归单人心
终归单人心 2020-12-20 14:05

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

5条回答
  •  独厮守ぢ
    2020-12-20 14:32

    It is also possible to get the DefaultNameSpace from the DTE. Very usefull if you are developing a Visual Studio Extension.

    EnvDTE.DTE dte = GetService(typeof(DTE)) as DTE;
    EnvDTE.Projects projects = dte?.Solution.Projects;
    if (projects != null)
    {
      foreach (EnvDTE.Project project in projects)
      {
        string defaultNameSpace1 = project.Properties.Item("DefaultNameSpace").Name;
        foreach (EnvDTE.ProjectItem projectItem in project.ProjectItems)
        {
          string defaultNameSpace2 = projectItem.Properties.Item("DefaultNameSpace").Name;
        }
      }
    }
    

提交回复
热议问题