I can't figure out if it is possible, (using VS 2005 and .Net 2.0), to get strongly-typed access (including IntelliSense at design-time) to resources stored in a seperate .dll.
Our project has about 5 seperate executable programs. Each has it's own VS Project. Many of the resources (strings and icons) need to be shared between these Projects, and they need globalization/localization. We have an assembly consisting of a single resources.resx file, which compiles into CoName.Applications.MyAppsGroup.Resources.dll. We also have a couple of Satellite Assemblies that translate many of the resources in the Neutral Culture .dll
I can include a reference to that .dll in my 5 .exe projects, and I can access the individual resouces using the "old" way - GetString and GetObject.
With VS 2005, it is easy to define a satelllite assembly resouce file for each form and easy to create a satelllite assembly resouce file for each project, and access the resources (from within theproject) in a strongly-typed manner using the project's Properties.Resources class.
But (after spending 2 days on research and testing) I can't find any way to access the resources in CoName.Applications.MyAppsGroup.Resources.dll from the CoName.Applications.MyAppsGroup.App1 project in a strongly-typed manner. (CoName.Applications.MyAppsGroup.Resources.dll is referenced in the CoName.Applications.MyAppsGroup.App1 project, so it is available at design-time, and copied to the bin dirs at compile-time, making the .dll available during debugging....)
If this is possible, could anybody throw some pointers my way and if it is not possible, let me know so I quite worrying about it
BTW - looking at how VS automagically builds the Resources.designer.cs file, I can see how it creates the internal class that provides the strong-typing for each resource. I don't want to have to manually create and maintain a public class in the CoName.Applications.MyAppsGroup.Resources project to provide strong-typing. If there is a way to tell the ResGen custom tool to create publically accessable helper classes for access to the resources, that would be a fine solution... Maybe there is already a way (with appropriate class/assembly/dll naming) to get this functionality, and I'm just dense. Anyway - any and all help will be appreciated!
Thanks!

Strongly-typed access to a resources (satellite assemblies) .dll from other projects?
Suresh63149
It is a known limitation of the current resource strong type generator in the Visual Studio. The command line tool ResGen supports to generate public classes, so you might want to use the command line tool to generate code. You can always disable the default code generator by removing the "Custom Tool" property of the project item (in the solution explorer.)
You can add this step to the .csproj file, so it would run automatically: (just edit the file with notepad, remember to copy a backup file, in case that you mess it up)
<Target Name="BeforeBuild" Outputs="Properties\Resources.cs">
<Exec Command="C:\...0\resGen /str:c# /publicClass Properties\Resources.resx"/>
</Target>
...
Some people write a small single file generator to replace the default one. It is another way to workaround this. You might be able to find one somewhere. However, I didn't try it.
It is on the feature list which is being considered in the next version.
Thanks
Lifeng Lu
MS Visual Basic Team
Al O
Fantastic, and thank you very much. I did have to modify your solution just a bit. Because on my system $(SdkPath) still contains whitespace, the solution as written produced "C:\Program is not recognized....". I simply took your second suggestion, and modified the solution thusly:
<Exec Command=""$(SdkPath)\bin\resGen.exe" /str:c# /publicClass Properties\Resources.resx"/>
Which now works as expected.
Wilfried Martens
Hello!
I am trying to localize a windows application using satellite dll, but
I am having problems because the app can't find the satellite dll ("Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Project1.Resource1.resources" was correctly embedded or linked into assembly "WindowsApplication1" at compile time, or that all the satellite assemblies required are loadable and fully signed.")
I have a windows project, with the next lines:
Dim oResourceMgr As System.Resources.ResourceManager Dim oCultureInfo As CultureInfooCultureInfo =
New CultureInfo("es-AR")Thread.CurrentThread.CurrentCulture = oCultureInfo
Thread.CurrentThread.CurrentUICulture = oCultureInfo
oResourceMgr =
New System.Resources.ResourceManager("Project1.Resource1", [Assembly].GetExecutingAssembly()) Me.Text = oResourceMgr.GetString("a") End SubRootnamespace: WindowsApplication1; Assemblyname: WindowsApplication1
And another project with a resource file: Resource1.es-AR.resx
Rootnamespace: Project1, AssemblyName: Project1
I am getting the next files:
WindowsApplication1\bin\Debug\es-AR\Project1.resources.dll
WindowsApplication1\bin\Debug\WindowsApplication1.exe
Can you help me I don't know what is wrong. I am creating the resource files with VS2005.
Do you have a little example of a winform app that use satellite dll
(or an URL)
Thanks in advance,
Fernando.
Victor Lu
Thank you for this answer. I am trying to implement your suggestion to invoke the command line resgen as a "beforeBuild" task. In your example, you show
"C:\...0\resGen "
On my system, resgen lives in "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin". Note the whitespace in the full path.
<Exec Command="C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\resGen /str:c# /publicClass Properties\resources.resx"/> resulted in
'C:\Program' is not recognized as an internal or external command...
<Exec Command="resGen /str:c# /publicClass Properties\resources.resx"/> resulted in
'resGen ' is not recognized as an internal or external command...
I tried escaping double quotes, as in
<Exec Command="\"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\resGen\" /str:c# /publicClass Properties\resources.resx"/> resulted in
"Invalid token C, expected >"
I could not find a pre-defined build macro that pointed to the SDK Bin dir.
Could you please suggest the proper way to specify the resgen executable to the "BeforeBuild" target
Thanks for your help.
SubZero
I have added a Resource file to my project named InsiteResources, updated the .vbproj file, and the assembly appears to build successfully.
However, while I can reference the assembly in another project, and the Intellisense is working, when I run/debug, I receive the same error as Fernando.
Here's the stuff I added to the .vbproj.
<Target Name="BeforeBuild" DependsOnTargets="CreateStrongTypeResource" />
<Target Name="CreateStrongTypeResource" DependsOnTargets="GenStrongTypeResource">
<CreateItem Include="InsiteResources.vb">
<Output TaskParameter="Include" ItemName="Compile" />
</CreateItem>
</Target>
<Target Name="GenStrongTypeResource" Inputs="InsiteResources.resx" Outputs="InsiteResources.vb">
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="SdkPath" />
</GetFrameworkSdkPath>
<Exec Command=""$(SdkPath)\bin\resGen.exe" /str:vb /publicClass InsiteResources.resx" />
</Target>
Here's the error.
"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "InsiteResources.resources" was correctly embedded or linked into assembly "Ildceo.Insite.Resources" at compile time, or that all the satellite assemblies required are loadable and fully signed."
So what have I fouled up
Mayank Banerjee
You can create a Resources.es-AR.resx in the same project inside your windows application. Make sure it is consistant with the resource you put in the default resource file (actuall resources.resx inside the "My Project" directory. When you build the window application, you should get the satellite DLL there.
bradbrown dot net
Yes, I noticed your issue, and it is also bad to include a path of your local machine in the project file. Actually, I did find a way to get SDK path, and posted in the blog: http://blogs.msdn.com/lifenglu/
Basically, what I added in the csproj file looks like:
<Target Name="BeforeBuild" DependsOnTargets="CreateStrongTypeResource"/>
<Target Name="CreateStrongTypeResource" DependsOnTargets="GenStrongTypeResource" >
<CreateItem Include="Properties\Resources.cs">
<Output TaskParameter="Include" ItemName="Compile" />
</CreateItem>
</Target>
<Target Name="GenStrongTypeResource" Inputs="Properties\Resources.resx" Outputs="Properties\Resources.cs">
<GetFrameworkSdkPath>
<Output
TaskParameter="Path"
PropertyName="SdkPath" />
</GetFrameworkSdkPath>
<Exec Command="$(SdkPath)\bin\resGen.exe /str:c# /publicClass Properties\Resources.resx"/>
</Target>
GetFrameworkSdkPath will give you the SDK path on your machine. CreateItem task will add the result of the code generator to the list of C# file to be compiled later.
BTW, the reason you had trouble with " was that you couldn't use \ to be the escape character in XML file like a C# code file. You will have to use '"' there.
Like:
<Exec Command=""C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\resGen" /str:c# /publicClass Properties\resources.resx"/>