Wednesday, March 11, 2009

Web setup project - content files - Vs.net 2008

Problem
In one of my project, I had Vs.net 2008 web project including multiple c# projects. 

I create a web setup project in the same solution but when deployed I noticed that PDF files are not included in the deployment. (Not webdeployment project)

Solution
By default, VS.net  project do not include PDF files as content files. (.js, .css, .jpg ... are included by default)

I posted on forums, and the solution is ...

Approach 1: Mark the file as content. Right click the file in Vs.net 2008, properties, set build action -> Content. You may have to do for every file. 

In other words, modify your web application's project file to set pdf files to "Content" by

<ItemGroup>

    <Content Include="YourFolder\Reference1.pdf"/>

     <Content Include="YourFolder\Reference2.pdf"/>

 ......

</ItemGroup>

 Using IDE does the modification for you.


Aprroach 2: Mark the whole folder to copy ...

If these pdf files are in one folder, we can try to use MSBuild to copy this folder to OutPut directory in Web Deployment project.

To do so, we need to enter Web Deployment project file by right clicking Web Deployment project in Solution Window and selecting "Open Project File", and then write following command below "Import" section:

<Target Name="AfterBuild">

<Copy DestinationFolder="YourDestinationfolder" SourceFiles="YourSourcefile"></Copy>

</Target>  

Example

<Copy DestinationFolder="Guides" SourceFiles="Guides\*.pdf"></Copy>

Or

<Copy DestinationFolder="$(OutputPath)\Guides\" SourceFiles="$(SourceWebPhysicalPath)\Guides\*.pdf"></Copy>

No comments: