Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

c# - Can I use one terminal for multiple files in Visual Studio Code?

enter image description here

enter image description here

Here's the error:

C:UserssmaduDocumentsCodeHouseProgram.cs(7,21): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.

I'm fairly new to visual studio so this is probably a simple fix. I've got two files up and would like to run them both through the terminal.

How do I do so separately?

I found that the code as is won't run because I have two "static void Main"s. Changing one to say static void Main2 will fix the error but only run the one without the 2.

Is there a way to run both files through the terminal or not? Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can have multiple files with Main() but as noted above, you can only build and run 1 at a time.

In your project file .csproj file

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net5.0</TargetFramework>

        <!-- set your startup object -->
        <StartupObject>CodeHouse.Test</StartupObject>

    </PropertyGroup>

The above will run your Test console. To build/run your Program change <StartupObject> accordingly.

So end of the day, its really just one "app" (at a time), whatever use case you may have. I personally do this only for organizing some quick scripts/hacks in one physical location/folder/repo.

Hth..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...