14

Is there a way to set visual studio to publish all pdf files?

I know that you can set each individual pdf file in a project with the Build Action "Content" property.

But that means doing the same thing 100's of times for my current project, is there a way to change a global setting to do the same thing?

TheAlbear
  • 5,507
  • 8
  • 51
  • 84
  • Publish PDF files? How about putting the PDF files outside your project and mapped them via virtual folder at your webserver? – o.k.w Oct 29 '09 at 10:57
  • The web servers not really the issues, the problem is getting pdf fiels whicvh are used and manuals / documents / downloads are added to the project, but you need to set each one so that when you publish there are transfered to the server. once there its all fine. – TheAlbear Oct 29 '09 at 11:02
  • How about using multi-selection? Just a few mouse clicks and you are done. Or, if you PDF documents are spread among the project tree, open the project file in a text editor and do a global search and replace. – Dirk Vollmar Oct 29 '09 at 11:31
  • Still menas clicking on each file, i was hopig there was a global setting for all projects that i could set and then forget about. – TheAlbear Oct 29 '09 at 11:44
  • I have found that you can now select multiple files and change the build options on all of then at the same time, which saves some time. – TheAlbear May 27 '11 at 12:16

7 Answers7

14

there is an easier way, you have to make sure your file is included in the project first, then right-click on the file go to properties, there will be an option "copy to output directory", choose "copy always"

Good luck

Dmitry.Alk
  • 570
  • 5
  • 6
  • 8
    You also need to set the "Build Action" to "Content", then this is the best answer. – paul Dec 08 '10 at 05:23
  • 3
    -1 Copy always copies it to the bin directory. Vinblad's answer is the correct one. Change the build action to content. – adam0101 Jun 13 '12 at 15:17
  • Thank you @paul .. `Copy Always` by itself doesn't do the trick. Setting the build action solves the problem. – cowsay Oct 18 '13 at 19:07
14

Just right click on the file you want to include, choose properties, in the properties window change build action to content. This will include the file during publish.

Vinblad
  • 676
  • 1
  • 7
  • 18
5

Add a post build event with the following command:

xcopy "$(ProjectDir)myPdfs\*.pdf" "$(TargetDir)myPdfs\" /S /Y

Note in the above command myPdfs is just a subfolder of your project directory that contains all the PDF files. If you have more than one of these subfolders you need to run the command for each.

Hope this works!!

Scott Willeke
  • 8,884
  • 1
  • 40
  • 52
3

Suppose you had the PDFs you wish to deploy outside the project in c:\PDFs, modify the .csproj

<ItemGroup>
    <Content Include="c:\PDFs\**\*.pdf" />
</ItemGroup>

If they're in a folder "MyPdfs" relative to the root of the project

<ItemGroup>
    <Content Include="MyPdfs\**\*.pdf" />
</ItemGroup>

Some further details about this can be found on: https://stackoverflow.com/a/12202917/37055

Community
  • 1
  • 1
Chris Marisic
  • 32,487
  • 24
  • 164
  • 258
2

Open the csproj file and change :

<None Include="my.pdf">

to:

<Content Include="my.pdf">
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
ben
  • 21
  • 1
1

You could edit your project file directly to add the required <CopyToOutputDirectory>Always</CopyToOutputDirectory> elements to the PDF files. (If your project isn't under source control, test on a copy first and keep backups in case it all goes wrong)

stuartd
  • 70,509
  • 14
  • 132
  • 163
1

CopyToOutputDirectory will copy the files to the bin folder when you publish. Setting "Build Action" to "Content" will copy the files without the need of CopyToOutputDirectory setting. But this is still needs to be done on each file. You could make a regex replace in project file from <None Include="XXX.pdf" /> to <Content Include="XXX.pdf" />.

adam0101
  • 29,096
  • 21
  • 96
  • 174
Mårten
  • 11
  • 1