在VS2008中添加到.resx文件的新字符串会导致编译错误,因为它不存在

时间:2022-08-29 22:57:45

I recently upgraded my projects from VS2005 to VS2008. I use a .resx file to store strings and it worked fine with VS2005.

我最近将我的项目从VS2005升级到VS2008。我使用.resx文件存储字符串,它与VS2005一起工作正常。

Now, with VS2008, I added a new string to Strings.resx file and used it in my code (C#). But I got a compilation error that my new string doesn't exist in Strings. I asked my colleague to check it on his machine and he got the same problem. I found out that VS2008 add the new string to the .resx file but not to the .Designer.cs file.

现在,使用VS2008,我在Strings.resx文件中添加了一个新字符串,并在我的代码(C#)中使用它。但是我得到了一个编译错误,我的新字符串在字符串中不存在。我让我的同事在他的机器上检查,他也遇到了同样的问题。我发现VS2008将新字符串添加到.resx文件中,但不添加到.Designer.cs文件中。

Is it a known issue? Is there any way to fix it? (besides adding the code manually to .Designer.cs)

这是一个已知的问题吗?有没有办法解决它? (除了手动将代码添加到.Designer.cs)

Thanks in advance.

提前致谢。

2 个解决方案

#1


Turns out that the problem occurred because my .resx and .Designer.cs files was read-only after I checked them out from StarTeam.

事实证明问题的发生是因为我的.resx和.Designer.cs文件在我从StarTeam检出后是只读的。

In VS2005 I was asked if I want to make both files writable and when I answered yes the .Designer.cs file was also modified, so I could access the new member from my code. But in VS2008, it doesn't ask if I want to make the .Designer.cs file writable, so it stays read-only and VS can't modify it, so I can't access the new member.

在VS2005中,我被问到是否要让两个文件都可写,当我回答是的时,.Designer.cs文件也被修改了,所以我可以从我的代码中访问新成员。但在VS2008中,它不会询问我是否要使.Designer.cs文件可写,因此它保持只读状态,VS无法修改它,因此我无法访问新成员。

To summarize: You should always make both .resx file and .Designer.cs file writable before changing the .resx file to make it work correctly with VS2008.

总结一下:在更改.resx文件之前,应始终使.resx文件和.Designer.cs文件都可写,以使其与VS2008一起正常工作。

#2


I've just tried creating a project in VS2005 with a .resx file and then converting it to VS2008, and there are no problems. However I think I have seen this before: in the Solution Explorer in VS2008, are the .resx and the .designer files displayed separately? i.e. there isn't a '+' icon next to the .resx file which will expand to show the .designer file.

我刚刚尝试在VS2005中使用.resx文件创建一个项目,然后将其转换为VS2008,并且没有任何问题。但是我想我以前见过这个:在VS2008的解决方案资源管理器中,.resx和.designer文件是分开显示的吗?即.resx文件旁边没有“+”图标,该图标将展开以显示.designer文件。

If this is the case, I'm sure there's some way of getting VS2008 to treat them as connected files again. Maybe highlight both in Solution Explorer, right-click and see what the options are?

如果是这种情况,我确信有一些方法可以让VS2008再次将它们视为连接文件。也许在解决方案资源管理器中突出显示,右键单击并查看选项是什么?

#1


Turns out that the problem occurred because my .resx and .Designer.cs files was read-only after I checked them out from StarTeam.

事实证明问题的发生是因为我的.resx和.Designer.cs文件在我从StarTeam检出后是只读的。

In VS2005 I was asked if I want to make both files writable and when I answered yes the .Designer.cs file was also modified, so I could access the new member from my code. But in VS2008, it doesn't ask if I want to make the .Designer.cs file writable, so it stays read-only and VS can't modify it, so I can't access the new member.

在VS2005中,我被问到是否要让两个文件都可写,当我回答是的时,.Designer.cs文件也被修改了,所以我可以从我的代码中访问新成员。但在VS2008中,它不会询问我是否要使.Designer.cs文件可写,因此它保持只读状态,VS无法修改它,因此我无法访问新成员。

To summarize: You should always make both .resx file and .Designer.cs file writable before changing the .resx file to make it work correctly with VS2008.

总结一下:在更改.resx文件之前,应始终使.resx文件和.Designer.cs文件都可写,以使其与VS2008一起正常工作。

#2


I've just tried creating a project in VS2005 with a .resx file and then converting it to VS2008, and there are no problems. However I think I have seen this before: in the Solution Explorer in VS2008, are the .resx and the .designer files displayed separately? i.e. there isn't a '+' icon next to the .resx file which will expand to show the .designer file.

我刚刚尝试在VS2005中使用.resx文件创建一个项目,然后将其转换为VS2008,并且没有任何问题。但是我想我以前见过这个:在VS2008的解决方案资源管理器中,.resx和.designer文件是分开显示的吗?即.resx文件旁边没有“+”图标,该图标将展开以显示.designer文件。

If this is the case, I'm sure there's some way of getting VS2008 to treat them as connected files again. Maybe highlight both in Solution Explorer, right-click and see what the options are?

如果是这种情况,我确信有一些方法可以让VS2008再次将它们视为连接文件。也许在解决方案资源管理器中突出显示,右键单击并查看选项是什么?