How can I reuse .NET resources in multiple executables?
I have an existing application that I'm supposed to take and create a "mini" version of. Both are localized apps and we would like to reuse the resources in the main application as is. So, here's the basic structure of my apps:
MainApplication.csproj
/Properties/Resources.resx
/MainUserControl.xaml (uses strings in Properties/Resources.resx)
/MainUserControl.xaml.cs
MiniApplication.csproj
link to MainApplication/Properties/Resources.resx
link to MainApplication/MainUserControl.xaml
link to M开发者_JAVA百科ainApplication/MainUserControl.xaml.cs
MiniApplication.xaml (tries to use MainUserControl from MainApplication link)
So, in summary, I've added the needed resources and user control from the main application as links in the mini application. However, when I run the mini application, I get the following exception. I'm guessing it's having trouble with the different namespaces, but how do I fix?
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure \"MainApplication.Properties.Resources.resources\" was correctly embedded or linked into assembly \"MiniApplication\" at compile time, or that all the satellite assemblies required are loadable and fully signed.
FYI, I know I could put the user control in a user control library but the problem is that the mini application needs to have a small footprint. So, we only want to include what we need.
You are correct that the different namespaces are the problem. A resource file cannot be given a namespace, it will take the namespace of the folder that contains it. If the namespaces across your two apps are different, the namespace will be different.
I can see three options available to you
- Use the same default namespace for both applications
- Have an assembly purely for your resource file and reference that in both apps
- In the code loading the resource, generate the namespace based on the namespace of the class that's loading it
The Resources generated by visual studio are not public, they are only visible to classes within a library. in order to generate resources as public properties you will need to use a custom generator like this: http://www.codeproject.com/kb/dotnet/ResXFileCodeGeneratorEx.aspx
精彩评论