How to rename wwwroot folder in ASP.NET Core 1.0

As mentioned earlier in my post quick summary of what’s changed in ASP.NET Core 1.0, wwwroot folder is new addition to ASP.NET Core 1.0 project structure. It’s place to keep all your static content like images, css and js files. Though, you can remove this folder from your project but if it is present then ASP.NET Core 1.0 expects folder with name wwwroot. And you can’t change the name directly from wwwroot to anything of your choice, as it works on conventions. In this post, let’s see how to rename wwwroot folder in ASP.NET Core 1.0.

[UPDATE: Below given solution no longer works. Please visit the Updated solution here].

How to rename wwwroot folder in ASP.NET Core 1.0

Till beta 8 release, the Project.json file has the configuration setting for wwwroot folder. But with the release of RC 1, the settings were removed from project.json file and moved to a new file named hosting.json. And if you look at your solution explorer, you will find that this file is not present by default, although all other json files are present.

Rename wwwroot folder in asp.net core 1

However, the ASP.NET hosts are smart if you do not have a hosting.json file with a webroot parameter configured. If there is a wwwroot folder in the base application folder, it will default that as the webroot of your application. If there is not a wwwroot folder, it will serve the base application folder as the base of static file contents for your web application.

So to change the name, let’s first add “hosting.json” file. At the time of writing this post, there is no predefined template listed for “hosting.json” in add new item dialog box like it exists for other json files. So select JSON file template and change name to “hosting.json”. And add following line of code.

{
  "webroot" :  "AppWebRoot"
}

I renamed it to “AppWebRoot”, though you can give it any name of your choice. Save the file. And now, right-click on “wwwroot” folder and rename it to the name specified in your hosting.json file. Now build the solution and it should build successfully.

Rename wwwroot folder in aspnet core

But when you try to run your application, you may get following error.

An error occurred attempting to determine the process id of the DNX process hosting your application.

To fix the above error, delete project.lock.json file and restart Visual studio. And it should work now.

Other settings of hosting.json

We are yet to hear concrete from ASP.NET team about other settings of hosting.json file. As mentioned on github issue, following settings should be part of this file.

  • Hosting:Detailed Errors – Show detailed errors for startup failures
  • server or Hosting:Server – Specify which servers
  • app or Hosting:App – Application where the startup is
  • ASPNET_ENV or Hosting:Environment – The environment to run as (Development, Production etc)
  • webroot – Webserver root, used by IIS and static file servers.

That’s all folks. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in comments section.

Leave a Reply

Your email address will not be published. Required fields are marked *

5 × five =