Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the default namespace in projects using project.json (.xproj)

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?

like image 844
Muhammad Rehan Saeed Avatar asked Feb 24 '16 12:02

Muhammad Rehan Saeed


People also ask

Where do we can change default namespace of a project?

You can change the default namespace: -> Project -> XXX Properties... Instead of Find/Replace, you can also right click the namespace in code and Refactor->Rename. my Default Namespace textbox in project properties is disabled.

What is Project JSON file in ASP NET MVC?

The project. json file used by NuGet is a subset of that found in ASP.NET Core projects. In ASP.NET Core project. json is used for project metadata, compilation information, and dependencies.

How do I open a project JSON file?

Right click your project and select "Edit ProjectName. csproj" to view the file.


2 Answers

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.

like image 122
nover Avatar answered Oct 13 '22 23:10

nover


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.

like image 42
danludwig Avatar answered Oct 13 '22 23:10

danludwig