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?

8 Answers 8

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>
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?

5
  • 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 3, 2013 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, 2014 at 16:01
  • 18
    Folders don't have Build Action or am I missing something? Only files have. Jun 23, 2016 at 9:30
  • 2
    @Frinavale Also, you should set the "Copy to Output Directory" option of the file properties to "Copy if newer" Oct 23, 2017 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. Jan 27, 2021 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.

1
  • 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, 2021 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.

1
  • Yes, that list seems too general. But something I did not know.
    – SamJolly
    Sep 3, 2013 at 22:05
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

0
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

-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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.