How to Include Files to Publish in ASP.NET

This ASP.NET post will show you how to include files to publish in ASP.NET application when deploying to Azure Web App.

By default, The ASP.NET template will not publish files not part of the template. This post will show you how to add files using Visual Studio and VS Code.

For example, if you have a text file or other configuration files, when you publish your app to an Azure Web App, the files are not included and will not appear in the Azure Web App file system.

This is a default behaviour; the issue is not with Azure, the Azure Web App, or the App Service.

How to Include Files to Publish in ASP.NET

To include template files with our application and publish them to an Azure Web App or other platform, we need to add them to the configuration.

In the following example, I have a text file called TextFile.txt in the root of my Blazor project.

TextFile.txt

If I go ahead and publish the project Azure, this file won’t be available in Azure.

Use Visual Studio to Include Files to Publish in ASP.NET

To include and publish the file with the solution, right-click on the File (or folder) and click on Properties.

CopyToPublishDirectory

In the Properties page, set the following:

  • Build action = Content
  • Copy to Output Directory – Copy always

Once you set the copy properties, go ahead and publish your solution.

Use VS Code to Include Files to Publish in ASP.ET

If you are using VS code, use the following with

<ItemGroup>
  <Content Include="TextFile.txt">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.