0

I am trying to publish an ASP.NET Core 5 project using FTP. However, I do not want to publish the App_Data folder.

Using Visual Studio 2017, I opened the .csproj file and added the following

<ItemGroup>
    <Content Remove="App_Data" />
</ItemGroup>

<ItemGroup>
      <Content Update="App_Data">
          <CopyToPublishDirectory>Never</CopyToPublishDirectory>
      </Content>
</ItemGroup>

<ItemGroup>
    <None Remove="App_Data" />
</ItemGroup>

I also added

<ExcludeFoldersFromDeployment>App_Data</ExcludeFoldersFromDeployment>

to the .pubxml file.

That did not work.

How can I exclude the App_Data entirely from being published?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jay
  • 1,168
  • 13
  • 41
  • _Why_ do you want to do this? ASP.net needs the App_Data directory to store application data for the web process. Is your intention to break the application? – JHBonarius Feb 27 '22 at 09:13
  • Possible dupe : https://stackoverflow.com/a/57524961 – JHBonarius Feb 27 '22 at 09:19
  • @JHBonarius I don't want the local files found in App_Data from my local machine to override the files in production when I deploy via FTP – Jay Feb 27 '22 at 19:20
  • [Does this answer useful to you ?](https://stackoverflow.com/a/53527057/7687666) – Jason Pan Feb 28 '22 at 14:05

1 Answers1

0

I think the easiest way is to exclude the folder in Visual Studio, like the image below.

After testing, the App_Data folder will not be included when publishing again.

enter image description here

Jason Pan
  • 15,263
  • 1
  • 14
  • 29