.net 有没有办法重新生成丢失的 .resx 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13354111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:42:12  来源:igfitidea点击:

Is there a way to regenerate a missing .resx file?

.netresx

提问by B. Clay Shannon

I have the source for a project, but am missing the .resx file, which prevents compilation. Is there a way to re-generate a resx file for it? This is a C# project I created with Visual Studio 2010 Professional on an XP machine that I'm trying to open with Visual Studio 2012 Ultimate on a Windows 8 machine.

我有一个项目的源代码,但缺少 .resx 文件,这会阻止编译。有没有办法为它重新生成一个 resx 文件?这是我在 XP 机器上使用 Visual Studio 2010 Professional 创建的 C# 项目,我试图在 Windows 8 机器上使用 Visual Studio 2012 Ultimate 打开该项目。

UPDATE

更新

It (Resources.resx) was actually there (under Properties), so I guess "cannot be found" means: "I don't like the one you gave me."

它 (Resources.resx) 实际上就在那里(在 Properties 下),所以我猜“无法找到”的意思是:“我不喜欢你给我的那个。”

When I mashed F6 to give it another try, I got the warning, "A custom tool 'ResXFileCodeGenerator' is associated with file 'Properties\Resources.resx', but the output of the custom tool was not found in the project. You may try re-running the custom tool by right-clicking on the file in the Solution Explorer and choosing Run Custom Tool."

当我捣碎 F6 再试一次时,我收到警告,“自定义工具 'ResXFileCodeGenerator' 与文件 'Properties\Resources.resx' 相关联,但在项目中找不到自定义工具的输出。您可能尝试通过右键单击解决方案资源管理器中的文件并选择运行自定义工具来重新运行自定义工具。”

also: "A custom tool 'SettingsSingleFileGenerator' is associated with file 'Properties\Settings.settings', but the output of the custom tool was not found in the project. You may try re-running the custom tool by right-clicking on the file in the Solution Explorer and choosing Run Custom Tool."

另外:“自定义工具‘SettingsSingleFileGenerator’与文件‘Properties\Settings.settings’相关联,但在项目中找不到自定义工具的输出。您可以尝试通过右键单击自定义工具来重新运行自定义工具解决方案资源管理器中的文件,然后选择运行自定义工具。”

I ran "Run Custom Tool" for both Resources.resx and Settings.settings, and still get the same error and two warnings.

我为 Resources.resx 和 Settings.settings 运行了“运行自定义工具”,但仍然收到相同的错误和两个警告。

采纳答案by DeanOC

If you have compiled the project in the past and have the dll/exe available, you can use JetBrains' DotPeek app to export the resx XML from the assembly

如果您过去编译过该项目并且有可用的 dll/exe,则可以使用 JetBrains 的 DotPeek 应用程序从程序集中导出 resx XML

Open the dll/exe in DotPeek

DotPeek 中打开 dll/exe

enter image description here

在此处输入图片说明

Then double-click each resource to see the XML in a window. You can then copy/paste the XML into a text editor and save as a .resx file.

然后双击每个资源以在窗口中查看 XML。然后,您可以将 XML 复制/粘贴到文本编辑器中并另存为 .resx 文件。

Don't bother right-clicking the resource and trying the 'Save Resource to File' option, as this doesn't create the file in the same format as you see on the screen.

不要费心右键单击资源并尝试“将资源保存到文件”选项,因为这不会以您在屏幕上看到的相同格式创建文件。

回答by Milind Morey

Right click and remove .resx form project right click on form and update resource manager build project run project

右键单击并删除 .resx 表单项目右键单击表单并更新资源管理器构建项目运行项目

回答by ub3rst4r

I know this question is a little old, but I was having problems generate the .resources.dll files and after recently changing the .NET Framework version, the .ResX files still included the old .NET Framework version. I was able to resolve this by opening the affected forms and going to "Design" -> "Localizable" and changing it to "False". Then I built the project and then changed it back to "True" and the .ResX file was regenerated.

我知道这个问题有点老了,但是我在生成 .resources.dll 文件时遇到了问题,并且在最近更改了 .NET Framework 版本后,.ResX 文件仍然包含旧的 .NET Framework 版本。我能够通过打开受影响的表单并转到“设计”->“可本地化”并将其更改为“假”来解决此问题。然后我构建了该项目,然后将其改回“True”并重新生成了 .ResX 文件。

回答by Wayne

I had this problem on a form I created for a rather extensive project. I was able to simply copy the resx of another form, in the same project, and change the filename.

我在为一个相当广泛的项目创建的表单上遇到了这个问题。我能够简单地复制另一个表单的 resx,在同一个项目中,并更改文件名。

I went through over a dozen of the resx files in my project and noticed that most of them were identical; the few that were not, only differed by one or two extra lines.

我浏览了项目中的十多个 resx 文件,并注意到它们中的大多数是相同的;少数不是,仅相差一两行。

回答by Peter Brennen

Visual Studio 2012-2015 users For a Web Application, simply select the Web Control (ascx) or Page (aspx) that is missing the resx in Solution Explorer and go to the Project menu and select "Convert to Web Application", press OK on the prompt. You should see the new files under the selected item in Solution Explorer.

Visual Studio 2012-2015 用户对于 Web 应用程序,只需在解决方案资源管理器中选择缺少 resx 的 Web 控件 (ascx) 或页面 (aspx),然后转到“项目”菜单并选择“转换为 Web 应用程序”,然后按 OK提示。您应该会在解决方案资源管理器中的所选项目下看到新文件。

回答by COLD TOLD

As far as I have read there is no way to regenerate .resx file but you can go another way you can create another/same win application and all the controls aspects to it . Than take a newly created resx file and add to old project. Try it maybe it will work

据我所知,无法重新生成 .resx 文件,但您可以采用另一种方式来创建另一个/相同的 win 应用程序及其所有控件方面。然后将新创建的 resx 文件添加到旧项目中。试试看也许会奏效

回答by B. Clay Shannon

Here's how I solved it: I opened the missing ancillary files (AssemblyInfo.cs, Resources.resx, Resources.Designer.cs, Settings.settings, and Settings.Designer.cs) from another project in Notepad, removed the things that didn't belong (such as the reference to ThemeEditor or some such), changed other things as necessary (the name of the app or package), and these were finally accepted as those belonging to my app.

这是我解决它的方法:我从记事本中的另一个项目中打开了丢失的辅助文件(AssemblyInfo.cs、Resources.resx、Resources.Designer.cs、Settings.settings 和 Settings.Designer.cs),删除了那些没有的东西t 属于(例如对 ThemeEditor 的引用等),根据需要更改其他内容(应用程序或包的名称),这些最终被接受为属于我的应用程序的内容。

回答by George M

If running VS 2017 or greater I just deleted the file.

如果运行 VS 2017 或更高版本,我只是删除了该文件。

回答by user4815065

copy the .resxfile of any other form in the project to the project folder and try again. It worked for me.

.resx项目中任何其他形式的文件复制到项目文件夹中,然后重试。它对我有用。