moh*_*ael 5 c# console compiler-errors visual-studio-code dotnet-cli
我是 c# 新手,我第一次尝试 Visual Studio Code 是使用命名空间 Microsoft.Toolkit.Uwp.Notifications 中的 ToastContentBuilder 在 Windows 10 上显示通知,这是我的代码:
using Microsoft.Toolkit.Uwp.Notifications;
namespace cs
{
class Program
{
static void Main(string[] args)
{
new ToastContentBuilder ()
.AddArgument("action","hello")
.AddText("my first try in csharp)")
.Show();
}
}
Run Code Online (Sandbox Code Playgroud)
}
这是错误:“ToastContentBuilder”不包含“Show”的定义,并且找不到接受“ToastContentBuilder”类型的第一个参数的可访问扩展方法“Show”(您是否缺少 using 指令或程序集引用? )
如果您将 TargetFramework 设置为更高版本,现在可以使用 - 微软文档说Set your TFM to net5.0-windows10.0.17763.0,尽管我只测试过net6.0-windows10.0.20348.0
Show()仅适用于 #if WINDOWS_UWP 条件编译符号。查看来源:
尝试使用 UWP 项目模板而不是控制台应用程序。