I can add and edit resources from dll compiled at runtime? - c#

I have a project webr that hosts two resource resx files in webr.properties, and resources are accessed as static properties, but when publishing the website becomes bin/webr.dll and bin/es/webr.resources.dll resx file are embedded in these dll, I can add and edit these resources in runtime in persistently? It is not to affect other projects that keep static reference to these resources.
What do you suggest?

I would recommend storing the new resources you want on the file system or in a database, and accessing them that way. Modifying the resources at runtime could be in theory possible, but feels like a strange solution. If it is images you are talking about, then I would try to find out how it is recommended to serve images in the specific web framework you are using.

No, you are referring to satellite assembly and that is precompiled and stored in your bin.
You can use other means like filesystem,database or any similar mechanism.

Related

ASP.net Resource Files not being copied to bin

I have a multi-lingual MVC web application referencing multiple projects. The application's resources are also defined in separate projects/modules, for example Application.Models.Resources.
This approach has worked well with the initial language set but now I have added additional languages to the resource projects, the new language resources dlls are not be copied to the application's /bin folder. For example, a Swedish language ('sv') variant was added to the resource project, it is not being copied to the /bin/sv folder of the application.
The resource file has its Access Modifier set to 'Public'.
What am I missing? How can I ensure that the language variants are installed?
Any advice would be appreciated.
Whilst there might be other solutions to this problem, I found that removing the references to the resource projects from the solution and then re-referencing them (Add existing project) fixed the problem. Other users with this problem might also want to try unloading and then reloading the resource projects (I was unable to test this as the first method resolved the problem).

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

How can I swap resources for different versions of an application?

I developing an application which will have at least 2 if not 3-4 different versions (don't ask). The applications will basically be identical except have different product names, window titles, application icon and some other minor differences in string or image resources.
My main goal is to avoid having to create multiple projects for each executable. I want to be able to have one main application project and have it just load those resources (name, icon, etc.) and be agnostic of which version it is. This way, I can simply configure my setup project to deploy the proper resources with the version of that application. Ideally it would not be that visible to the end-user after it was installed.
What I've tried: I've experimented with creating different .resx files and swapping them based off build configuration, or I've also experimented with adding environment variables and #if on the variable. But, I really do not want multiple build configurations. I want it to only depend on deployment.
Is it possible to create resx files, either in a different project or in the same project and exclude them from the build, and have them generated into satellite .DLL assemblies similar to localization, and then load whichever one is deployed with the application?
I'm confused if I should be looking at running my own RESGEN and AL tasks, or if I should just create a DLL project (but maybe then I'd have to have multiple DLL projects for only 1 resource file). Also, any article I can find about using .RESX files is for localization. It relies on setting the CurrentCulture to resolve the specific resources to use. My scenario has nothing to do with culture... I just want to load different resources for different deployments of the application.
Without knowing how deeply you need to go, you can package the resources into separate .dll files and differentiate that way. For instance, building the various different versions into a seperate DLLs and having your installer adjust the name to match what your application expects or use an XML configuration file to specify which to load and load it that way.
Assembly.Load() will allow you to load the alternative assembly.
Assembly _assembly;
_assembly = Assembly.GetExecutingAssembly();
Stream _imageStream;
_imageStream =
_assembly.GetManifestResourceStream(
"ThumbnailPictureViewer.resources.Image1.bmp");
Bitmap theDefaultImage = new Bitmap(_imageStream);
See: http://www.attilan.com/2006/08/accessing-embedded-resources-using.html

Localization in Class Library

I would like to localize my c# class library
The library will output a .dll file, which I will distribute to .net application bin folders.
I want localization in the class library but I do not want to have to recompile the DLL each time a localization change is required.
So ideally....
have c# class with resx files outside the assembly, so that when the contents of the resx changes, all that should be required is that the asp.net host application might require a restart.
Best case scenario, is that the asp.net host application doesn't require a restart.
Thanks in advance for your advice - the resx file will just hold string values.
If possible I would like to do this using a best practice method, or at least without writing a whole custom localization solution.
Check this stackoverflow question.
Is there any performance difference in using .resx file and satellite assembly?
Looks like you can have a seperate resource dll.

Referencing resource files from multiple projects in a solution

I am working on localization for a asp.net application that consists of several projects.
For this, there are some strings that are used in several of these projects. Naturally, I would prefer to have only one copy of the resource file in each project.
Since the resource files don't have an namespace (at least as far as I can tell), they can't be accessed like regular classes.
Is there any way to reference resx files in another project, within the same solution?
You can just create a class library project, add a resource file there, and then refer to that assembly for common resources.
I have used this solution before to share a assembley info.cs file across all projects in a solution I would presume the same would work fro a resource file.
Create a linked file to each individual project/class library. There will be only one copy and every project will have a reference to the code via a linked file at compile time. Its a very elegant solution to solve shared non public resources without duplicating code.
<Compile Include="path to shared file usually relative">
<Link>filename for Visual Studio To Dispaly.resx</Link>
</Compile>
add that code to the complile item group of a csproj file then replace the paths with your actual paths to the resx files and you sould be able to open them.
Once you have done this for one project file you should be able to employ the copy & paste the linked file to other projects without having to hack the csproj.
Some useful advice on how to manage a situation like this is available here:
http://www.codeproject.com/KB/dotnet/Localization.aspx

Categories

Resources