Muhammad Rehan Saeed
Muhammad Rehan Saeed

Reputation: 38527

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?

Upvotes: 23

Views: 21872

Answers (2)

nover
nover

Reputation: 2369

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.

Upvotes: 46

danludwig
danludwig

Reputation: 47375

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.

Upvotes: 9

Related Questions