Console App (.Net Standard) not listed

2020-06-30 05:14发布

I am using Visual Studio 2017 and trying to create a "Console App (.Net Standard)". It is no longer on my list of available projects when I do "File -> New Project..."

options in Visual Studio

It was there a few minutes ago. It disappeared after I created a "Console App (.Net Core)" and then deleted that app because I realized I really wanted a Standard app.

I deleted it by removing it from Visual Studio, then going to the file system and deleting it.

I tried running the installer and updating the 2017 install. That did not help.

How can I get "Console App (.Net Standard)" available as a project type to create?

[EDIT] I have shutdown and restarted visual studio.

[EDIT] I have attempted to run devenv /installvstemplates but the devenv command is not found. I found it located here: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE. What is the preferred way to call it? [add to path or some other way?]

[EDIT] I ran like this: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" /installvstemplates and got a The operation could not be completed. The requested operation requires elevation..

[EDIT] I ran like this: runas /user:Administrator "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" /installvstemplates and got a RUNAS usage help message.

[EDIT] I ran the command in a powershell window with Administrator privilege and got this:

PS C:\Windows\system32> 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv' /installvstemplates
At line:1 char:75
+ ... iles (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv' /installv ...
+                                                                  ~
You must provide a value expression following the '/' operator.
At line:1 char:75
+ ... \Microsoft Visual Studio 14.0\Common7\IDE\devenv' /installvstemplates
+                                                        ~~~~~~~~~~~~~~~~~~
Unexpected token 'installvstemplates' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

[EDIT] found out that I need to run the quoted command prefixed with a &. Now I can run devenv.

[EDIT] I decided I needed a "Console App (.Net Standard)" after posting this question: Project Type for simple headless windows application

2条回答
狗以群分
2楼-- · 2020-06-30 05:45

It doesn't make sense to create a .NET Standard console app.

You can think of .NET Standard like you would an interface in C#. .NET Standard is an interface, then there's concrete implementations of it in .NET Framework, .NET Core and other platforms. .NET Standard makes sense for class libraries, but a console app needs to actually run on a specific concrete implementation.

Thus, there is no Visual Studio project template for .NET Standard console apps. You can create a console app for .NET Framework or .NET Core and then consume .NET Standard class libraries.

查看更多
叛逆
3楼-- · 2020-06-30 05:46

My code looked like this

using System;
namespace TriNitroToluene
{
    public static class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.Read();
        }
    }
}

In the project properties, set output type to console application, and just change the extension to EXE. that's how it works!

查看更多
登录 后发表回答