1

My ASP.Net Core app has an App_Data folder located under the project root:

Folders

(As I recall -- I may be mistaken -- I had to manually create that folder in the project. The template didn't give it to me automatically.)

My problem is that changes to the files in the App_Data folder are not pushed to Azure when I publish my project. I'm using VS Pro 2019.

When I first published the project, the App_Data folder and its contents were pushed to Azure. But, as I said, changes are ignored.

Here's the larger issue that I don't understand: Apparently, the App_Data folder is special. At least, it's got an entry in the publish profile. And I've seen lots of questions and uninformed answers about difficulties publishing (or not publishing) files that live in this magic folder. But I've never seen anything close to official documentation that talks about this bit of magic.


Here is my publish profile:

    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <ResourceId>/subscriptions/xxx/resourceGroups/Production/providers/Microsoft.Web/sites/xxx</ResourceId>
    <ResourceGroup>Production</ResourceGroup>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>http://xxx.azurewebsites.net</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <ProjectGuid>xxx</ProjectGuid>
    <MSDeployServiceURL>xxx.scm.azurewebsites.net:443</MSDeployServiceURL>
    <DeployIisAppPath>xxx</DeployIisAppPath>
    <RemoteSitePhysicalPath />
    <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <UserName>$xxx</UserName>
    <_SavePWD>True</_SavePWD>
    <_DestinationType>AzureWebSite</_DestinationType>
    <InstallAspNetCoreSiteExtension>False</InstallAspNetCoreSiteExtension>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <SelfContained>false</SelfContained>
    <_IsPortable>true</_IsPortable>
  </PropertyGroup>
</Project>

and here is my project file (edited for brevity):

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <UserSecretsId>aspnet-xxx</UserSecretsId>
    <ApplicationInsightsResourceId>/subscriptions/xxx/resourcegroups/xxx/providers/microsoft.insights/components/xxx</ApplicationInsightsResourceId>
    <ApplicationInsightsAnnotationResourceId>/subscriptions/xxx/resourcegroups/MyIndigoHealth/providers/microsoft.insights/components/xxx</ApplicationInsightsAnnotationResourceId>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <TypeScriptToolsVersion>3.1</TypeScriptToolsVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.6.1" />
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />
    <PackageReference Include="Neleus.DependencyInjection.Extensions" Version="1.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Areas\Identity\Services\" />
  </ItemGroup>

  <ItemGroup>
    <WCFMetadata Include="Connected Services" />
  </ItemGroup>

</Project>
Bob.at.Indigo.Health
  • 11,023
  • 13
  • 64
  • 111

2 Answers2

2

According to the official documentation:

The Content item list contains files that are published in addition to the build outputs. By default, files matching the pattern wwwroot/** are included in the Content item.

The implication (not clearly stated) is that ONLY build outputs and wwwroot/** are published.

Later in the same documentation, they give examples (without explanation) of markup that adds additional files to the set of files being published. Based on those examples, I cooked up this markup. Adding this to the project (csproj) file causes changed files in the App_Data folder to be published:

<ItemGroup>
    <DotnetPublishFiles Include="App_Data/**/*">
        <DestinationRelativePath>App_Data/%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
    </DotnetPublishFiles>
</ItemGroup>

This still leaves a couple of related mysteries:

  1. What does the <ExcludeApp_Data> element really do?
  2. Apparently, the initial Publish (from Visual Studio) pushes the App_Data folder to the server. Why does this happen, when experimentation and the above-referenced documentation says that subsequent attempts to publish ignore the App_Data folder (and, indeed, any folder outside of wwwroot)?
Bob.at.Indigo.Health
  • 11,023
  • 13
  • 64
  • 111
1

If you right click your web project and select Publish > Settings > File Publish Options, then uncheck "Exclude files from the App_Data folder" what happens?

publish

Mitch Stewart
  • 1,253
  • 10
  • 12
  • It looks like the App_Data folder already isn't excluded in his publish profile: `False` – Marc Apr 25 '19 at 20:15
  • That's correct. The publish profile does not lie... the check box in the UI is already unselected. – Bob.at.Indigo.Health Apr 25 '19 at 20:47
  • I've also tried marking the files as "content" (as opposed to "none"). That made no difference. – Bob.at.Indigo.Health Apr 25 '19 at 20:48
  • Perhaps this longwinded, accepted answer will help you: https://stackoverflow.com/questions/8900005/how-do-i-get-msdeploy-to-create-app-data-if-it-doesnt-exist-but-not-delete-any. – Mitch Stewart Apr 25 '19 at 21:07
  • And here's the larger issue that I don't understand: Apparently, the `App_Data` folder is special. At least, it's got an entry in the publish profile. And I've seen lots of questions and uninformed answers about difficulties publishing (or not publishing) files that live in this magic folder. But I've never seen anything close to official documentation that talks about this bit of magic. – Bob.at.Indigo.Health Apr 26 '19 at 00:51