如何在同一工作区中分别运行多个C#文件?
安装Vscode后,我执行了以下操作:如何在同一工作区中分别运行多个C#文件?,c#,visual-studio-code,C#,Visual Studio Code,安装Vscode后,我执行了以下操作: 我在vscode中打开了一个空文件夹 为VisualStudio代码添加了C# 我在终端中输入了dotnet new console命令,以创建bin、obj文件夹、.csproj文件和Program.cs文件 在命令选项板上单击.Net Generate Assets for Build and Debug,并生成包含launch.json和tasks.json文件的.vscode 我将launch.json文件的“console”部分更改为extern
dotnet new console
命令,以创建bin、obj文件夹、.csproj文件和Program.cs文件dotnew-console
命令创建的Program.cs文件。我在谷歌上搜索了一下,想知道怎么做,然后重新安装了Vscode,但无法修复
这是Program.cs文件和test.cs文件以及launch.json文件
Program.cs
using System;
namespace ProgramFile
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World! Program");
Console.ReadKey();
}
}
}
using System;
namespace testFile
{
class test
{
static void Main(string[] args)
{
Console.WriteLine("Hello World! Test");
Console.ReadKey();
}
}
}
测试.cs
using System;
namespace ProgramFile
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World! Program");
Console.ReadKey();
}
}
}
using System;
namespace testFile
{
class test
{
static void Main(string[] args)
{
Console.WriteLine("Hello World! Test");
Console.ReadKey();
}
}
}
launch.json
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/Vscode.Workspace.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
我的VSocde
有没有办法在一个工作区中创建多个C#文件,并且每次只运行要运行的文件?转到项目->属性->应用程序选项卡->启动对象
C程序只能有一个入口点,按照惯例,该入口点由方法签名
static void Main()
确定。我不确定,为什么一个控制台应用程序需要两个入口点?如果您正在制作两个不同的程序,请创建第二个项目。您不“运行”C#文件,而是将它们编译成可执行文件并运行可执行文件。我如何制作第二个程序?我想在同一个工作区内处理多个程序,但当我创建并运行这样的新文件时,只有通过“dotnet new console”命令创建的文件将继续运行。如果您知道如何在同一工作区中创建两个程序文件,并在必要时调试或运行它们,请告诉我。谢谢您的回答!但是您知道如何打开应用程序选项卡或属性在哪里吗?这是我第一次使用VScode。我用VScode应用程序选项卡进行了搜索,但找不到任何信息。请在.csproj文件下查找“启动对象”。我想说我真的很抱歉。我不知道我是否找不到,但我找不到你说的话。我将把我的VScode的图片放在问题中。如果可能的话,请告诉我它是哪个文件。如果它不在.csproj文件中,您可以添加属性组->{Namespace.className}谢谢。因此,您的意思是在使用“”命令创建的.csproj文件之间和中添加{我要运行的文件的名称空间.ClassName}。你是说?