Bug in MSBuild (940245)
It seems that, under certain circumstances, if you have a Portable Class Library that contains an asset that is marked as copy always, and you reference the library from a Windows Phone Silverlight project, the asset will be copied into the resulting
.xap file twice. The bug looks like it was introduced in the second update to Visual Studio 2013, but is still present in the third update. Lets take a look at how to reproduce the bug.
We start with a solution that contains three project types:
- Windows Phone (Silverlight)
- Normal Library
- Portable Class Library
There is also some setup required to reproduce the bug:
- Reference both libraries from the Windows Phone project.
- Create a
.txtfile with the
Copy to Output Directoryproperty set to
Copy alwaysin both of the library projects.
- Finally, you will need to compile the Windows Phone project.
Once you have compiled your project, you will need to view the content of the
.xap file. You can use something like 7-Zip to decompress it.
In the above picture you need to note that while we have the assets we created,
asset.txt, at the root of our
.xap file as expected, we also have a second copy of the portable asset,
portable.txt, which is secretly living in that strange
This situation is not ideal when you have more than 200MB of assets in your portable class library, so i reached out to David Kean on the .Net team and he suggested we add an empty MSBuild target called
GetPackagingOutputs to our
.csproj file for the portable class library, which seems to resolve the issue for Windows Phone 8 (Silverlight) projects, but breaks any
I have logged a bug on the Microsoft Connect site so that the progress may be tracked by anyone else experiencing the same issue, you can find it over here.