C# 错误 CS2001:找不到源文件“.cs”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19406924/
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-08-10 14:55:11  来源:igfitidea点击:

Error CS2001: Source file '.cs' could not be found

c#

提问by kevlar90

I am getting the following error on a project of mine when I try to build... Error CS2001: Source file '.cs' could not be found. I took the two files that are causing this error out on purpose because they conflict with other files and cannot be in there. How can I resolve this error without putting the 2 files back in the solution?

当我尝试构建时,我的一个项目出现以下错误...错误 CS2001:找不到源文件“.cs”。我故意取出导致此错误的两个文件,因为它们与其他文件冲突并且不能在那里。如何在不将 2 个文件放回解决方案的情况下解决此错误?

采纳答案by Tim Rogers

They are likely still referenced by the project file. Make sure they are deleted using the Solution Explorer in Visual Studio - it should show them as being missing (with an exclamation mark).

它们可能仍被项目文件引用。确保使用 Visual Studio 中的解决方案资源管理器删除它们 - 它应该显示它们丢失(带有感叹号)。

回答by Eric

I had this problem, too.

我也有这个问题。

Possible causes in my case: I had deleted a duplicated view twice and a view model. I reverted one of the deletes and then the InitializeComponent error appeared. I took these steps.

在我的情况下可能的原因:我删除了两次重复的视图和一个视图模型。我恢复了其中一个删除,然后出现了 InitializeComponent 错误。我采取了这些步骤。

  1. I checked all of the solutions mentioned on this question. The class name and build action were correct.
  2. I Cleaned my Solution and rebuilt. Another error appeared. "Error CS2001: Source file '.cs' could not be found"
  3. I found this answerand followed the steps.
  4. I reloaded the project and cleaned/rebuilt again.
  5. My solution builds without errors and my application works now.
  1. 我检查了这个问题中提到的所有解决方案。类名和构建操作是正确的。
  2. 我清理了我的解决方案并重建。出现了另一个错误。“错误 CS2001:找不到源文件 '.cs'”
  3. 我找到了这个答案并按照步骤操作。
  4. 我重新加载了项目并再次清理/重建。
  5. 我的解决方案构建没有错误,我的应用程序现在可以运行。

回答by AdnR

I open the project,.csproj, using a notepad and delete that missing file reference.

我使用记事本打开项目 .csproj 并删除丢失的文件引用。

回答by Amir Aghajani

In my case, I add file as Link from another project and then rename file in source project that cause problem in destination project. I delete linked file in destination and add again with new name.

就我而言,我将文件添加为来自另一个项目的链接,然后在源项目中重命名导致目标项目出现问题的文件。我删除目标中的链接文件,然后用新名称再次添加。