Moving form resource files to a resource dll - c#

I want to move the localized resource files, created for my various winforms, to a resource dll. Is there an easy way to do it, that don't include manually reading every single string from the dll for each form, just like the forms usually handles it?

I don't think it'll be that difficult, you just have to create a new project of type class library and move your resource file to that project, when you build that project it'll create the dll and then you just need to refer this dll to your actual project and done.

Related

Is it possible to import class file without converting it to a dll in c#?

There are a lot of variables and methods in my program and I want to seperate some of them in other class files. But as the program grows the methods and functions can change.
I searched on the net but many people generally speaking for dll files. Without making a dll file, how can I arrange my code and split into small class files?
Yes, just split it out in to a separate file in a new class but still inside the same project. The term for what you are doing is called Code Refactoring. There are some tools built in to Visual Studio to make it easier to do, and there are some 3rd party tools that add even more features to make it easier to do.
But all it boils down to is just making new classes in the same project and referencing those new classes from where you took the code out from.
You can add folders to your solution. Classes are by default a namespaceprovider, so that classes in this folder have a different namespace.
For example if your default-namespace is MyNameSpace and you create a folder called Entity then all classes in this folder have the namespace MyNameSpace.Entity
And all Items in a project are compiled to one single dll or exe
Just add more classes to the project and put the data and behavior (methods) into the appropriate classes. The project will still build into a single exe or dll.
Generally, it's better to add a second project under the same solution call it "CommonLib" or something like that. Then you add it as a reference to the main application and set up the project so that the applications build depends on the libraries build. Add a using statement for the common lib where ever you want to use those objects. This is definitely better for large scale or enterprise applications. There's a pretty decent chance that somewhere down the line you'll want to reuse some of this code, if everything builds into a single exe that won't be an option.

Updating classes used in multiple projects?

I have a few classes that are abstracted in a way that I can use them in multiple projects. I'm always working on these classes, optimizing, adding, etc. So when I optimize something in one of these classes, I then need to copy that new version into every project I remember using it. This isn't a very good way of doing it, but is there a better way?
Thanks
Put these base classes in a single project and share this project between your different solutions as an referenced class library. This way you will not have to copy / paste anything between projects or solutions and everything should always be up to date.
You could even set-up a local NuGet feed so you can use NuGet to retrieve this shared project as a reference in a well structured and managed way.
Instead of manually copying the updated classes to every project that uses them, create a Class Library project and reference the compiled file in every project that uses the classes. Organizing your classes like that will help you to follow the DRY ("Don't repeat yourself") principle.
If you need to reference files instead of compiled libraries, however, you can reference a file as a link so that multiple projects refer to the same file without copying it to each solution folder. To do that, right-click on your project, choose Add existing item..., browse to the .cs file, and choose Add as Link from the combobox in the right lower corner.
How about if you extract the classes into a separate project, and add a reference to this project in every project you are using?
It is a bad idea to copy paste file throughout the application. To avoid these repetitions you can either:
make a link, if the amount of file is really small . In the Solution browser of Visual Studio, right click, Add Existing file, chose your file and in the split button, choose Add as a link
create a separate project and reference this project wherever is is necessary if the amount of files not tiny.
Create a base-lib and build it to a "shared" location. Add a reference to it in you project. It will keep the other projects smaller and will be faster to build.

When should I use Satellite Assemblies when it comes to localization? And When should I use Resources Files(.resx)?

I'm creating a windows appplication in which I wanna do some localization. That application will also use a DLL that might use a different language(CultureInfo) than the main application. Which one of those two localization concepts applies best to my case?
I don't quite think you understand .Net's localization model.
Actually, when you add resx file to your project in Visual Studio and set language (change from Default to something else), not only it will automatically create language copy of your Default (invariant) resource file, but will also create Resource Managers to load data from Satellite Assemblies behind the scenes. Go ahead and try it by yourself. You should observe some language-based subdirectories with satellite assemblies in your output directory.
Therefore your question quite does not make sense.

how to attach javascript file and use them when built dll file

I have a solution contain one class library and one JavaScript file. I want build it into dll file and then call a function in that file.
If this is for a web project (which I'm assuming) why do you want to do it this way? Is this for deployment of your single library to others?
You need to embed this as a resource which wil lthen use ScriptResource.axd.
See:
http://msdn.microsoft.com/en-us/library/system.web.handlers.scriptresourcehandler.aspx

Reusing code in .NET website (app_code folder)

I need to use some classes inside the app_code folder of a website project in visual studio 2008. I need to access this code from a class library project in the same solution. I cannot add a reference to the website, and I'm not sure of the easiest way to use the classes that already exist here. Do I need to move it to a class library?
What other options do I have?
Yes, create a class library and move any types you need into that library. This library can be referenced in as many places as you would like.
The best way to do this is to put those classes in their own library.
However, if you really don't want to do that, you could add a link to the files in the library project. To do that, right-click the Class Library project or a folder within it, Add, Existing Item, navigate to the code files, click the down arrow near the Add button, Add As Link. This will add the same file to both projects. You can even use the #if preprocessor directive to limit portions of the file to specific projects.
However, it is vastly preferable to put the code in a library and reference it in the web project.

Categories