C# 重命名命名空间后找不到为 Main 方法指定的“WindowsFormsApplication1.Program”

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

Could not find 'WindowsFormsApplication1.Program' specified for Main method after renaming name space

c#visual-studio-2010namespaces

提问by Mausimo

I have a C# app that had the default namespace WindowsFormsApplication1.

我有一个具有默认命名空间的 C# 应用程序WindowsFormsApplication1

I decided that I would like to use a different namespace so I renamed WindowsFormsApplication1. Now when I compile I get the error:

我决定要使用不同的命名空间,因此我将WindowsFormsApplication1. 现在,当我编译时,出现错误:

Could not find 'WindowsFormsApplication1.Program' specified for Main method.

找不到为 Main 方法指定的“WindowsFormsApplication1.Program”。

To rename the namespace I highlighted the namespace in a file and hit F2.

要重命名命名空间,我在文件中突出显示了命名空间并按 F2。

How do I resolve this and change the actual namespace through out the project?

我如何解决这个问题并在整个项目中更改实际的命名空间?

I am using Visual C# 2010 Express.

我正在使用 Visual C# 2010 Express。

采纳答案by Mausimo

In project -> properties change "startup object" to the new namespace.

在项目 -> 属性中,将“启动对象”更改为新的命名空间。

Select Startup Object

选择启动对象

回答by Stecenko Ruslan

You should rename through the "Refаctor" feature of Visual Studio.

您应该通过 Visual Studio 的“重构”功能重命名。

回答by d219

As Mausimo says you need to select the 'Startup object' in Project -> References, however I was finding that the new namespace was not being shown here; I could only select the old namespace or '(Not set)'. If you find the same then it appears VS (this is on 2013) does not pick up the change immediately, restart VS and you can then select the class under the new namespace.

正如 Mausimo 所说,您需要在 Project -> References 中选择“Startup object”,但是我发现这里没有显示新的命名空间;我只能选择旧的命名空间或“(未设置)”。如果您发现相同,那么 VS(这是 2013 年)不会立即接受更改,重新启动 VS,然后您可以选择新命名空间下的类。