即将推出的 C# 9 的一项功能是所谓的顶级程序。这样您就可以在没有类的情况下编写以下内容。
using System;
Console.WriteLine("Hello World!");
和 dotnet run
将为您启动它。它对我有用,但前提是我还添加了
.csproj
像下面这样的文件<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
有没有办法跳过.csproj
从图片? :) 所以只有一个 Program.cs
文件,仅此而已。
最佳答案
不,没有。 csproj
文件,向编译器解释要生成什么样的输出。
它还引用了任何需要的库,在您的情况下是 SDK:https://docs.microsoft.com/en-us/dotnet/core/tools/csproj
Metapackages are implicitly referenced based on the target framework(s) specified in the
<TargetFramework>
or<TargetFrameworks>
property of your project file.
没有它,net core 将错过关于构建什么以及如何构建的信息。你甚至不会有对
System
的引用。可用的命名空间。
关于没有 csproj 的 C# 9 顶级程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64399484/