pfe*_*sky 22 c# msbuild visual-studio-code
我想尝试一下Microsoft的新编辑器 - Visual Studio Code.我想实现一个简单的应用程序(如Hello,World)并能够调试它.但经过大量的谷歌搜索和尝试,我没有设法做到这一点.那可能吗?我安装了Visual Studio 2015的Windows 10.
我试图做的事情:
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"
}
]
Run Code Online (Sandbox Code Playgroud)
但是编译(ctrl-shift-b)失败并出现错误:"无法启动外部程序msbuild.spawn msbuild ENOENT"
2)阅读这篇文章:http://michaelcrump.net/creating-and-debugging-console-apps-with-vscode/,但我没有任何project.json文件,也" dnx . run
"失败并显示错误" 系统.InvalidOperationException:无法解析项目 "
有没有一种简单的方法在VS Code中运行简单的C#app?我想知道它为何如此复杂.可能,我错过了什么,欢迎任何想法.
更新1:将msbuild添加到路径帮助
VS Code中的C#支持针对跨平台.NET开发(DNX)进行了优化(请参阅使用ASP.NET 5和VS Code获取另一篇相关文章.我们对VS Code的关注是成为跨C#开发的优秀编辑器 - 例如,许多Unity开发人员一直在使用VS Code代替Mono Develop.
我们支持通过Mono调试C#apps cross platfrom(参见Mono Debugging).
由于这一焦点,VS Code无法识别许多标准C#项目类型.不受支持的项目类型的示例是ASP .NET MVC应用程序.在这些情况下,如果您只想拥有一个轻量级工具来编辑文件 - VS Code可以满足您的要求.如果您希望获得这些项目的最佳体验,并且通常在Windows上进行开发,我们建议您使用Visual Studio社区.
来自:code.visualstudio.com/Docs/languages/csharp
2017年6月更新:
Visual Studio Code使用Microsoft的VS Code C#扩展支持C#:https://marketplace.visualstudio.com/items?itemName = ms-vscode.csharp
这可以通过在Extensions:Install Extension中搜索"C#"来安装.或者,打开.cs
文件应提示安装扩展.
此扩展支持调试在.NET Core或Mono上运行的C#应用程序,但不支持在桌面.NET Framework上运行的调试应用程序- 仍建议使用Visual Studio社区以获得完整的.NET项目支持.
有关VS Code的C#支持的更多信息,请参阅https://code.visualstudio.com/docs/languages/csharp
有关VS Code C#扩展的市场页面,请参阅https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp
您可以设置msbuild
构建完整的.NET
应用程序就好了,注意您必须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"
}
]
}
Run Code Online (Sandbox Code Playgroud)
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"
}
]
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12885 次 |
最近记录: |