Jon*_*ies 5 c# visual-studio-code vscode-tasks
我有一个 C# 任务,可以在 VSCode 工作区文件夹中生成一个文件。
我希望文件生成后自动打开。目前我能做的最好的事情就是打印文件的全名,以便用户可以Ctrl单击链接。
环境设置:
dotnet new console在终端中键入)。Program.cs:namespace VSCodeOpenGeneratedFile
{
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
File.WriteAllText("test.txt", "Hello world!");
Console.WriteLine(Path.Combine(Directory.GetCurrentDirectory(), "test.txt"));
}
}
}
Run Code Online (Sandbox Code Playgroud)
.vscode/tasks.json:{
"version": "2.0.0",
"tasks": [
{
"label": "Generate File",
"command": "dotnet run",
"type": "shell",
"problemMatcher": []
}
]
}
Run Code Online (Sandbox Code Playgroud)
如何让任务自动打开此文件?
小智 2
我发现您可以使用VS code 的命令行参数来完成此任务。使用-ror--reuse-window参数,您可以在当前的 VS Code 窗口中打开文件。
在使用此任务创建一个过时的 Markdown 文件后,我能够执行此操作:
{
"label": "new note",
"type": "shell",
"command": "set -lx t (date +%Y-%m-%d-%H-%M-%S);echo \"# $t\" > ${workspaceFolder}/notes/$t.md;code -r ${workspaceFolder}/notes/$t.md"
}
Run Code Online (Sandbox Code Playgroud)
这是在带有 Fish shell 的 Linux 上进行的,但您应该能够在 Windows 或其他 shell 中使用类似的命令。
| 归档时间: |
|
| 查看次数: |
2854 次 |
| 最近记录: |