Visual Studio Code command “dnx run” not available

2019-05-30 04:11发布

问题:

I'm hoping some of you out there have tried out visual studio code for OSX and have gotten it to work with a simple C# console application.

I tried following this guys tutorial, linked below.

Creating and Debugging C# Console Apps with Visual Studio Code on OSX

My problem is that the command "dnx run" is not showing in my command line options in visual studio code. The command "dnx run" works from the terminal, but doesn't show in visual studio code as an available command. All I see from visual studio code for dnx is below.

Additionally I noticed the tutorial tells you to run "dnx .run" from the terminal, this doesn't work for me, it says the command ".run" is invalid, but "dnx run" does work and successfully runs the console application. I'm wondering if that might have something to do with it.


Some background info:

1.) installed dmvm by running this:

curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh

2.) installed dnx mono by running this:

dnvm upgrade -r mono

3.) installed yeoman by running this:

npm install -g yo

4.) installed aspnet generator by running this:

npm install generator-aspnet

5.)ran "yo aspet" and chose console application and named it.

6.) ran "dnu restore" in directory of console app.

7.) ran "dnu build" in directory of console app.

8.) go to run "dnx .run" and get an error saying command not found. Run command "dnx run" and successfully runs console app.

9.) "dnx run" command (or any form of it) is not available from VSCode and it appears it should be according to the tutorial.

I realize this isn't really a code question, but resources on the web are pretty low or confusing regarding getting VScode up and running. Also i'm not a big OSX expert. Does anyone know why I don't see this command from VSCode?

Maybe the tutorial is outdated and dnx run is not available from VSCode anymore or something like that?

回答1:

DNX is obsolete and no longer used or maintained.DNX and DNVM have been replaced by the new .NET CLI. See:.NET Command Line Interface

Try running the command dotnet run in your project folder.



回答2:

The "dnx run" command is not available from vscode because its not in the project.json commands section by default.

I had to change my project.json from this

    "commands":
     {
                "ConsoleApplication": "ConsoleApplication"
     },

to this

    "commands":
     {
                "run": "TestConsoleApp"  //this is the name of your application folder.
     },

Now type ">dnx run" into the VSCode command section and you should see it available.



回答3:

You probably don't have the C# Extension installed. This is not mentioned in the tutorials.

Solution: Extensions -> Install -> C# (by Microsoft)