Visual Studio代码:程序具有多个定义的入口点

编程入门 行业动态 更新时间:2024-10-27 00:36:08
本文介绍了Visual Studio代码:程序具有多个定义的入口点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用 Visual Studio代码 .该项目包含两个.cs文件,分别是 Addition.cs 和 Substraction.cs .这两个文件都包含 main()函数,并且两个文件都包含两个不同的程序.

I created a C# project using Visual Studio Code. This project contains two .cs files, Addition.cs and Substraction.cs. Both files contain a main() function and both files contain two different programs.

代码:

using System; namespace Example { class Addition { static void Main(string[] args) { int sum = 3 + 2; Console.WriteLine(sum); } } }

Substraction.cs 文件中的

代码

Code in the Substraction.cs file

using System; namespace Example { class Substraction { static void Main(string[] args) { int sub = 3 - 2; Console.WriteLine(sub); } } }

我想一个接一个地测试这两个程序,但是当我这样做的时候

I want to test both the programs one by one, but when I do

"dotnet运行"

"dotnet run"

由于上述错误而失败.

我知道,因为同一项目中有两个main()函数(入口点)会导致此错误,但这可以在Visual Studio中通过设置启动项目来克服.

I know because of two main() functions (entry points) in the same project creating this error, but this can be overcome in Visual Studio by setting up a startup project.

我正在使用 Visual Studio代码,在这里我无法设置启动项目.

I am using Visual Studio Code, where I am unable to setup a startup project.

是否可以在Visual Studio Code中为C#项目设置入口点?

Is there a way to setup entry point for a C# project in Visual Studio Code?

推荐答案

如果两个入口点都在同一个项目中,则设置启动项目将无济于事.您需要设置启动 object .

If both entry points are in the same project, setting the startup project wouldn't do anything anyway. You need to set the startup object.

这可以在完整版本的Visual Studio中的项目属性对话框(在应用程序"下查找启动对象")中完成,也可以通过设置Project/PropertyGroup/StartupObject在.csproj文件中完成:

This can be done in the project properties dialog in a full version of VisualStudio (look for "Startup object" under Application), or in the .csproj file by setting Project/PropertyGroup/StartupObject:

<StartupObject>Example.Addition</StartupObject>

或者考虑使用一个带有命令行参数的Main()入口点.

Alternatively consider using a single Main() entry point which takes a command-line argument.

更多推荐

Visual Studio代码:程序具有多个定义的入口点

本文发布于:2023-11-16 10:45:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   入口   定义   代码   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!