[SalesForce] Create scratch org with namespace

How do I create a scratch org that has the same namespace as my Developer Edition org where the managed package is held?

I've followed the instructions in the "Link a Namespace to a Dev Hub Org" page to link the namespace to my Dev Hub org, but I cannot find any instructions on any of the documentation pages below for how to actually create a new scratch org that has the same namespace as my DE org.

Best Answer

In the project configuration file, specify the namespace.

{ 
"packageDirectories" : [ 
    { "path": "force-app", "default": true}
  ],
"namespace": "myns", 
"sfdcLoginUrl" : "https://login.salesforce.com", 
"sourceApiVersion": "44.0"
}

This really only alluded to in the documentation, but sfdx-project.json is the key to creating a scratch org with a namespace.