In a standard .csproj
you could go into properties and set the default namespace. How can this be achieved in a .xproj
project using project.json
?
Asked
Active
Viewed 1.6k times
22

Muhammad Rehan Saeed
- 35,627
- 39
- 202
- 311
-
2AFAIK this can't be done with a project.json. You can do it with an xproj the same way you used to do it with a csproj though. Right click it in Visual Studio, and on the Application tab, change the `Default namespace`. – danludwig Feb 24 '16 at 13:34
-
Add that as an answer, so I can mark it so. – Muhammad Rehan Saeed Feb 24 '16 at 13:53
-
1you can do it via project.json, see my answer below. – nover Oct 24 '16 at 11:51
2 Answers
41
With ASP.NET Core 1.0.1, you can set your default namespace in the project.json
file as follows:
"tooling": {
"defaultNamespace": "Your.Name.Space"
}
The yeoman ASP.NET generator will respect this defaultNamespace
when generating new classes.
For the new Visual Studio 2017 csproj
tooling, you can add the following XML to change your default namespace (up in the top level <PropertyGroup>
reference):
<PropertyGroup>
<Optimize>true</Optimize>
...
<RootNamespace>My.Root.Namespace</RootNamespace>
</PropertyGroup>
This is only necessary if your .csproj filename does not match your intended root namespace for the project.
-
-
It goes into the root of project json, so on the same level as dependencies. – nover Apr 10 '17 at 06:12
-
-
1@muhammadtayyab that's because all the new tooling from Microsoft ditched the project.json in favor of csproj files - so read the last part of my post to figure out what to do :) – nover Apr 08 '19 at 09:35
-
Yes, I was thinking for the same in .Net Core we only have .csproj file – muhammad tayyab Apr 08 '19 at 09:44
8
AFAIK this can't be done with a project.json. You can do it with an xproj the same way you used to do it with a csproj though. Right click it in Visual Studio, and on the Application tab, change the Default namespace
.

danludwig
- 46,965
- 25
- 159
- 237