visual-studio Visual Studio 告诉我我的项目不支持代码是什么意思?

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

What does it mean when Visual Studio tells me my project doesn't support code?

visual-studio

提问by Luke

Possible Duplicate:
Errors in Windows Forms controls in designer view

可能的重复:
设计器视图中 Windows 窗体控件中的错误

The file 'C:\Users[path removed]\ReportForm.cs' does not support code parsing or generation because it is not contained within a project that supports code.

文件“C:\Users[path removed]\ReportForm.cs”不支持代码解析或生成,因为它不包含在支持代码的项目中。

alt text

替代文字

回答by Luke

I've come across this one when I've renamed a form then closed and re-opened VS. The error is thrown and I can't see the designer. The remedy for me was checking to make sure the project form is looking for my newly named form and not the old name, if it is the old name then just delete it and add->existing item.

当我重命名一个表单然后关闭并重新打开 VS 时,我遇到了这个。错误被抛出,我看不到设计者。对我来说,补救措施是检查以确保项目表单正在寻找我新命名的表单而不是旧名称,如果它是旧名称,则只需将其删除并添加-> 现有项目。

All should be good from that point.

从那时起,一切都应该很好。

回答by Waqar Salim

The solution that helped me was that I was running my VS in compatibility mode and also as an administrator.

帮助我的解决方案是我在兼容模式下运行我的 VS 并且作为管理员运行。

In order to make it run smoothly you have to uncheck the "compatibility" and "Run as administrator" options.

为了让它顺利运行,您必须取消选中“兼容性”和“以管理员身份运行”选项。

回答by JaredPar

I don't believe that the problem is a lack of supporting code. It's more likely that the code in ReportForm.cs or ReportForm.designer.cs is not parsable by the WinForms designer class. You can verify this by deleting all of your code and type in something very simple and reload the designer.

我不认为问题在于缺乏支持代码。更有可能的是,WinForms 设计器类无法解析 ReportForm.cs 或 ReportForm.designer.cs 中的代码。您可以通过删除所有代码并输入非常简单的内容并重新加载设计器来验证这一点。

Example:

例子:

public class ReportForm(){ 
  public ReportForm(){}
}