Add resx to cab file - c#

I have an app on Windows Embedded which uses .resx files to translate the app to different languages.
Also I create an installation .cab file but I can't include the resx file to this cab.
How can I achieve this?
Thanks for any tip

A few things:
You'd not told us how you're trying to add the file. Are you using a custom INF file and just calling CABWIZ or are you using a Visual Studio Installer Project?
What have you done to try to include the file?
Most importantly, a RESX file does not contain the run-time resources and you rarely would deploy it. The RESX resources get compiled into a *.resource.dll assembly, that is typically in a subfolder with a name for the locale (e.g. en-us or fr-ca). You need to deploy those files/folders which is challenging because CABWIZ doesn't allow duplicate file names (and all resources have the same file name, just different folders). That scenario is handled by this SO question.

Related

Visual Studio 2013 windows forms application with Resource file using c#

I have created windows forms application in C# VS 2013 with resource file (to maintain configurations). I created a Task in 'windows task scheduler' with the exe of the application (I copied 'exe file and resouce related file' to another envirnonment). when I run task, its running without any issues.
My intention of using resource file is to change configurations at any time without building the application.
But when I change configurations in application, if I update resource file in above mentioned environment, application using old configurations. when I copy new exe file its working with new configurations.
Please let me know is it correct way or guide me how to schedule 'windows forms application' in 'windows task scheduler' with resource file.
Thanks in advance,
Krishna.
You're confusing resx files and config files. You should use the second one. Here is good example.
Outside of ASP.NET, there isn't an easy way to use resource files in this way, resource files (.resx) are XML files which are build into a binary formal .resrouce file and embedded into the application assembly during build time, this is why any changes are ignored.
However you can put settings in your .config file in the appsettings section or build your own configsection, this way when the application runs again it will read the settings with your changes from this file.
You can also have a custom Xml/Json/Ini file and read from it using with your own code, but for simple settings, use appsettings section in the app.config file.
https://msdn.microsoft.com/en-us/library/aa903313(v=vs.71).aspx

Proper procedure to import existing RESX files into a C#/WPF project

I have my auto generated Resource.resx file set up with keys and strings. I also have three other resx files for German, French and Spanish given to me from translators. I'm not able to get the localization functioning and I suspect that the resx files aren't being called correctly. I added them to the project by dragging them into the solution explorer under "Properties". I have a nagging suspicion that just dragging them in isn't creating the proper connections behind the scene.
Now It's totally possible my issue lies somewhere else. If anyone can tell me whether it's ok to add resource files this way or if not, what the correct way is, it would save me tons of time spent chasing my tail. Thanks!
Resx files in Visual Studio include a special tool which is run at build time and translates them into embedded resources. Right-click your original VS-created resx file and click Properties. You should see Build Tool or something similar. Also note the resource type (Embedded, etc.). Make sure that you match these settings for your manually added files.
Once this is set up, you will need to use the CurrentUICulture property to tell .NET to pick up the appropriate resources. You can choose to change the culture/language at install-time or run-time. Here is a comprehensive tutorial which describes the various options available to you:
WPF Localization Using RESX Files
That said, as a best practice, translated Resx files are generally deployed as satellite assemblies. The main application DLL/EXE contains only the language neutral resources file. Other resource files are compiled into separate assemblies and deployed side-by-side with specific naming conventions. This allows you to dynamically add translations, localizations, etc. even after the application is deployed. Here's an introduction: Packaging and Deploying Resources in Desktop Apps

what will happen to images in the Resources directory once the app is packed and how safe are those images for the app?

the Resources folder typically contains all the app images (those 16 X16) that we use to look our apps good. I haven't dealt with installation and resources folder before therefore :
When application needs to be deployed, what would happen to those images in that Resource folder?
I haven't tried this before so when I install the application where would that resource folder be saved?
If the installation creates another resource folder to keep those images, then what if a user manually deletes that folder? App would crash? what is the solution to overcome this?
I've heard some place the images in a .dll file, is this a common practice?
thanks
When you build your application, Visual Studio invokes the resgen.exe tool to convert your application resources into an internal class called Resources. This class is contained in the Resources.Designer.cs file which is nested under the Resources.resx file in Solution Explorer. The Resources class encapsulates all your project resources into static readonly get properties as a way of providing strongly-typed resources at run-time. When you build through the Visual C# IDE, all the encapsulated resource data, including both the resources that were embedded into the .resx file and the linked files, is compiled directly into the application assembly (the .exe or .dll file). In other words, the Visual C# IDE always uses the /resource compiler option. If you build from the command line, you can specify the /linkresource compiler option that will enable you to deploy resources in a separate file from the main application assembly. This is an advanced scenario and is only necessary in certain rare situations. A more common scenario for deploying resources separately from the main application assembly is to use satellite assemblies as discussed below.
All your queries is answered above
i.e.
When application needs to be deployed, what would happen to those images in that Resource folder?
I haven't tried this before so when I install the application where would that resource folder be saved?
If the installation creates another resource folder to keep those images, then what if a user manually deletes that folder? App would crash? what is the solution to overcome this?
I've heard some place the images in a .dll file, is this a common practice?
For More information
http://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.80).aspx

VS2010 (C#) Environment.SpecialFolder.ProgramFiles is where in the Solution Project?

I have created a C# WinForms application. It has some additional files that it uses, such as help files and some external data files. I want to put these files in folders under the Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) path so that the application can find and read them.
This path doesn't get created until the application is installed right? So where do I put these files in my VS2010 project, or how do I tell my project that these files exist so that when I am running (debugging) the application from VS it will find the files.
Thanks
EDIT: I did think about adding the files as resource files, but unfortunately some files may get added after the project is built and deployed. Therefore we decided to make the program search and find the data files (and associated help files) at a specific location and load them if they exist.
Thing is that your application should not need to use 'Environment.SpecialFolder.ProgramFiles'. It "should" be location agnostic. The quick answer to your question is "from the folder that the application was launched from". The real answer is how you reference these files.
Your help files and data files need to be deployed to folder with a known relationship to the application. That is, the same folder or a child folder. Consider making the file resources.
Now if the files are user configurable or run time writable then they should not be in the program files area but be in the application data area. If so, then there is your path!
Hope this helps.
You should add these files to the main (exe) project inside your solution.
(Right click on Project Name, Select Add Existing Item)
Then set its property Copy to Output Directory = Always
(not sure of the translation because I use a localized version of VS)
Of course, it should be noted that, when you deploy your files in the Environment.SpecialFolder.ProgramFiles, you could not be able to write to them (Windows7, Vista) for security reasons.
Add the files as resources in your project. Take a look at this MSDN article. You can add resources to a project by right-clicking the Properties node under your project in Solution Explorer, clicking Open, and then clicking the Add Resource button on the Resources page in Project Designer.
You can add resources to your project either as linked resources, which are external files, or as embedded resources, which are embedded directly into the .resx file.
When you add a linked resource, the .resx file that stores your project resource information includes only a relative path to the resource file on disk. If you add images, videos, or other complex files as linked resources, you can edit them using a default editor that you associate with that file type in the Resource Designer.
When you add an embedded resource, the data is stored directly in the project's resource (.resx) file. Strings can only be stored as embedded resources.

C#/.Net: What are the best practices for setting ResXResourceReader's basepath?

I am working on a Windows Forms application in C#/.Net. I want to use a resource file that contains translations of my strings. My my project in visual studio I have the following hierarchy:
Project
CS files ...
Resources\
resource.en-US.resx
I am trying to read in the resource file as follows:
m_ResourceReader = new ResXResourceReader("resources/resource.en-US.resx");
When I run this project, Visual Studio seems to look for the resources folder in the bin/Debug output folder of my project.
My questions are:
What is the right way to reference a resource file?
I would like my installer to place this resource file under my application's folder under Program Files\MyApp\resources\resource.en-US.resx. What would be the way to make ResXResourceReader read it from that location.
Thanks for your help.
-Raj
There is no right way to reference a .resx file at runtime. They are design-time files, the build system translates them to satellite assemblies. And copies the resulting DLL into the en-US folder of your bin\Debug folder. And the runtime automatically finds and uses them if the current culture is set to en-US.
I suppose you can get .resx reading going, but you'll get no help from the IDE or the build system to do so. I'd have to recommend you avoid fighting the machine.

Categories

Resources