Search code examples
c#asp.net-corelets-encrypt

Add .well-known to asp.net core


I want to have a .well-known directory in my root for letsencrypt renewals.

I have added a route to .well-known like so:

 app.UseStaticFiles(new StaticFileOptions
        {
            FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @".well-known")),
            RequestPath = new PathString("/.well-known"),
            ServeUnknownFileTypes = true // serve extensionless file
        });

I added a direcotry inside my wwwroot called .well-known but it never gets copied to the output when I publish.

I tried adding a file to it and also edit csproj:

  <ItemGroup>
    <Content Include="wwwroot\.well-known\" />
  </ItemGroup>

Every time I publish I have to manually create the directory. How do I get it automatically added to the wwwroot?


Solution

  • I tried adding a file to it and also edit csproj:

    <ItemGroup>
      <Content Include="wwwroot\.well-known\" />
    </ItemGroup>
    

    You can't copy over folders via Content, only files. You have to change it to

    <ItemGroup>
      <Content Include="wwwroot\**">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      </Content>
    <ItemGroup>
    

    and like mentioned in the comments, you need to put an empty dummy file inside.