简体   繁体   English

如何配置 Vs Code 以使用 Code Runner 运行 Csharp(C#)?

[英]How to configure Vs Code to run Csharp(C#) with Code Runner?

My settings.json我的设置。json

"code-runner.ignoreSelection": true,    
"code-runner.executorMap": {
    "javascript": "node",
    "php": "php",
    "python": "python -u",
    "powershell": "powershell -ExecutionPolicy ByPass -File",
    "csharp": "scriptcs -script",
    "vbscript": "cscript //Nologo",
    "typescript": "ts-node",
    "coffeescript": "coffee",
    "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
    "scss": "scss --style expanded"
},
"code-runner.runInTerminal": true,

In Terminal:在终端:

PS C:\Users\avaa1\Desktop\Projeto\ConsoleProject> scriptcs -script "c:\Users\avaa1\Desktop\Projeto\ConsoleProject\Program.cs" scriptcs: O termo 'scriptcs' não é reconhecido como nome de cmdlet, função, arquivo de script ou programa operável. PS C:\Users\avaa1\Desktop\Projeto\ConsoleProject> scriptcs -script "c:\Users\avaa1\Desktop\Projeto\ConsoleProject\Program.cs" scriptcs: O termo 'scriptcs' não é reconhecido como nome de cmdlet, função,arquivo de script ou programa operável。 Verifique a grafia do nome ou, se um caminho tiver sido incluído, veja se o caminho está correto e tente novamente. Verifique a grafia do nome ou, se um caminho tiver sido incluído, veja se o caminho está correto etente novamente。 No linha:1 caractere:1没有 linha:1 caractere:1

  • scriptcs -script "c:\Users\avaa1\Desktop\Projeto\ConsoleProject\Progr... scriptcs -script "c:\Users\avaa1\Desktop\Projeto\ConsoleProject\Progr...
  •  + CategoryInfo: ObjectNotFound: (scriptcs:String) [], CommandNotFoundException + FullyQualifiedErrorId: CommandNotFoundException

you can run your code in terminal by using this command:您可以使用以下命令在终端中运行代码:

dotnet run

(make sure your terminal url must be in the project directory) (确保您的终端 url 必须在项目目录中)

You can configure code runner to run with the command "dotnet run" like this:您可以配置代码运行器以使用命令“dotnet run”运行,如下所示:

"csharp": "dotnet run"

Also make sure that code runner is configured to run in the terminal.还要确保将代码运行器配置为在终端中运行。

"code-runner.runInTerminal": true

In VS Code Go to Settings, Search for " Code-runner:Executor Map " There you find " Edit in settings.json " open " settings.json " inside JSON put the following Script: In VS Code Go to Settings, Search for " Code-runner:Executor Map " There you find " Edit in settings.json " open " settings.json " inside JSON put the following Script:

 "code-runner.executorMap": {

    "javascript": "node",
    "php": "C:\\php\\php.exe",
    "python": "python",
    "perl": "perl",
    "ruby": "C:\\Ruby23-x64\\bin\\ruby.exe",
    "go": "go run",
    "html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
    "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
    "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
    
    "csharp": "cd $dir && dotnet run",
   
},

Step 1: First you should install cs-script from here第 1 步:首先你应该从这里安装 cs-script

step 2: Make sure cs-script is installed, open terminal and type css第 2 步:确保已安装 cs-script,打开终端并输入css

Step 3: Open VS Code settings.json file [ VS Code: How to open settings.json file?第 3 步:打开 VS 代码settings.json文件 [ VS 代码:如何打开 settings.json 文件? ] ]

Step 4: Add the below lines at the end of your file ( Note: if "code-runner.executorMap" config is already present, then you have to copy and paste/replace only "csharp": "cd $dir && css $fileName" )第 4 步:在文件末尾添加以下行(注意:如果“code-runner.executorMap”配置已经存在,那么您只需复制和粘贴/替换"csharp": "cd $dir && css $fileName" )

"code-runner.executorMap": {
      "csharp": "cd $dir && css $fileName",
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM