sdknewbie

I am looking for some help as how to add to the properties folder of the project the Resources.resx and Resources.Designer.cs file programmatically. Also i would to add to the resource a file (text content file).

thank you



Re: Visual Studio Extensibility How to Add Resources.resx and Resources.Designer.cs files programmatically?

alvaroval

Hi,
If you want to add a file to the resource you have to add it manually, for example, in your Resources.resx file:

...

Code Snippet

<data name="File" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>resources\File.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=**************;utf-8</value>
<comment>A text file</comment>
</data>



...

"data name" is the name of the method that the generator creates to acces the file
"PublicKeyToken" you can copy the key of other resource in the .resx file
"value" the path of the file

The generator creates the following code in the Resources.Designer.cs file:

Code Snippet

internal static string File {

get {
return ResourceManager.GetString("File", resourceCulture);

}
}

With this method you can access your file.




Re: Visual Studio Extensibility How to Add Resources.resx and Resources.Designer.cs files programmatically?

C l e m e n s

To add the "resources"file to your solution...

grab the properties folder [projectitem] with DTE and add it in code... AddItem methode

or much easier allready add the file in you project template [see xml]

<Folder Name="Properties" TargetFolderName="Properties">

<ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem>

<ProjectItem ReplaceParameters="true" TargetFileName="Resources.resx">Resources.resx</ProjectItem>

<ProjectItem ReplaceParameters="true" TargetFileName="Resources.Designer.cs">Resources.Designer.cs</ProjectItem>

</Folder>

Clemens






Re: Visual Studio Extensibility How to Add Resources.resx and Resources.Designer.cs files programmatically?

sdknewbie

Hi Clemens,

I modified my template to add Resources.resx and Resources.Designer.cs according to your xml instruction above. Now i got a empty resources in my project. How do i add a file (registry .rgs file to the that resource programmatically some code snippet would be appreciated.

thank you for you help in advance.





Re: Visual Studio Extensibility How to Add Resources.resx and Resources.Designer.cs files programmatically?

C l e m e n s

CBrookes86,

Feng Chen - MSFT made a post in this thread " How can I add a resource file to a C# project programatically " about the use of the ResourceWriter Class

Clemens