19

I have an "Uploads" folder with logos within in. I would like the VS2012 one-click publish to include this folder. Currently it is not.

How can I achieve this?

LCJ
  • 22,196
  • 67
  • 260
  • 418
SamJolly
  • 6,347
  • 13
  • 59
  • 125

8 Answers8

11

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>
Abdul Rehman Sayed
  • 6,532
  • 7
  • 45
  • 74
9

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?

Community
  • 1
  • 1
Andy T
  • 10,223
  • 5
  • 53
  • 95
  • 1
    Thanks for this. However I am a little confused as to how/where I do this. Ideally I would like to just "include" my "Upload" folder, and all child files will be included in the publish. I did read this SO post, but still confused. – SamJolly Sep 03 '13 at 22:01
  • 10
    The only way that I found to ensure that my "empty" folder was included in the output produced by publishing my application was to add something to the folder and mark it as content. I added a text file called "info.txt" that simply stated the purpose of the folder ("to temporarily contain uploaded content"). Now the folder and text file are included in the published output. – Frinavale Aug 25 '14 at 16:01
  • 18
    Folders don't have Build Action or am I missing something? Only files have. – Daniel Dušek Jun 23 '16 at 09:30
  • 2
    @Frinavale Also, you should set the "Copy to Output Directory" option of the file properties to "Copy if newer" – Mohamed Emad Oct 23 '17 at 15:30
  • @DanielDušek You are right...In most cases you will just right click the file and change its Build Action to Content...the folder gets copied with the file. – Chris Catignani Jan 27 '21 at 20:49
7

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.

DaanH
  • 161
  • 1
  • 4
  • 2
    This should be the answer to the question. So simple and elegant. No need for a custom MSbuild task or something else. Thanks for sharing! – David Oct 21 '21 at 16:46
5

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.

CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
Hugo Hilário
  • 2,848
  • 2
  • 27
  • 43
2

There is an attribute named CopyToPublishDirectory to publish in vs profiles. You can specify this in .csproj file of the project.

<ItemGroup>     
    <Content Update="Foo\**\*" CopyToPublishDirectory="Always" />
</ItemGroup>

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

VS Publish Profiles

gurkan
  • 884
  • 4
  • 16
  • 25
1

in my case i Created a folder in the bin folder and needed to include that folder in the publish. and that code is worked for me.

<Target Name="CustomCollectFiles">
   <ItemGroup>
     <_CustomFiles Include=".\bin\Dlls\**\*" />
       <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
         <DestinationRelativePath>bin\Dlls\%(RecursiveDir)%(Filename)%(Extension) 
         </DestinationRelativePath>
       </FilesForPackagingFromProject>
  </ItemGroup>
</Target>
<PropertyGroup>
  <CopyAllFilesToSingleFolderForPackageDependsOn>CustomCollectFiles;
   ;</CopyAllFilesToSingleFolderForPackageDependsOn>
  <CopyAllFilesToSingleFolderForMsdeployDependsOn>CustomCollectFiles;
   ;</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>

hope that helps someone.

1

In visual studio 2019 community, you have to right click on the folder and then click on publish. You can see it is published to the destination i.e. existing publish folder

Shaahin
  • 1,195
  • 3
  • 14
  • 22
-1

In visual studio 2022 you can publish a content folder separately by right clicking it and selecting "publish".

While this means an extra step when publishing the whole project, it means that you can just push out new content without having to publish the server again

user430788
  • 2,143
  • 2
  • 17
  • 17