2015-06-09 108 views
20

我想试用微软的新编辑器 - Visual Studio Code。 我想实现一个简单的应用程序(如Hello,World)并能够调试它。但经过大量的谷歌搜索和尝试,我没有设法做到这一点。那可能吗?我安装了Visual Studio 2015的Windows 10。Windows上的Visual Studio代码,C#支持

我已经尝试做的事:

1)取消注释在tasks.json文件中的以下内容:

{ 
"version": "0.1.0", 
"command": "msbuild", 
"args": [ 
    // Ask msbuild to generate full paths for file names. 
    "/property:GenerateFullPaths=true" 
], 
"taskSelector": "/t:", 
"showOutput": "silent", 
"tasks": [ 
    { 
     "taskName": "build", 
     // Show the output window only if unrecognized errors occur. 
     "showOutput": "silent", 
     // Use the standard MS compiler pattern to detect errors, warnings 
     // and infos in the output. 
     "problemMatcher": "$msCompile" 
    } 
] 

但是编译(按Ctrl-Shift-B键)失败,出现错误:“无法启动外部程序的MSBuild 产卵的MSBuild ENOENT。“

2)阅读这篇文章:http://michaelcrump.net/creating-and-debugging-console-apps-with-vscode/,但我没有任何project.json文件,也是‘dnx . run’失败,出现错误” System.InvalidOp erationException:无法解决项目

有没有简单的方法来在VS代码中运行简单的C#应用​​程序?我想知道为什么它如此复杂。可能,我错过了一些东西,欢迎任何想法。

更新1:添加的MSBuild到路径有助于

+0

VS Code的功能还是有限的。在Visual Studio 2015中运行简单的C#应用​​会容易得多。 – natemcmaster

+0

您是否对此有进一步了解?我也只是发现了VSC,这对于小的变化来说是VS的一个很好的替代方案,但是我得到了同样的错误。 – svanelten

+0

@svanelten,不幸的是,没有。但我使用旧版本的VS Code,你有哪个版本? – pfedotovsky

回答

7

The C# support in VS Code is optimized for cross platform .NET development (DNX) (see working with ASP.NET 5 and VS Code for another relevant article. Our focus with VS Code is to be a great editor for cross platfrom C# development - for instance many Unity developers have been enjoying using VS Code in place of Mono Develop.

We support debugging of C# apps cross platfrom via Mono (see Mono Debugging).

Due to this focus many standard C# project types are not recognised by VS Code. An example of a non-supported project type is an ASP .NET MVC Application. In these cases if you simply want to have a lightweight tool to edit a file - VS Code has you covered. If you want the best possible experience for those projects, and development on Windows in general we recomend you use Visual Studio Community.

来自:code.visualstudio.com/Docs/languages/csharp


更新,2017年6月:

C#在Visual Studio代码使用微软的VS支持代码C#扩展名:https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp

这可以通过在扩展:安装扩展中搜索'C#'来安装。或者,打开.cs文件应提示安装扩展。

该扩展支持在.NET运行核心的C#应用​​程序的调试,但桌面.NET框架运行支持调试应用程序 - Visual Studio Community仍建议全。 NET项目支持。

有关VS代码的C#支持的详细信息,请参阅https://code.visualstudio.com/docs/languages/csharp

欲了解VS代码C#扩展市场页面,看到https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp

4

您可以构建完整的.NET应用程序就好了,注意设置msbuild您必须在路径上有msbuild或在command属性中提供完整路径。这就是例子生成任务(绑定到ctrl + shift + b)看起来像:

{ 
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format 
    "version": "0.1.0", 
    "command": "MSBuild.exe", 
    "args": [ 
     // $msCompile requires GenerateFullPaths=true, rest is optional. I set it to build Debug/Any CPU and use parallel project build 
     "${workspaceRoot}/src/ExampleSolution.sln", 
     "/p:Configuration=Debug;Platform=Any CPU;GenerateFullPaths=true", 
     "/m" 
    ], 
    "taskSelector": "/t:", 
    "showOutput": "silent", 
    "echoCommand": true, 
    "tasks": [ 
     { 
      "taskName": "Rebuild", 
      // Required if you want "Rebuild", not build as your target and still use ctrl + shift + b hotkey 
      "isBuildCommand": true, 
      // Show the output window only if unrecognized errors occur. 
      "showOutput": "silent", 
      // Use the standard MS compiler pattern to detect errors, warnings and infos 
      "problemMatcher": "$msCompile" 
     } 
    ] 
} 

UPD:如果你想建立两个建筑物和单位试运行,你可以使用这样的事情(使用nunit控制台亚军和cmd的任务,破解各地vscode限制只支持单任务):

{ 
    "version": "0.1.0", 
    "command": "cmd", 
    "args": [ 
     "/c" 
    ], 
    "showOutput": "always", 
    "echoCommand": true, 
    "tasks": [ 
     { 
      "isBuildCommand": true, 
      "taskName": "MSBuild.exe", 
      "args": [ 
       "${workspaceRoot}/src/Example.sln", 
       "/t:Rebuild", 
       "/p:Configuration=Debug;Platform=Any CPU;GenerateFullPaths=true", 
       "/m" 
      ], 
      "showOutput": "always", 
      "problemMatcher": "$msCompile" 
     }, 
     { 
      "taskName": "nunit3-console.exe", 
      "args": [ 
       "${workspaceRoot}/src/Example.sln" 
      ], 
      "showOutput": "always" 
     } 
    ] 
} 
1

有同样的问题。修改了msbuild的直接路径修复了它:

{ 
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format 
    "version": "0.1.0", 
    "windows": { 
     "command": "C:\\Program Files(x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe" 
    }, 
    // "command": "msbuild", 
    "args": [ 
     // Ask msbuild to generate full paths for file names. 
     "/property:GenerateFullPaths=true" 
    ], 
    "taskSelector": "/t:", 
    "showOutput": "silent", 
    "tasks": [ 
     { 
      "taskName": "build", 
      // Show the output window only if unrecognized errors occur. 
      "showOutput": "silent", 
      // Use the standard MS compiler pattern to detect errors, warnings and infos 
      "problemMatcher": "$msCompile" 
     } 
    ] 
} 
相关问题