在Visual Studio上运行csharp代码时出现意外的命名参数错误 [英] got unexpected named argument error when running csharp code on visual studio

查看:494
本文介绍了在Visual Studio上运行csharp代码时出现意外的命名参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Visual Studio Code for Mac中运行csharp代码,我安装了脚本并将其添加到PATH.
它给了我下面的错误,并且代码无法运行.

I tried to run the csharp code in Visual Studio Code for Mac, I have scripts installed and added to PATH.
It gives me below error and code cannot run.

[Running] scriptcs "/var/folders/sr/5jzw91rn4g3cc2b0xyhw0j100000gq/T/tempCodeRunnerFile.csharp"
    Unexpected named argument: var/folders/sr/5jzw91rn4g3cc2b0xyhw0j100000gq/T/tempCodeRunnerFile.csharp

这是链接的问题:获取错误:/bin/sh脚本:找不到命令

操作系统版本为10.14.6(18G87),请参阅所附的屏幕截图.

The OS version is 10.14.6(18G87) Please see attached screenshot.

Visual Studio Code版本如下:

The Visual Studio Code version is below:

Version: 1.38.1
Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
Date: 2019-09-11T13:31:32.854Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Darwin x64 18.7.0

最小可重复示例:

打开Visual Studio代码并使用以下代码创建一个新文件:

minimal reproducible example:

Open Visual Studio Code and create a new File with below code:

using System;
using System.Collections.Generic;
class Test
{
    static void Main()
    {
        foreach (int fib in Fibs(6))
        Console.Write (fib + " ");
    }
    static IEnumerable<int> Fibs (int fibCount)
    {
        for (int i = 0, prevFib = 1, curFib = 1; i < fibCount; i++)
        {
             yield return prevFib;
             int newFib = prevFib+curFib;
             prevFib = curFib;
             curFib = newFib;
        }
     }
 }

,然后单击Visual Studio代码右上方的运行代码".

and then click Run Code on top right in Visual Studio Code.

推荐答案

这是 PowerArgs ,它可以识别以slash开头的参数,因此您需要将命令分为两个步骤.

This is a bug in PowerArgs, it recognizes an argument started with slash as an option, so you need split the command into two steps.

cd "/var/folders/sr/5jzw91rn4g3cc2b0xyhw0j100000gq/T"
scriptcs "tempCodeRunnerFile.csharp"


[更新] scriptcs是一个csharp代码运行器,要使其运行,至少需要一行来调用entry方法.


[Update] scriptcs is a csharp code runner, to make it work, at least you need one line to call the entry method.

...

class Test
{
    public static void Main() // Public
    {
        ...
    }
}

Test.Main(); // Run it

这篇关于在Visual Studio上运行csharp代码时出现意外的命名参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆