title: WPF: LibVLCSharp integration in setup project/release version
body: <p>So I have been against a wall for this one for a while now.</p>
  <p>My requirement is to play <code>.mp4</code> video file in a wpf application. Sounds simple enough, right?</p>
  <p>At first, I used built-in <code>MediaElement</code> class and everything worked.</p>
  <p>But it turns out, <code>MediaElement</code> is based on <code>Windows Media Player</code>, and for people (myself included) who are using <code>Windows 10 Pro N (or KN)</code> versions, which are basically stripped-down versions of Windows 10, videos are not playing, because <code>Windows Media Player</code> is not included.</p>
  <p>That is also reported by attaching an error callback to <code>MediaElement</code>, resulting in message:</p>
  <p><code>&quot;Windows Media Player version 10 or later is required&quot;</code></p>
  <p>Of course, one option is to show user a message and a link to download the feature pack (<a href="https://www.microsoft.com/en-us/software-download/mediafeaturepack" rel="nofollow noreferrer">https://www.microsoft.com/en-us/software-download/mediafeaturepack</a>), which includes <code>Windows Media Player</code>, but in all my years using Windows apps, I have NEVER seen any app do/ask that. It is also wrong - the feature pack comes with alot more than just WMP and user might not want to bloat their system with unnecessary apps. That's why user chose <code>Windows 10 Pro N (or KN)</code> in the first place.</p>
  <p>But then - how do other apps do it? How are videos on Slack, Discord apps played on my <code>Windows 10 Pro N</code>?</p>
  <p>A bit of googling and general solution is to use <code>VideoLAN.LibVLC.Windows</code> framework, because it is open-sourced, well maintained and has proven itself over the years on multiple platforms.</p>
  <p>Ok, I get it's nuget package, and since it is native code, I also download a wrapper libraries to use it in WPF - <code>LibVLCSharp</code> and <code>LibVLCSharp.WPF</code>.</p>
  <p>I have successfully integrated video playback, everything works in Debug version.</p>
  <p>Now it's time to test it in Release version. I create a new <code>Setup project</code>, build it, install it.</p>
  <p><strong>So here's the problem:</strong></p>
  <p>My app runs just fine, but when I get to the section where video is supposed to play, I get an exception error:</p>
  <pre><code>Failed to load required native libraries. 
  Have you installed the latest LibVLC package from nuget for your target platform?
  Search paths include 
  C:\Program Files (x86)\My app\libvlc\win-x64\libvlc.dll,
  C:\Program Files (x86)\My app\libvlc\win-x64\libvlccore.dll; 
  C:\Program Files (x86)\My app\libvlc\win-x64\libvlc.dll,
  C:\Program Files (x86)\My app\libvlc\win-x64\libvlccore.dll; 
  C:\Program Files (x86)\My app\libvlc.dll,
  </code></pre>
  <p>So, in my install directory <code>C:\Program Files (x86)\My app\</code>, I find these 2 dlls:</p>
  <pre><code>LibVLCSharp.dll
  LibVLCSharp.WPF.dll
  </code></pre>
  <p>I check the Debug version's folder (because it was working just fine there) and I see that I also have a <code>libvlc</code> folder being generater there, with contents:</p>
  <pre><code>libvlc
  - win-x64
  -- hrtfs
  -- locale
  -- lua
  -- plugins
  -- libvlc.dll
  -- libvlc.lib
  -- libvlccore.dll
  -- libvlccore.lib
  - win-x86
  -- hrtfs
  -- locale
  -- lua
  -- plugins
  -- libvlc.dll
  -- libvlc.lib
  -- libvlccore.dll
  -- libvlccore.lib
  </code></pre>
  <p>I copy that folder to my install directory and videos are now playing.
  Ok, I can automate that folder copy during installation.</p>
  <p>But now the problem is <strong>size</strong>.</p>
  <p>My app is 10 MB in size. That <code>libvlc</code> folder is 324 MB in size.
  It is quite unacceptable for a small 10 MB app to suddenly grow to be 334 MB large. I would understand 10-20 MB increase, but not by this much.</p>
  <p>I understand, that I can create two seperate installations - one for <code>x64</code> and one for <code>x86</code> systems.
  Great, that splits size in half.</p>
  <p>Then by trial and error, I removed things from those folders that my app can live without and still play the videos.</p>
  <p>I am left with this structure, which runs fine:</p>
  <pre><code>libvlc
  - win-x64
  -- plugins
  -- libvlc.dll
  -- libvlccore.dll
  </code></pre>
  <p>But it still weighs 125 MB. If I delete anything from plugins folder, app crashes.</p>
  <p>Is there a better/correct way of including this &quot;libvlc&quot; folder to my Release version, without it blowing up my installer size?</p>
  <p>Perhaps there is another, more lightweight framework that can play <code>.mp4</code> files?</p>
  <p>Did I jump into the wrong rabbit hole?</p>
  <p><strong>====================== Update ======================</strong></p>
  <p>Solved, thanks to <strong>@cube45</strong> suggestion.</p>
  <p>Indeed, I can delete plugins that I don't need, thus saving space (I initially deleted a required one, so I assumed all were mandatory, simply unlucky).</p>
  <p>So again, by trial and error I only left those files that were needed for successfully displaying video.</p>
  <p>The resulting list:</p>
  <pre><code>libvlc
  - win-x64
  -- libvlc.dll
  -- libvlccore.dll
  -- plugins
  --- access
  ---- libimem_plugin.dll
  --- codec
  ---- libavcodec_plugin.dll
  ---- libd3d11va_plugin.dll
  --- video_output
  ---- libdirect3d9_plugin.dll
  ---- libdirect3d11_plugin.dll
  ---- libdrawable_plugin.dll
  ---- libvmem_plugin.dll
  </code></pre>
  <p>Same for x86 configuration.</p>
  <p>The main problem, why the <code>libvlc</code> folder wasn't being generated in the install directory, was because I needed to explicitly add a content output for that directory.</p>
  <p>I did so by:</p>
  <pre><code>1. Right clicked on **my setup project -&gt; View -&gt; File System**
  2. Right clicked on **Application Folder -&gt; Add -&gt; Project Output**
  3. Selected **Content Files -&gt; Ok**
  </code></pre>
  <p>And voila - now <code>libvlc</code> folder with it's contents are included in the installer file and placed in install directory.</p>
  <p>However, even compressed, the installer file now is 140 MB large, because it included <strong>whole</strong> <code>libvlc</code> folder. We need to include only those files we need and skip the rest.</p>
  <p>So that's where the link <strong>@cube45</strong> provided came in handy.
  Process, where we select only those files/folders that we need, is called <code>Cherry picking</code>. So I added following to <code>*.csproj</code> file:</p>
  <pre><code>  &lt;ItemGroup&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;libvlc.dll&quot; /&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;libvlccore.dll&quot; /&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;plugins\access\libimem_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;plugins\codec\libavcodec_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;plugins\codec\libd3d11va_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;plugins\video_output\libdirect3d9_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;plugins\video_output\libdirect3d11_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;plugins\video_output\libdrawable_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX64IncludeFiles Include=&quot;plugins\video_output\libvmem_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;libvlc.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;libvlccore.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;plugins\access\libimem_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;plugins\codec\libavcodec_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;plugins\codec\libd3d11va_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;plugins\video_output\libdirect3d9_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;plugins\video_output\libdirect3d11_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;plugins\video_output\libdrawable_plugin.dll&quot; /&gt;
      &lt;VlcWindowsX86IncludeFiles Include=&quot;plugins\video_output\libvmem_plugin.dll&quot; /&gt;
    &lt;/ItemGroup&gt;
  </code></pre>
  <p>And voila - now my installation file weighs only 23 MB, which is completely acceptable!</p>
  <p>Oh and that size can be cut down by half, because this was built for <code>Any CPU</code> configuration. So if I split this installation into two seperate ones, the weight would be ~11.5 MB (but then a whole new set of problems would occur, so I'm not gona delve into that).</p>
  <p>Long story short - <strong>success!</strong></p>