19

I'm trying to create new resources files in VS2015. I created them fine, but when I try to change the "Access Modifier", the dropdown is disabled...

Any ideas?

I'm working in a ASP.NET MVC 6 (ASP.NET5). The project is a Class Library, but I have tested in Web Project with same results.

Thanks!!

enter image description here

Edit: Added Properties window enter image description here

chemitaxis
  • 13,889
  • 17
  • 74
  • 125
  • Open designer file (Resource.Designer.resx) on Notepad++ and change the internal/private modifier (from all property, constructor and class). – Ricardo Jun 01 '16 at 23:03
  • @chemitaxis, follow the instructions in [my answer](http://stackoverflow.com/questions/34314146/visual-studio-2015-cant-change-access-modifier-of-new-resources-files/39441597#39441597) – Ramin Bateni Sep 11 '16 at 23:32

4 Answers4

14

Can you check the property of your file and verify if Custom Tool is ResXFileCodeGenerator ? If it's GlobalResourceProxyGenerator, the dropdown will be disabled.

arya404
  • 346
  • 1
  • 8
  • 1
    Go directly on Solution explorer and right click on your file to get Properties. If you just open the window Properties It won't show anything :( CustomTool is in the "Advanced" category, just after Copy To Output Directory. – arya404 Dec 16 '15 at 14:22
  • 1
    Hi @arya404 I have updated my question... like you see, I don't have the option to change anything... I have tested with a clean new project with the same result... – chemitaxis Dec 16 '15 at 15:39
  • I have tested it in a new computer with new installation of VS, but it's not working... – chemitaxis Dec 16 '15 at 15:59
  • Can't you tell me what is the type of your project "....Resources" ? And Under your *.resx file, do you have the Designer file ? – arya404 Dec 16 '15 at 17:01
  • I have read about it... it's like VS2015 with ASP.NET 5 projects has changed how works with resources... But, for your question... it's a class library – chemitaxis Dec 16 '15 at 17:06
  • 1
    I've got the same issue :( – Cool Breeze Jan 15 '16 at 02:50
  • Same issue! I can able to access properties of .resx and change access modifier and check the tool that is active in older version of VS but not in VS 2015 – Anil Mar 31 '16 at 08:59
  • Did anyone found a solution for this? – Ricardo Mota Apr 23 '16 at 15:46
  • 1
    same thing here :I – peco Jun 17 '16 at 14:26
  • @Simon and others, Yes, follow the instructions in [my answer](http://stackoverflow.com/questions/34314146/visual-studio-2015-cant-change-access-modifier-of-new-resources-files/39441597#39441597) – Ramin Bateni Sep 11 '16 at 23:36
6

I had the same problem but I found this easy solution Visual Studio's Access Modifier drop down option is disabled for resource file

To summarize:

  1. Right click on your file resource, choose Properties (Alt+Enter)
  2. Change Build Action to Embedded Resource
  3. Change Custom Tool to PublicResXFileCodeGenerator
Community
  • 1
  • 1
Aranha
  • 2,903
  • 3
  • 14
  • 29
3

A) In Asp.net Core projects

This problem is a known bug in Asp.net Core projects and access modifier is on public by default and you can not change it. It will be solved by asp.net core team next updates but if you need internal access modifier you can use my temporary solution:

  1. Add your all items by the resource designer in your Resource.resx and save it
  2. In the solution explorer expand the Resource.resx tree and open Resource.Designer.cs
  3. Replace all public strings in it with internal and save it

Note: every time you save the Resource.resx file you should do the step 3 again.

Finally you should have a Resource.Designer.cs file with access modifiers like this: enter image description here

Also check the namespace in Resource.Designer.cs file. it should be a appropriate namespace. Sync with your project namespace.


B) In Normal Asp.net projects

If you have not CustomTool property in the Properties panel for your resource (.resx) file to change it to PublicResXFileCodeGenerator and solve the problem

Then you should change some settings in your project (.csproj) file manually. It's so easy, just follow my instructions:

  1. Right click on your project in solution explorer and select Unload Project
  2. Right click again on it and select Edit .....csproj
  3. In the opened .csproj file, find the .resx string, you will see a block of settings there. That is something like bellow codes.
  4. Change it to something like the following code (include PublicResXFileCodeGenerator):

.

<EmbeddedResource Include="MyResourceFile.resx">
      <SubType>Designer</SubType>

      <Generator>PublicResXFileCodeGenerator</Generator> <!--important line-->

      <LastGenOutput>MyResourceFile.Designer.cs</LastGenOutput>
</EmbeddedResource>
  1. Save the edited .csproj file
  2. Right click again on your project in the solution explorer and select Reload project
  3. Now open your .resx file and enjoy ;)

Note: use your resource file name instead of MyResourceFile

Ramin Bateni
  • 16,499
  • 9
  • 69
  • 98
  • But what if there is no `.csproj` file - just a `.xproj` file (note question's the tags)? – Tubbe Sep 13 '16 at 11:32
  • @Tubbe, good point. I edited my answer and added a new temporary solution for this bug in `asp.net core` projects. I hope it works. – Ramin Bateni Sep 13 '16 at 22:18
  • @Simon, i tested it. I created a new Core project and did the core part instruction then i built the core project. Now if i open `Resource.Designer.cs` file i see all access modifiers are `internal` in it. So what is your problem? – Ramin Bateni Sep 25 '16 at 17:21
  • @RAM when I edit the access modifiers to public, I am getting MissingManifestResourceException – Simon Sep 25 '16 at 18:09
  • @Simon, i edited my answer with a pic. Default value is `public` and every time you open the `.resx` file and save it, all access modifiers in it will be changed to `public` automatically (reason is the bug) so there is no need to edit them to `public` manually. If you want public access modifier just open and save it BUT if you want `internal` you can try part `A` of my answer. I test it several times without any error. Check namespace in your `Resource.Designer.cs` file. It should has an appropriate namespace. Also read [this answer](http://stackoverflow.com/questions/1327692#1329631). – Ramin Bateni Sep 25 '16 at 18:47
  • @RAM can I provide some details to you in the chat? – Simon Sep 25 '16 at 19:14
2

I've been having a similar problem.

This appears to be a known issue: https://github.com/aspnet/Tooling/issues/339

Nagoh
  • 813
  • 2
  • 10
  • 23