How to include custom folders when publishing a MVC application?

Solution 1:

I did this for a web api project (not dot net core) which had Angular 6 as a front end. My visual studio version was 2017.

I had created a wwwroot folder where I was compiling angular files via custom build action & this folder was not included in my project.

I edited the project file & added these lines.

<PropertyGroup>
    <PipelineCollectFilesPhaseDependsOn>
    CustomCollectFiles;
    $(PipelineCollectFilesPhaseDependsOn);
  </PipelineCollectFilesPhaseDependsOn>
  </PropertyGroup>

  <Target Name="CustomCollectFiles">
    <Message Text="Inside of CustomCollectFiles" Importance="high" />
    <ItemGroup>
      <_CustomFiles Include="wwwroot\**\*" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>wwwroot\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>

Solution 2:

I believe you need to set the folder's "Build Action" to "Content":

What are the various "Build action" settings in Visual Studio project properties and what do they do?

Solution 3:

Go to Project Properties > Package / Publish Web

Then select the configuration combo that you want to setup up.

Below you have the Items to deploy. I just tested here with "All files in this project folder" and everything was published.

The only downside is that everything is getting deployed, I don't know if this is what you want.

Solution 4:

I tried all solutions above, but none of them worked. I'm using VS2017 and wasn't able to folder publish some help files. I edited the project file (.csproj) and added the following lines somewhere in de file.

<ItemGroup>
    <Content Include="HelpFiles\**\*" />
</ItemGroup>

When I push the publish button all my help files are copied to the publish directory.