C# 两个输出文件名解析为相同的输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13739794/
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
Two output file names resolved to the same output
提问by user1613523
Am developing .NET Application for .NET 3.5 Framework. Recently I created new Form called WorkersScreen. When I try to run the project I got this error:
正在为 .NET 3.5 Framework 开发 .NET 应用程序。最近我创建了一个名为 WorkersScreen 的新表单。当我尝试运行该项目时,出现此错误:
Error 1 Two output file names resolved to the same output path: "obj\x86\Debug\DryWash.WorkersScreen.resources" DryWash
What does it mean?
这是什么意思?
回答by Aaron Anodide
I confirm WimOmbelets answer given in the comments. This can apparently happen when you rename a class in VS2012 (I never had this in a prior version).
我确认评论中给出的 WimOmbelets 回答。当您在 VS2012 中重命名一个类时,这显然会发生(我在以前的版本中从未有过这个)。
I can't be sure this is the cause, but one thing I did different from my normal way is I used F2to rename it as opposed to changing it and then pressing control-.
我不能确定这是原因,但我做的与正常方式不同的一件事是我使用F2重命名它,而不是更改它然后按control-。
回答by Wim Ombelets
This can happen in the event of two .resx files pointing to the same form. Mostly happens when renaming forms (other reasons may apply, I'm not exactly sure)
如果两个 .resx 文件指向同一个表单,就会发生这种情况。主要发生在重命名表单时(其他原因可能适用,我不确定)
If your particular form files looks like this:
如果您的特定表单文件如下所示:
Form1.cs
Form1.designer.cs
MyFormerFormName.resx
Form1.resx
then that usually implies that you renamed the form but Visual Studio didn't remove the old .resx file. Once you delete the file (in this example MyFormerFormName.resx) manually, the error should be gone upon next build.
那么这通常意味着您重命名了表单,但 Visual Studio 没有删除旧的 .resx 文件。一旦您MyFormerFormName.resx手动删除文件(在本例中),错误应该在下一次构建时消失。
回答by RDP
This just happened to me. I had accidentally "Drag and dropped" a form into another. It ended up making a copy of it called "Copy of ". I deleted it and the problem went away.
这只是发生在我身上。我不小心“拖放”了一个表单到另一个表单中。它最终制作了一份名为“Copy of”的副本。我删除了它,问题就消失了。
回答by athena
i did a little search i had the same problem it's probably beacause your form has two .resx if you try to delete one, the problem will be gone my form:
我做了一点搜索,我遇到了同样的问题,这可能是因为您的表单有两个 .resx,如果您尝试删除一个,问题就会消失我的表单:
Form1.Designer.cs
Form1.resx
Log_in.resx
Form1
i deleted Log_in.resx and my program worked again
我删除了 Log_in.resx 并且我的程序再次运行
回答by Branden
I thought that I would post on at least one random forum after encountering this error in hopes of easing someone elses problems. I searched many google sites and none had my exact problem. My cause was similar, but different in some ways.
我以为我会在遇到此错误后至少在一个随机论坛上发帖,以期缓解其他人的问题。我搜索了许多谷歌网站,但没有一个有我的确切问题。我的原因很相似,但在某些方面有所不同。
I actually had a partial class spread across multiple files. this class was a form class. This was successful in itself and didn't cause a problem. However, this caused the new class to keep its unique file name while maintaining a split 'class Form' code. It was most likely not kosher practice, but none the less it happened at the time. It seemed like a good alternative to get a lot of cluttered code out of the way. Needless to say, next time I will just use regions or some other alternative.
我实际上有一个分布在多个文件中的部分类。这个类是一个表单类。这本身是成功的,并没有引起问题。但是,这导致新类在维护拆分的“类表单”代码的同时保留其唯一的文件名。这很可能不是犹太教的做法,但在当时确实发生了。摆脱大量杂乱的代码似乎是一个不错的选择。不用说,下次我将只使用区域或其他一些替代方法。
The error then occured when I tried to take the code from the 2nd file and copy/paste into a new non form file with just a class, as I had intended upon essentially turning it into a library and making the code a little more proper and readable. As I didn't know exactly what had caused the error when it happened and had made a small plethora of changes, it took some time to track. Even after reversing the code, I managed to miss a pair of methods.
当我试图从第二个文件中获取代码并将代码复制/粘贴到一个只有一个类的新非表单文件中时,错误发生了,因为我本来打算将它本质上变成一个库并使代码更合适一些可读。由于我不知道发生错误时究竟是什么导致了错误并且做了大量的更改,因此需要一些时间来跟踪。即使在逆向代码之后,我还是错过了一对方法。
The methods for the main form containing the class Form with initializeComponent and form constructor (load). A 2nd copy of these methods appeared to result in the same error. Even after deleting the extra code and extra form and resx files. I even tried deleting the legitimate resx file since it was not actively needed. I was unable to effectively track it, because any errors pointed to the legit versions of these code segments. Ctrl+F and backup copies are your friends.
包含具有 initializeComponent 和表单构造函数 (load) 的类 Form 的主表单的方法。这些方法的第二个副本似乎导致了同样的错误。即使删除了额外的代码和额外的表单和 resx 文件。我什至尝试删除合法的 resx 文件,因为它不是主动需要的。我无法有效地跟踪它,因为任何错误都指向这些代码段的合法版本。Ctrl+F 和备份副本是您的朋友。
Hope that helps someone
希望能帮助某人
回答by Bill Nazzaro
This happened to me when I copied a form to reuse most of the functionality and then renamed the form. I went to the directory referenced, found that there was in fact only one file, copied the file in question, renamed it to reference the name of my new form, and then pasted the new file back in the directory.
当我复制表单以重用大部分功能然后重命名表单时,这发生在我身上。到了引用的目录,发现其实只有一个文件,把有问题的文件复制过来,重命名为引用我的新表单的名字,然后把新文件粘贴回目录中。
I don't think this is a good practice (I'm new to C#) but it did work, instead of having to recreate everything. I also needed to update the form name in a few places throughout the solution, surprising in the original form as well as in the new form.
我不认为这是一个好的做法(我是 C# 的新手),但它确实有效,而不必重新创建所有内容。我还需要在整个解决方案的几个地方更新表单名称,在原始表单和新表单中都令人惊讶。
Copying forms does not seem like a good idea.
复制表格似乎不是一个好主意。
回答by Teoman shipahi
This happened to me when I run Add Migrationcommand and gave same name as my project name as migration class. I removed all migration classes and added new one, solution build again.
当我运行Add Migration命令并将与我的项目名称相同的名称作为迁移类时,这发生在我身上。我删除了所有迁移类并添加了一个新的,再次构建解决方案。
回答by mtRoom
In my case, the issue was caused by an EmbeddedResource tag for a designer.resx file that somehow got added to the .csproj file.
就我而言,该问题是由设计器.resx 文件的 EmbeddedResource 标记引起的,该标记以某种方式添加到 .csproj 文件中。
Specifically, the following:
具体来说,如下:
<EmbeddedResource Include="Forms\frmMenu.designer.resx">
<DependentUpon>frmMenu.designer.cs</DependentUpon>
</EmbeddedResource>
回答by Dean Seo
I had the same issue when I renamed one of my Formclasses using Ctrl + R + Rwhich VS provides to rename things by default.
当我Form使用Ctrl + R + RVS 提供的默认重命名类重命名我的一个类时,我遇到了同样的问题。
Then I somewhat got two classes with the same class name on 2 different files (*.cs).
然后我在 2 个不同的文件 ( *.cs)上得到了两个具有相同类名的类。
class Bar { ... } // From Bar.cs
class Bar { ... } // This should've been Foo, from Foo.cs
The two Barindicating the same resource file that one of them shouldn't.
这两个Bar指示相同的资源文件,其中之一不应该。
It's a trivial issue but sometimes could be hard to find the cause because looking at cs filesjust can't say which one is what you should look for.
这是一个微不足道的问题,但有时可能很难找到原因,因为查看cs 文件无法说出您应该寻找哪个文件。
回答by Majkl
In my option, help delete one *.resx for every form where the error raised
在我的选项中,帮助为每个引发错误的表单删除一个 *.resx
Detail INFO
详细信息
In our project we have 6 *.resx for every form for localization (DE,GB,SK,RU,SRB) and if i delete (from VS) FormName.sr-Latn-CS.resx than the error disappeared. If i try deleted FormName.en-GB.resx it did not help. Error disappeared just for delete sr-Latn-CS.resx (maybe a designer can not solved two - ). I first saw this error when I migrated project from VS 2010 Win 7 to VS2010 Win 10.
在我们的项目中,对于每个本地化表单(DE、GB、SK、RU、SRB),我们有 6 个 *.resx,如果我删除(从 VS)FormName.sr-Latn-CS.resx,错误就会消失。如果我尝试删除 FormName.en-GB.resx 它没有帮助。错误消失只是为了删除 sr-Latn-CS.resx (也许设计者无法解决两个 - )。当我将项目从 VS 2010 Win 7 迁移到 VS2010 Win 10 时,我第一次看到这个错误。

