【问题标题】:How to configure Vs Code to run Csharp(C#) with Code Runner?如何配置 Vs Code 以使用 Code Runner 运行 Csharp(C#)?
【发布时间】:2021-05-05 21:02:37
【问题描述】:

我的 settings.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,

在终端:

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 etente novamente。 没有 linha:1 caractere:1

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

【问题讨论】:

  • 什么是“scriptcs”程序?

标签: c# visual-studio-code vscode-code-runner coderunner


【解决方案1】:

您可以使用以下命令在终端中运行您的代码:

dotnet run

(确保您的终端 url 必须在项目目录中)

【讨论】:

    【解决方案2】:

    您可以配置代码运行器以使用命令“dotnet run”运行,如下所示:

    "csharp": "dotnet run"
    

    还要确保将代码运行器配置为在终端中运行。

    "code-runner.runInTerminal": true
    

    【讨论】:

      【解决方案3】:

      在 VS Code 中转到设置,搜索“Code-runner:Executor Map” 在那里你可以找到“在 settings.json 中编辑” 打开“settings.json” 在 JSON 中放入以下脚本:

       "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",
         
      },
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-30
        • 2019-02-13
        • 2019-05-11
        • 1970-01-01
        • 2022-01-14
        • 1970-01-01
        相关资源
        最近更新 更多