8

If you create Windows Phone 8 App in Visual Studio and reference any libs with XML documentation files supplied from nuget or manually, Visual Studio will automatically pack those XML files into output XAP as well.

In our case this weird behavior of Visual Studio increases XAP size almost twice. (We have 8Mb of xml docs in total.)

There is no such problem for WP7 app projects.

How to reduce the size of the xap file by forcing Visual Studio not to pack unnecessary documentation files?

Update 14/02/2013:

Steps to reproduce the issue:

  1. Create Windows Phone 8 App project using Visual Studio
  2. Reference “Reactive Extensions – Main Library” using NuGet package manager
  3. Build solution
  4. Go to Bin folder and unpack XAP archive

You will find there lots of unnecessary XML doc files like “System.Reactive.Core.xml”

I believe this is security issue, because if you enable XML doc generation for your project (or other projects in solution), those XML docs will be packed into XAP as well – this is highly undesirable when anyone may read comments to your code.

A-student
  • 785
  • 1
  • 5
  • 12

1 Answers1

6

Updated on 20/02/2013

As @A-student pointed out in the comments, my previous solution would force you to add the MSBuild stuff in each and every project in a solution.

This one only requires you enter it on the projects that actually have a XAP/APPX file output:

<PropertyGroup>
  <FilesToXapDependsOn>$(FilesToXapDependsOn);AfterFilesToXapDependsOn</FilesToXapDependsOn>
</PropertyGroup>
<Target Name="AfterFilesToXapDependsOn">
  <ItemGroup>
    <FilteredPackagingOutputs Remove="@(FilteredPackagingOutputs)" Condition="'%(FilteredPackagingOutputs.OutputGroup)' == 'CopyLocalFilesOutputGroup' AND '%(FilteredPackagingOutputs.Extension)' == '.xml'" />
  </ItemGroup>
</Target>

It's a bit of a hack and should be used carefully (not sure right now of what implications this might actually have), but seems to do the job perfectly for now!

Pedro Lamas
  • 7,185
  • 4
  • 27
  • 35
  • 1
    Thanks for the reply. I've tested your solution and found that XML doc files are removed from the output dir but still get packed into XAP :( – A-student Feb 15 '13 at 13:18
  • Right now the above solution seems to be working fine both in WP8 and Win8 apps, can you provide a sample project of yours for me to test? Are you using Visual Studio Express? – Pedro Lamas Feb 15 '13 at 13:32
  • Please ensure that you actually do a clean + build (or rebuild) of the solution! If nothing else works, fell free to contact me directly (contacts in my profile) – Pedro Lamas Feb 15 '13 at 13:54
  • I tried the same things by adding Bing map SDK in Win8 app, there's nothing change in the size of APPX. Can you please test this ? – Farhan Ghumra Feb 18 '13 at 05:40
  • 2
    @Pedro After investigating the problem more deeply, i find that one should modify each WP8 project file in the VS solution (not just main one) - this helped me. Thank you very much for the work done! – A-student Feb 18 '13 at 07:47
  • 1
    Happy to see the solution. I think that this is a actual problem that every WP8/W8 app developer must know. Probably every WP8/W8 app in the store is already large in size than it must be. –  Feb 18 '13 at 14:18
  • After reading your comments, I rechecked and confirmed that you did have to add that to ALL projects... I've edited my answer with a new solution that only requires to be added to the main project. – Pedro Lamas Feb 20 '13 at 16:43