ASP.NET Core directory structure

By Luke Latham

In ASP.NET Core, the published application directory, publish, is comprised of application files, config files, static assets, packages, and the runtime (for self-contained deployments).

App Type Directory Structure
Framework-dependent Deployment
  • publish†
    • logs† (optional unless required to receive stdout logs)
    • Views† (MVC apps; if views aren't precompiled)
    • Pages† (MVC or Razor Pages apps; if pages aren't precompiled)
    • wwwroot†
    • *.dll files
    • <assembly-name>.deps.json
    • <assembly-name>.dll
    • <assembly-name>.pdb
    • <assembly-name>.PrecompiledViews.dll
    • <assembly-name>.PrecompiledViews.pdb
    • <assembly-name>.runtimeconfig.json
    • web.config (IIS deployments)
Self-contained Deployment
  • publish†
    • logs† (optional unless required to receive stdout logs)
    • refs†
    • Views† (MVC apps; if views aren't precompiled)
    • Pages† (MVC or Razor Pages apps; if pages aren't precompiled)
    • wwwroot†
    • *.dll files
    • <assembly-name>.deps.json
    • <assembly-name>.exe
    • <assembly-name>.pdb
    • <assembly-name>.PrecompiledViews.dll
    • <assembly-name>.PrecompiledViews.pdb
    • <assembly-name>.runtimeconfig.json
    • web.config (IIS deployments)

†Indicates a directory

The publish directory represents the content root path, also called the application base path, of the deployment. Whatever name is given to the publish directory of the deployed app on the server, its location serves as the server's physical path to the hosted app.

The wwwroot directory, if present, only contains static assets.

The stdout logs directory can be created for the deployment using one of the following two approaches:

  • Add the following <Target> element to the project file:

    <Target Name="CreateLogsFolder" AfterTargets="Publish">
       <MakeDir Directories="$(PublishDir)Logs" 
                Condition="!Exists('$(PublishDir)Logs')" />
       <WriteLinesToFile File="$(PublishDir)Logs\.log" 
                         Lines="Generated file" 
                         Overwrite="True" 
                         Condition="!Exists('$(PublishDir)Logs\.log')" />
    </Target>
    

    The <MakeDir> element creates an empty Logs folder in the published output. The element uses the PublishDir property to determine the target location for creating the folder. Several deployment methods, such as Web Deploy, skip empty folders during deployment. The <WriteLinesToFile> element generates a file in the Logs folder, which guarantees deployment of the folder to the server. Note that folder creation may still fail if the worker process doesn't have write access to the target folder.

  • Physically create the Logs directory on the server in the deployment.

The deployment directory requires Read/Execute permissions. The Logs directory requires Read/Write permissions. Additional directories where files are written require Read/Write permissions.