13

I'm trying to use an embedded resource in a console application, but apparently console applications don't come with a resource file automatically. How do I create a resources file for my console app?

Community
  • 1
  • 1
Joe
  • 3,804
  • 7
  • 35
  • 55

5 Answers5

17

The project template for a console mode application doesn't have pre-cooked Resources. You simply add it with Project + Properties, Resources tab, click the "Click here to create one" link. Take an hour and click around some more. This is all very discoverable but you have to take a look.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • "Take an Hour and click around some more"... I see mushroom clouds in his future ;) – Moo-Juice May 20 '13 at 18:48
  • So do I :) Incidentally, this did exactly what I needed, so thank you! – Joe May 20 '13 at 18:50
  • 1
    @Joe This is probably the best answer. I didn't know it could be done this way. And this way you get it in the customary place - inside `Properties`. – ispiro May 20 '13 at 18:53
12

Right click on the console application project node in the solution explorer. Add->New Item->Resources File.

edit: as has been pointed out, if you open the Properties of the console app project, it will also have a Resources tab, which will tell you that it doesn't have a resources file and provide you with a link to create one. This will do the same thing as the above, except that it will create the files under the Properties folder.

neminem
  • 2,658
  • 5
  • 27
  • 36
7

I added the answer in my answer to your previous question:

Right-Click on 'test' in Solution Explorer -> Add -> New Item -> Resources File

Then double-click on the created file (e.g. Resource1.resx), and take it from there.

Then use it:

string s = Resource1.String1;
ispiro
  • 26,556
  • 38
  • 136
  • 291
2
  1. Right click your project.
  2. Select Properties.
  3. In Resources click the link "This project does not contain a default resource file". Click here to add one.".

enter image description here

AH.
  • 2,913
  • 1
  • 28
  • 26
0

Understanding the fundamentals.

Just build your default

public class Lang {
    public string Title = "my title";
}

then

public class Lang_en_US : Lang{

    public Lang_en_US(){
        Title = "my US Title";
    }

}

then find your lang you want to case into with switch, if not match, just use the default

ASP.net compiles into classes like the global resource.

:)

ppreetikaa
  • 1,149
  • 2
  • 15
  • 22