I am adding two new strings to our resource.resx but these newly added resources(strings) are not reflecting into the auto-generated Designer.cs file. I have rebuilt the project and also tried clean+build the project but no luck!
I have other resource files to support various international languages where also i need to these two new string resources
Please suggest.
Make sure the Custom tool property for your resx file is set to ResXFileCodeGenerator or PublicResXFileCodeGenerator. The .Designer.cs file should be regenerated every time you modify the resx file; if it's not, you can force it by selecting Run custom tool in the context menu for the resx file.
Right click the resx file in solution explorer, select "Run custom tool".
This generated/added the code in the .designer.cs file for the new strings in the resource file for me.
When editing the resource file in Visual Studio, check the Access Modifier drop down is not set to No code generation.
If it is then select the appropriate option from the drop down - Public or Internal.
You just need to :
& then do :
Tada! You got your new Designer.cs !
In JetBrains Rider, I had to right-click the resx file and select "Generate resources"
I had the same issue when I renamed my [YOUR_RESOURCE].resx file into [YOUR_RESOURCE].en-US.resx. It seems [YOUR_RESOURCE].Designer.cs no longer auto generates any code after you renamed the default [YOUR_RESOURCE].resx format to something like [YOUR_RESOURCE].en-US.resx
I came across this solution and it worked fine for me.
Close the solution
Edit the project file LastGenOutput tag for the resource file
Open the solution again and try
If you're looking to automate this process you can use resgen
resgen c:\development\test\properties\resources.resx /str:csharp
Related
My team has some WPF projects written using XAML. We recently added a large number of local specific RESX files to each project. In order to keep things tidy, I was asked to store these files in [Project]>Localization>[locale]
Now, when we run the application on a non en-US locale, strings are pulled from the appropriate RESX file. We've tried to update Namespaces in the properties of the RESX files, as well as setting them to Public so that a resulting Designer is created.
The only way that we can get things to work is by moving the locale RESX files directly into the Project's Properties directory.
Is there anyway to update the XAML to search for locale RESX files in a subdirectory?
EDIT
XAML Codebase and Solution Explorer
I've attached an image of the problem for clarification.
Some code changes that we've tried:
1) We attempted to set the Namespace for xmlns:res="clr-namespace:[PROJECT].CoreUI.Localization"
2) Attempted to set the Namespace to xmlns:res="clr-namespace:[PROJECT].CoreUI"
3) We've also attempted to change the Custom Tool Namespace of the RESX file to match the current namespace My.Properties as well as CoreUI.Properties
We've also confirmed that the Access Modifiers for both Resources.resx and Resources.ru.resx (for example) are set to Public and that both Build Actions show "Embedded Resource"
Thanks for the help!
My colleague actually stumbled upon another post in here that we somehow missed during out countless searching:
Put translated resx files in a different folder in Visual Studio?
In short, we were thinking about making the project search down into subdirectories for the RESX files. In actuality, we need the RESX file to search for the already created designer further up in the chain.
<ItemGroup>
<EmbeddedResource Include="Localization\ar\Resources.ar.resx" >
<ManifestResourceName>$(TargetName).Properties.%(Filename)</ManifestResourceName>
</EmbeddedResource>
Entering the ManifestResourceName appears to tell the RESX file that we already have a Designer created and not to make a new one.
Thanks again for everyone's help!
You've to first include your folder in the namespace and mention project name like:
xmlns:resx="clr-namespace:Prism_Modules.MyResources;assembly=Prism_Modules"
Also you must include:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Finally, you should call values in resources as:
<dxb:BarButtonItem x:Name="menuFile" Content="{x:Static resx:Resources.mnuFile}" }" />
When moving .resx file to another folder/project, the .Designer.cs file that exposes resource members will still point to the old namespace and also Visual Studio will place it outside the .resx file.
To fix this, I simply deleted the generated .Designer.cs file and then after opening and saving .resx file, the Designer.cs file got generated with proper namespace and I could normally refer to it even from other projects. To generate .Designer.cs file for resource languages/files that have none just open .resx file and use the Access Modifier combobox and VS will create it for you.
I hope I was of any help.
So I went in to the project and right click > Add and created a new Config.settings file and Login.settings file.
I then added a couple of inputs in each of those settings files.
How do go about accessing the settings values in those settings files?
I tried Properties.Default... but then it seems to not recognize Properties class as it shows a curly red underline in its name.
Do I have to import some name space?
I then try adding a new file called "Setting.settings" file and its still the same. I clean and rebuilt my project too.
Try right clicking on .settings file and selecting run custom tool option.
Also, sometimes it helps when you manually remove bin and obj files from project. Finally, close the solution and open again.
For user overrides and how settings are working refer to microsoft docs: https://learn.microsoft.com/en-us/dotnet/framework/winforms/advanced/using-application-settings-and-user-settings
When you create a new C# Windows Forms Application in Visual Studio 2012, It has a Properties folder containing a Resources.resx file.
How do I access this file?
I have tried:
ResourceManager rm=new ResourceManager("Resources.resx",typeof(MyClass).Assembly);
string s=rm.GetString("MyString");
But I get System.Resources.MissingManifestResourceException because for some reason it appends .resources to the filename so it's looking for Resources.resx.resources.
I then appended .resources to the filename to see if it might actually work. It didn't, same exception, why?
I also tried using the ResxResourceReader class but it looks for a resx file in a directory, and this specific resx file I'm trying to access is not stored in a directory, it's compiled in to my assemblies so that doesn't seem to be helping either.
I thought it'd be really simple, maybe it is and I'm just overlooking something?
If it's not simple, I might as well create a C# class and hard-code my strings (only type of resource I need right now).
And another question: If the resx file is compiled in to your exe, does that mean you can't change it's values during runtime?
It is plain simple (usually).
Use the Properties class!
Properties.Resources.MyString
The Properties folder you see in your Solution Explorer is not just a fancy folder ;p Visual Studio generates a class to access all your resources with ease.
I have a console application that builds some default classes for me from a database. When the files are built, I want to be able to refresh my folders and see the new files in my class library.
However no matter what I do the files don't show up unless I go in and manually add existing files. Is there a way for VS2010 to look at the file folder and add in anything that is in that folder to the project? For example:
Folder > File1.cs, File2.cs, File3.cs, File4.cs
VS2010 sees
Folder > File1.cs
How can I make VS2010 show these new classes?
Your problem is that you will only see files that are included and referenced in your .csproj file. This is by and large a good thing because it gives you ultimate control over what is taken into account in the project or not. This is causing you a problem though, because the created files which are inserted into your project directory aren't being referenced. As you have mentioned you can include the files manually, but I understand that you wish this process to be automatic.
The best way to resovle this in my opinion is instead of having a project create the files, use design-time T4 templates. Design-time T4 templates are files which resemble pre-Razor ASP.NET views, which allow code generation within your project. You can access your database, format your classes and then output .cs files directly into your project without building it. This is extremely convenient becuase it lets you work on catching compile-time errors that may come up based on the output without having to do a complete build.
More information about using T4 can be found here.
And a good walkthrough can be found here.
Haven't tried this personally, but you should be able to do it using this..
First gain a reference to your project using your apps' solution, then with the Visual Studio automation framework (DTE):
ProjectItems p = Project.ProjectItems;
p.AddFromFile("File1.cs");
Taken from: http://msdn.microsoft.com/en-us/library/envdte.projectitems.addfromfile.aspx
I would read further into it.
Select the project where you can find your file
On top of your solution explorer you can select "show all files"
Select your files and include
Adding them automatically can be done from another app or script by modifying your projects .csproj/vbproj file
<Compile Include="My Project\MyClass.vb" />
This must be done in the correct itemgroup.
I think this is not directly possible. You may write a template file (t4) in order to create you cs files and they will be added to project when the transformation file is run.
In order to run the transformation file after / before build, you may write a pre/post build event.
That will require you to create a VS add-in.. you can find an example here...
Okay so I have a console application that is building some default classes for me from a database.
Can't you let this application write all classes in one file, say Proxy.cs or Entities.cs. Then every time you regenerate the file and rebuild the project, you can access the new classes.
Had a basic WinForm question: By default a resx file is created for every form or user control (along with the designer.cs). This resx works fine for all the controls and the text added to the controls via the UI.
I was wondering if I could use the same resx to add strings which have to be used programmatically and based on conditions, attached to the controls? Will the resx get overridden in any case and this custom strings be removed?
What is the best practice to follow in this case?
There's a strange problem with the string resources in the Resources.resx file. There's no obvious way that I ever discovered how to create a new resource table for another language with the IDE. It can be done by hand though. Follow these steps:
Project + Properties, Resource tab,
add the strings you want to use in
your program
Start Windows Explorer and navigate
to your project's Properties folder
Copy and paste the Resources.resx
file
Rename it to the culture you want to
use. For example:
Resources.fr-FR.resx
Back to VS, click the Show All Files
icon in the Solution Explorer window
Expand the Properties node, the new
resource file should be visible
Right-click it and select "Include
in project"
Select it, in the Properties window
set Custom Tool =
"ResXFileCodeGenerator"
Verify that Build Action is set to
"Embedded Resource"
Build your program. You should get a new folder in your project's bin\Debug directory with the satellite assembly, named projectname.resources.dll. This satellite assembly contains both the localized strings and any localized resource from the forms. Test that it works with code like this:
public Form1() {
System.Threading.Thread.CurrentThread.CurrentUICulture =
System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
InitializeComponent();
textBox1.Text = Properties.Resources.String1;
}
The auto-generated ones get overwritten (I'm using 2005), so no I would not use the same file. I would suggest creating a separate area in your project for .resx files like this. Usually I create one .resx per form, matching the name, of course.
Edit: Here is a more detailed answer I gave recently to organize the file/folder structure when localizing your app with .resx files.
Or you can try this:
Add this code in main();
using System.Resources;
ResXResourceWriter rw = new ResXResourceWriter("Resources.de-DE.resx");
rw.AddResource("String1", "de");
rw.Close();
...
repeat for more files
Go to the bin directory and move the XML (resx) file(s) to perhaps the property folder.
Go to Step 5-9 above in nobugz post.