I'm packaging my WPF application as an MSIX package for distribution in Microsoft's store, using a Windows Application Packaging Project in Visual Studio.
Now, my application works perfectly fine. The only trouble is that the resulting .msix package seems to contain all my 'Content' resources twice: once for the project I'm packaging, and once for the packaging project.
This is how my project is structured:
A: my original WPF project, called "MyProject"
- this contains a folder called SoundEffects containing a number of mp3 files. In VS, I've set the Build Action to 'Content' and Copy to Output Directory to 'Copy if newer'. I need those files to be included separately to the .exe so the user has the ability to replace those files.
B: my packaging project, containing the appxmanifest and having MyProject set as a project reference.
The resulting .msix package is structured like this, if I open it with 7Zip:
(folder) MyProject
- (folder) SoundEffects <--- good
- ... other project binaries
(folder) SoundEffects <--- bad
AppXManifest.xml
resources.pri
[Content_Types].xml
As you can see, I get the SoundEffects folder twice. This happens for all resources, including a huge 80mb folder of dependencies added by LibVLC, which almost doubles my package size.
What I've tried:
- In the MyProject.Package.wapproj MSBUILD file, I've tried removing the content from the build like this:
<Content Remove="SoundEffects\MySoundEffect.mp3" />
<Content Remove="SoundEffects\*.*" />
I tried other paths for the remove property as well but with no luck. I'm unsure whether my approach is wrong or I misunderstand how to construct the correct path here.
- I created an MSIX Package Layout file through Visual Studio. It seems to include the files here:
<GeneratedFiles/>
<GeneratedResources/>
Below that, I tried this (relevant learn.microsoft.com page):
<Files>
<File ExcludePath="SoundEffects\MySoundEffect.mp3"/>
<File ExcludePath="SoundEffects\*.*"/>
</Files>
Unfortunately, neither does anything, and the resulting package still contains everything twice. I was hoping to keep the package layout the same, except exclude the SoundEffects folder at the package root. What am I missing?
The issue you are facing is likely due to the fact that the packaging project is including the files from the MyProject project as content during the packaging process, resulting in duplicate entries within the resulting .msix package.
To prevent this, you can modify the packaging project's .wapproj file by adding a post-build event that deletes the duplicate files from the package. Here's how to do it:
In Visual Studio, right-click on the packaging project in the Solution Explorer and select "Unload Project". Right-click on the unloaded project and select "Edit MyProject.Package.wapproj". Locate the "Project" element that references the MyProject project, and add a Child element named "TargetPath" with the value "$(MSBuildThisFileDirectory)AppxLayout\MyProject". Save and close the .wapproj file. Right-click on the packaging project and select "Reload Project". Open the packaging project's properties and navigate to the "Build Events" tab. In the "Post-build event command line" field, add the following command to delete the duplicated files from the package:
This command will delete the contents of the SoundEffects directory within the MyProject folder after the package has been built. The /s switch tells del to delete all files in all subdirectories, and the /q switch tells it to do so without asking for confirmation.
Save the project properties and rebuild the solution. Verify that the package no longer contains duplicate content under MyProject\SoundEffects. This should resolve the issue without requiring any changes to the structure or content of the MyProject project.