我试图编译一个简单的示例代码片段,可以找到here:,但我没有任何运气得到它编译没有错误.

首先,我将网站上的代码片段包装成如下所示的main函数:

using System;
using Microsoft.Extensions.Configuration;

internal class Program
{
  static void Main(string[] args)
  {
    IConfigurationBuilder builder = new ConfigurationBuilder().AddJsonFile(".\appsettings.json", false, true);
    IConfigurationRoot root = builder.Build();

    Console.WriteLine($"Hello, { root["weather"] } world!");
  }
}

我的构建脚本:

#!/bin/bash
mcs monotest.cs \
-r:/usr/lib/dotnet/sdk/8.0.103/Microsoft.Extensions.Configuration.dll \
-r:/usr/lib/dotnet/shared/Microsoft.AspNetCore.App/8.0.3/Microsoft.Extensions.Configuration.Abstractions.dll

但是,我仍然得到以下错误:monotest.cs(10,41): error CS0012: The type System.Object is defined in an assembly that is not referenced. Consider adding a reference to assembly System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (错误消息中的额外引号在粘贴此处之前已被删除.

我在/usr/lib中搜索"System. NTFS",发现了这个文件名的几个不同实例:

$ find /usr/lib -name "System.Runtime.dll"
/usr/lib/dotnet/sdk/8.0.103/Microsoft/Microsoft.NET.Build.Extensions/net461/lib/System.Runtime.dll
/usr/lib/dotnet/shared/Microsoft.NETCore.App/8.0.3/System.Runtime.dll
/usr/lib/dotnet/packs/Microsoft.NETCore.App.Runtime.ubuntu.22.04-x64/8.0.3/runtimes/ubuntu.22.04-x64/lib/net8.0/System.Runtime.dll
/usr/lib/dotnet/packs/NETStandard.Library.Ref/2.1.0/ref/netstandard2.1/System.Runtime.dll
/usr/lib/dotnet/packs/Microsoft.NETCore.App.Ref/8.0.3/ref/net8.0/System.Runtime.dll
/usr/lib/mono/4.5-api/Facades/System.Runtime.dll
/usr/lib/mono/4.7.1-api/Facades/System.Runtime.dll
/usr/lib/mono/4.6.1-api/Facades/System.Runtime.dll
/usr/lib/mono/4.7-api/Facades/System.Runtime.dll
/usr/lib/mono/4.6.2-api/Facades/System.Runtime.dll
/usr/lib/mono/4.5.1-api/Facades/System.Runtime.dll
/usr/lib/mono/4.5.2-api/Facades/System.Runtime.dll
/usr/lib/mono/4.6-api/Facades/System.Runtime.dll
/usr/lib/mono/4.5/Facades/System.Runtime.dll
/usr/lib/mono/4.8-api/Facades/System.Runtime.dll
/usr/lib/mono/4.7.2-api/Facades/System.Runtime.dll

我不知道该把哪一个加到我的 playbook 里. 我try 了其中的一些,但他们只是导致了更多的错误,如:error CS1070: The type System.Object has been forwarded to an assembly that is not referenced. Consider adding a reference to assembly System.Private.CoreLib... etc.

也许我需要一个完整的狗屎更多的这些刚刚正确的组合,但我希望有人会知道答案,这样我就不必try 他们所有.

我只想知道有没有人试过这样的东西.

我的操作系统:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:  Ubuntu 22.04.4 LTS
Release:  22.04
Codename: jammy

单声道版本:

$ mono --version
Mono JIT compiler version 6.8.0.105 (Debian 6.8.0.105+dfsg-3.2 Wed Jun 30 05:34:49 UTC 2021)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
  TLS:           __thread
  SIGSEGV:       altstack
  Notifications: epoll
  Architecture:  amd64
  Disabled:      none
  Misc:          softdebug
  Interpreter:   yes
  LLVM:          supported, not enabled.
  Suspend:       hybrid
  GC:            sgen (concurrent by default)

顺便说一句,如果有人想问"你想做什么",这里是答案:没有什么具体的,我只是想学习一些东西. 我在一个学习网站上看到了一些类似的代码,但我不想经历注册Microsoft帐户的麻烦,只是为了下载Visual Studio Community Edition并在我的Windows机上运行它.

提前感谢!

推荐答案

除非有任何进一步的信息,我认为正确的答案是:"单声道没有维持.使用VS代码. 请参阅原问题后的 comments ."切换到不同的框架解决了我的问题. 感谢@ Lex Li把我带到正确的方向.

Csharp相关问答推荐

如何使用PDFSharp将文本添加到现有PDF

ASP.NET Core 8 Cors标题未显示

如何在Visual Studio中为C# spread操作符设置格式规则?

Unity如何在PlayerPrefs中保存数据?

在命令行中使用时安装,但在单击时不会安装

在实时数据库中匹配两个玩家的问题

使页面内容居中

应用程序启动器,可 Select 物理屏幕

如何将ASP.NET Core 2.1(在.NET框架上运行)更新到较新的版本?

System.Net.Http.HttpClient.SendAsync(request)在docker容器内的POST方法30秒后停止

如何使用MoQ模拟Resources GroupCollection?

未找到任何HTTP触发器.成功部署Azure Functions Project后(c#)

如何在C#中创建VS代码中的控制台应用程序时自动生成Main方法

Swagger没有显示int?可以为空

源代码生成器:CS8795分部方法';Class1.GetS2(字符串)';必须有实现部分,因为它有可访问性修饰符?

在';、';附近有错误的语法.必须声明标量变量";@Checkin";.';

JSON串行化程序问题.SQLite中的空值

Maui:更改代码中的绑定字符串不会更新UI,除非重新生成字符串(MVVM)

C#;AvaloniaUI;MVVM;当另一个窗口上的按钮被单击时,如何更新视图图像源?

.NET8支持Vector512,但为什么向量不能达到512位?