Adding reference to windows phone class library vi

2019-09-03 14:59发布

问题:

I wasn't quite sure how to word the title as I'm very confused about this problem, edits or suggestions to clarify are welcome...

Anyway, the problem is that I have a Windows Phone 8.1 (RT) application, and I'm attempting to use add a reference to a class library so that I can make use of code and XAML views in that project.

If I add the entire class library project to my visual studio solution, and then add a reference to that project in my app, everything works fine.

However, if I remove the reference and library project, and instead add a reference to the same DLL files of the class library project, my application will no longer build.

The error message is this:

Payload file 'C:\Users\Me\Desktop\MyProject\MyClassLibrary\bin\Debug\ MyClassLibrary\MyPage.xbf' does not exist.

that bold MyClassLibrary is an extraneous folder definition whose origin I cannot identify. If I add the class library as a reference via the solution, it builds just fine, even though that folder doesn't exist.

but when I add the reference to the same DLL files only, it starts looking in that folder. if I create that folder manually and copy everything into it, I can build and run like before, but that seems like a hack, as it works fine without this workaround if I add the project reference instead...

Why is it doing this? according to the output of the build it appears to be a result of this error:

1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\AppxPackage\Microsoft.AppXPackage.Targets(1496,9): error APPX0702: Payload file 'C:\Users\Me\Desktop\MyProject\MyClassLibrary\bin\Debug\MyClassLibrary\MyPage.xbf' does not exist.

but why does it append that folder when I add the reference to the dlls files directly, where is it coming from and how can I stop it from doing that?

回答1:

This one is tricky. In fact when you build Store apps, (Phone or Windows 8) you cannot add libraries that contains xaml just by referencing the dll. It just won't work and display this kind of errors. You cannot package xaml into your WinRT librairies as you would in Silverlight.

Please read those links

Embedded Xaml pages on DLL

http://timheuer.com/blog/archive/2012/03/07/creating-custom-controls-for-metro-style-apps.aspx