可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
(There's a link at the bottom to a solution with repro of the problem.)
I've been using a portable library with .resx resources for quite some time as it worked for both Windows Store apps and Windows Phone apps. I tried to use it with a Universal app as well, and it works for the Windows Store part, but does not work for Windows Phone.
The problem occurs only when I try to deploy the app on a device (built with the Release configuration). If I just Build it, it does not give an error (but it still can't be deployed on the device successfully). I get the following error:
Error : DEP6810 : MdilXapCompile.exe failed with error code 1004. See log file
'...\Phone App Test\Phone App Test\obj\Release\MDIL\MDILXapCompileLog.txt' for more details.
And in that file:
Error: Compile filter argument specified non-existent file:
...\Phone App Test\Phone App Test\obj\Release\MSIL\en-US\PCL.resources.dll
Invalid argument
The file truly isn't there, but the app does not support the en-US culture anyway, only the library does, so I don't think this file should be needed.
Any idea how I can resolve this issue?
Here's a simple solution with the problem: link
回答1:
You can have .resx files in pcls, you just have to use the workaround explained on http://blogs.msdn.com/b/philliphoff/archive/2014/11/19/missingmanifestresourceexception-when-using-portable-class-libraries-in-winrt.aspx
Even with the latest VS 2013 (update 5) the mdil error will appear when trying to deploy Release packages.
MdilXapCompile.exe failed with error code 1004
To work around it you must compile your app using the store option and then use the Application Deployment tool to actually deploy it to the device.
回答2:
Unfortunately the workaround described on Phil Hoff blog did not work for me too well. I have developed my own workaround. It turns out if you are using .resx files to store string values only, then you can easily convert them to .resw and use natively in Windows Phone 8.1.
So what I am doing is copying and converting resources from PCL and placing as native .resw resources in Windows Phone project every build automatically using the tool I made - ResxHell. Just follow the instructions on the repository and you can then reach resources like this
var resourceLoader = new ResourceLoader();
var localizedText = resourceLoader.GetString("MyCustomReswFile/MyStringId");
For nice binding I ended up creating ValueConventer and small localization helper class, take a look at this gist: Binding from .resw files example
With the use of that you can do following in your xaml pages:
//For resource in file Page.Login.resw and string ID "NotUserYet"
<TextBlock Text="{Binding ConverterParameter=Page.Login/NotUserYet, Converter={StaticResource ResString}, Mode=OneWay, Source={StaticResource ResString}}"/>
or
string localizedtext = LocalizationHelper.GetString("MyCustomReswFile", "MyStringId");
回答3:
I found this is already reported to ms connect
https://connect.microsoft.com/VisualStudio/feedback/details/991028/issue-using-resx-files-on-winrt-apps-windows-phone-and-windows
and there is a workaround I haven't tried yet.
http://blogs.msdn.com/b/philliphoff/archive/2014/11/19/missingmanifestresourceexception-when-using-portable-class-libraries-in-winrt.aspx
Unfortunatelly it has not been fixed so far.
回答4:
You certainly unchecked the "Build" checkbox in the Configuration Manager, that's why the resources are not copied automatically. Check it and it will works.
回答5:
In the end, it seems you can't use PCL library with localized resources using .resx files in the WP part of a Universal app. At least it's not trivial.
There were runtime problems when the app is build in Realese configuration, which I couldn't resolve, so I decided to change to .resw resources. This solved my problems, of course, but I had to duplicate the resources, which is what I was trying to avoid.
回答6:
Had the same problem. I tried deploying via Windows Phone Deployment Tool and it worked.
So instead of using Visual Studio to deploy: create packages and put them on phone and it works!!