“Xap packaging failed” build error

A few days ago, I checked out a Windows Phone project from our SVN server where one of my colleagues had stored it, planning to continue working on it – but somehow, all I got was the infamous build error “Xap packaging failed”. How would a solution that started fluently on my colleagues machine not even compile on my side after going through SVN?

After the usual sequence of cleaning & rebuilding, checking Nuget references, closing Visual Studio and rebooting the machine, I finally started to think instead of acting instinctively and looked at the error message in detail: “Xap packaging failed. Failed to package file ‘C:\…\README.TXT’. Unable to find the specified file.” In fact, there was a text file “README.TXT” referenced in some sub-folder of the solution, and its build action set to “Content”, but obviously Visual Studio couldn’t locate it on the file system as the icon suggested:

Text file reference

Text file reference

It turned out that the solution originally had contained this precise readme file, but my colleague decided that it wasn’t necessary any more and removed it from the SVN commit. Since it wasn’t available on my machine, but Visual Studio believed it being absolutely necessary to the success of our project due to the build action set to “Content”, the build failed although all the really necessary files actually were there… After removing the reference to README.TXT, Visual Studio happily packaged and deployed the project to the Windows Phone emulator!

What do we learn from this? First of all, if you remove any file from a Visual Studio solution, use the Solution Explorer to exclude it from the project first. But in addition, always make sure that all the files in your project have the correct build action set! Apparently, text files added to a solution are assigned the “Content” build action automatically…