Search code examples
c#namespacesroslyn

How get default namespace of project with roslyn?


I have an c# project. I have renamed NameSpaceDeclarationSyntax for example namespace1 to namespace2 . When I compiled this project with visual studio and roslyn api I find out that visual studio has embedded the all resources of project with namespace2 just the resources file in properties folder has embedded with default namespace of project.

I have embedded all resources with namespace2 with roslyn and because of this it doesn't run .

the following exception had thrown :

Couldn't find any resources appropriate for specified culture or the neutral culture. Make sure namespace1.properties.Resources.resources was correctly embedded or linked into assembly "assemblyname" ...

I must change the default namespace of project or get the default namespace and embed with that but I don't know how find or change default namespace of project ?


Solution

  • The default namespace is a property of MSBuild and Visual Studio, not the compilers themselves. Therefore, you won't find it in the Roslyn API.

    Instead, you can change the <RootNamespace> element directly in the project file.

    You can see how Roslyn's Visual Studio layers get the default namespace here.