例如,如果我当前在sublime中的文件是foo.cs,我希望它运行“csc /out:foo.exe foo.cs”。我不想运行完整的 msbuild。
在 Sublime 中,选择菜单 Tools > Build System > New Build System 粘贴以下文本。将其保存为“C#.sublime-build”。
{
"cmd": ["cmd", "/c", "del", "${file/\\.cs/\\.exe/}", "2>NUL", "&&", "csc", "/nologo", "/out:${file/\\.cs/\\.exe/}", "$file"],
"file_regex": "^(...*?)[(]([0-9]*),([0-9]*)[)]",
"variants": [
{ "name": "Run", "cmd": ["cmd", "/c", "start", "cmd", "/c", "${file/\\.cs/\\.exe/}"] }
],
}
或者当您输入 ctrl-b 时,此替代行将构建并运行它:
"cmd": ["cmd", "/c", "del ${file/\\.cs/\\.exe/} 2>NUL && csc /nologo /out:${file/\\.cs/\\.exe/} $file && start cmd /c ${file/\\.cs/\\.exe/}"],
您可以使用以下配置创建一个新的构建系统。
{
"cmd":["csc","$file"],
"selector":"source.cs",
"variants" :
[
{
"cmd" : "$file_base_name.exe",
"name" : "run",
"shell" : true,
}
]
}
下面的 C#.sublime-build 在新的弹出式控制台中编译并运行任何 c# 程序。但它只适用于windows用户。其他操作系统用户可能会在以下 C#.sublime-build 中稍微更改“cmd”键的值,以制作他们的自定义 C#.sublime-build 系统。希望,这会有所帮助:
{
"cmd": ["csc", "$file_name", "&&", "start","cmd", "/k", "$file_base_name.exe"],
"file_regex": "^(...?):([0-9]):?([0-9]*)",
"working_dir": "$file_path",
"selector": "source.cs",
"shell": true,
"quiet": true
}
只需使用这个和你的 OK
{
"cmd": ["csc", "/out:$file_base_name.exe", "$file_name"],
"selector": "source.cs",
"shell": true,
"working_dir": "${file_path}",
"variants": [
{
"cmd": ["cmd", "/c", "csc", "/out:$file_base_name.exe", "$file_name", "&&", "start", "cmd", "/k", "$file_base_name.exe"],
"name": "Build and Run",
"shell": true,
"working_dir": "${file_path}"
}
]
}