开发者

How to set Visual Studio to Publish pdf files automatically

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

I know that you can set each indi开发者_运维问答vidual 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?


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


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.


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


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


Open the csproj file and change :

<None Include="my.pdf">

to:

<Content Include="my.pdf">


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)


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" />.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜