Including a Hidden Folder in ASP.NET Publish

Screenshot of a Hidden Folder in an ASP.NET Project Ever want to include a hidden folder and files in your publish output from an ASP.NET project? It's something you might have to do for files you need to place in a folder like .well-known (the one I have the screenshot of below is for a Brave Rewards verification file). It's actually pretty easy to include hidden folders in publish, but there's no way to do it in the UI that I'm aware of.

Including the actual hidden folder in the wwwroot folder is straightforward, and works just like you'd expect in the UI.

However, when you publish it (at least, at the time this post is being written), the folder is not included in the publish output. The easiest way I know of to include it is to edit the .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <!-- Snip -->
  </PropertyGroup>
  <!-- Snip -->
  <ItemGroup>
    <Content Include="wwwroot\.well-known\**" CopyToPublishDirectory="PreserveNewest" Exclude="$(DefaultItemExcludes)" />
  </ItemGroup>
  <!-- Snip -->
</Project>

The key here is the ItemGroupContent element directly under Project. After you add that, your hidden folder should be in the publish output.