且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Visual Studio 2015上找不到控制台应用程序

更新时间:2022-06-13 06:22:13

我遇到了同样的问题,并在

I had the same problem and found the solution on another site. Here are the steps that need to be performed:

  1. 使用管理员权限打开Visual Studio命令窗口.单击位于左下角的Windows按钮(或开始"按钮-取决于操作系统)后,可以通过Windows搜索完成此操作.在继续操作之前,请确保没有打开任何Visual Studio项目.

  1. Open a Visual Studio command window with admin privileges. This can be done from Windows search after clicking on the Windows button (or Start button - depending on the OS) located in the lower left corner. Make sure that you don't have any Visual Studio project open before proceeding.

在搜索框中键入提示,然后选择"Developer Command Prompt".右键单击它,然后选择以管理员权限运行.

Type in prompt in the search box and select "Developer Command Prompt". Right click on this and select run with admin privileges.

在命令窗口中输入:

cd C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE

  1. 在命令窗口中,然后输入:

devenv/installvstemplates

这对我有用,之后我就可以创建一个新的控制台项目.

This worked for me and I was able to create a new console project after this.

在我的VS 2015社区版中,安装后提供了一个控制台应用程序(包)模板,我错误地认为这是控制台应用程序模板.不是这种情况.这是一个Web控制台应用程序项目,只有在尝试从我的代码访问System.IO中的File和Directory类之后,我才发现此问题.编译器不断抱怨:

With my version of VS 2015 community edition, upon install there was a Console Application (Package) template available, which I mistakenly thought was a Console Application template. This is not the case. It is a web console application project and I only discovered this after trying to access the File and Directory classes in System.IO from my code. The compiler kept on complaining:

错误CS0234类型或名称空间名称目录"在名称空间"System.IO"中不存在(您是否缺少程序集引用?) MyProject.DNX Core 5.0 ...

Error CS0234 The type or namespace name 'Directory' does not exist in the namespace 'System.IO' (are you missing an assembly reference?) MyProject.DNX Core 5.0 ...

在添加对System.IO的引用后,甚至在将有问题的代码行更改为以下内容后,它仍然抱怨:

It still complained after putting in a reference to System.IO and even after changing the offending line of code to:

string DataPath = System.IO.Directory.GetCurrentDirectory();

这里有一个主要线索是对DNX Core 5.0的引用,DNX Core 5.0是ASP应用程序的优化运行时.正是在这一点上,我发现控制台应用程序(程序包)模板也已在新建项目"窗口的模板"/"Visual C#/Web"下列出.

A big clue here is the reference to DNX Core 5.0, which is an optimized run-time for ASP apps. It was at that point that I discovered that the Console Application (Package) template was also listed under the New Project window Templates / Visual C# / Web.

因此,对于可能碰巧发现此帖子并认为您正在使用标准控制台应用程序模板的其他人,却遇到诸如"CS0234类型或名称空间名称"在名称空间中不存在..."之类的错误,那么您可能正在使用控制台应用程序(程序包)模板-可能不是您想要的模板,应将其替换为常规控制台应用程序.如果在模板"/"Visual C#"下的新建项目"窗口中看不到它,则应按照上述步骤进行安装.

So, For others that may happen to find this post and think you are using a standard Console Application template, but have errors like "CS0234 The type or namespace "name" does not exist in the namespace..." then you could be using a Console Application (Package) template - which is probably not what you want and should be replaced by a regular Console Application. If you don't see it in the New Project window under Templates / Visual C#, then you should follow the steps above to install it.

编辑

执行完上述步骤后,这是新建项目"窗口的外观:

This is what my New Project window looks like after I performed the steps above:

将此窗口与上面的窗口进行比较,似乎有些不同.请注意,我的窗口上的新项目"居中,而对您而言则不在.另外,在窗口底部,只有名称,位置和解决方案名称,而我的窗口中添加了第四项,称为解决方案.

Comparing this window with yours above, it appears to be somewhat different. Notice that "New Project" on my window is centered and for yours it is not. Also, at the bottom of the window yours has only Name, Location and Solution name, while my window adds a fourth item called Solution.

因此,首先,请尝试单击新建项目"窗口左窗格中的Visual C#,以查看可用的模板.在此处发布快照.这可以通过选择编辑来完成.

So, first thing, try clicking on Visual C# located in the left pane of your New Project window to see the templates available. Post that snapshot here. This can be done by selecting edit.

如果您仍然看不到控制台应用程序模板,则可能您下载的Visual Studio 2015版本与我下载的版本不同.因此,这是在系统上选择帮助"/关于Microsoft Visual Studio"后弹出的屏幕:

If you still don't see the Console Application template, then perhaps you downloaded a different version of Visual Studio 2015 than I did. So, here is the screen that pops up after selecting Help / About Microsoft Visual Studio on my system:

将此屏幕与您的屏幕进行比较,并在此处发布屏幕快照.另外,您使用的是什么操作系统?

Compare this screen with yours and post a snapshot of your screen here. Also, what operating system are you using?