【问题标题】:mcs : Metadata file not foundmcs:未找到元数据文件
【发布时间】:2019-11-12 12:01:38
【问题描述】:

我正在尝试使用

在 ubuntu 命令行上运行 csharp 程序
mcs hello.cs

它可以工作,但我想使用我通过 nuget CLI 下载的 nuget:

using Mailjet.Client;
using Mailjet.Client.Resources;
using System;
using Newtonsoft.Json.Linq;
namespace Mailjet.ConsoleApplication {
 class Program {
  static void Main(string[] args) {
   RunAsync().Wait();
  }
..........

然后我得到错误:

hello.cs(1,15): error CS0234: The type or namespace name `Client' does not exist in the namespace `Mailjet'. Are you missing an assembly reference?

hello.cs(2,15): error CS0234: The type or namespace name `Client' does not exist in the namespace `Mailjet'. Are you missing an assembly reference?                        
hello.cs(4,7): error CS0246: The type or namespace name `Newtonsoft' could not be found. Are you missing an assembly reference? 

所以我参考了一个 SO 答案并尝试了这个

mcs /reference:Mailjet.Api.1.2.2 /reference:Newtonsoft.Json.9.0.1 hello.cs

现在我得到一个不同的错误

error CS0006: Metadata file `Mailjet.Api.1.2.2' could not be found                                      
error CS0006: Metadata file `Newtonsoft.Json.9.0.1' could not be found 

我尝试过其他方法,例如

mcs hello.cs -r:Mailjet.Api.1.2.2 -r:Newtonsoft.Json.9.0.1 

但没有区别

这是我的目录结构

.
├── Mailjet.Api.1.2.2
│   ├── Mailjet.Api.1.2.2.nupkg
│   └── lib
│       ├── net45
│       │   └── Mailjet.Client.dll
│       └── netstandard1.1
│           └── Mailjet.Client.dll
├── Newtonsoft.Json.9.0.1
│   ├── Newtonsoft.Json.9.0.1.nupkg
│   ├── lib
│   │   ├── net20
│   │   │   ├── Newtonsoft.Json.dll
│   │   │   └── Newtonsoft.Json.xml
│   │   ├── net35
│   │   │   ├── Newtonsoft.Json.dll
│   │   │   └── Newtonsoft.Json.xml
│   │   ├── net40
│   │   │   ├── Newtonsoft.Json.dll
│   │   │   └── Newtonsoft.Json.xml
│   │   ├── net45
│   │   │   ├── Newtonsoft.Json.dll
│   │   │   └── Newtonsoft.Json.xml
│   │   ├── netstandard1.0
│   │   │   ├── Newtonsoft.Json.dll
│   │   │   └── Newtonsoft.Json.xml
│   │   ├── portable-net40+sl5+wp80+win8+wpa81
│   │   │   ├── Newtonsoft.Json.dll
│   │   │   └── Newtonsoft.Json.xml
│   │   └── portable-net45+wp80+win8+wpa81
│   │       ├── Newtonsoft.Json.dll
│   │       └── Newtonsoft.Json.xml
│   └── tools
│       └── install.ps1
├── hello.cs
├── hello.exe
└── tree.txt

14 directories, 22 files

请帮助我。我不想使用 Visual Studio IDE

【问题讨论】:

  • 您是否特别需要直接使用mcs 而不是.NET Core SDK?后者将使这一切变得更加简单。但如果您确实想指定引用,则应指定要引用的 DLL 的完整路径。
  • @JonSkeet 你能提供一个完整路径的例子吗
  • 鉴于你所拥有的,比如Mailjet.Api.1.2.2/lib/netstandard1.1/Mailjet.Client.dll
  • @JonSkeet 这是错误的语法:使用 Mailjet.Api.1.2.2/lib/netstandard1.1/Mailjet.Client.dll 显然不起作用。我收到语法错误。我想我没明白你的意思
  • 不,不适用于 using 指令 - 用于您尝试指定引用的命令行。当您指定要使用的其他程序集时,您需要指定文件的路径。

标签: c# visual-studio nuget


【解决方案1】:

我认为你应该使用这种格式的命令:

mcs  /reference:Mailjet.Client.dll /reference:Newtonsoft.Json.dll hello.cs

对于这种格式,我们需要确保Mailjet.Client.dllNewtonsoft.Json.dll 位于hello.cs 所在的同一文件夹中。

(将netstandard1.x文件夹中的两个程序集复制到hello.cs文件所在的文件夹中)

此外:您还可以使用完整路径指定引用,例如:

mcs  /reference:path/Mailjet.Client.dll /reference:path/Newtonsoft.Json.dll hello.cs

【讨论】:

  • 可以简单地提供程序集的完整路径,而不是复制它们。
  • 当然也支持全路径,会加的:)谢谢提示!
  • 感谢回复
  • 不客气:) 如果这个问题不再阻碍你(当这个问题解决后),请随时告诉我,然后我们可以归档这个帖子!
猜你喜欢
  • 2013-11-08
  • 2022-10-20
  • 2013-03-11
  • 2010-11-28
  • 2015-05-13
  • 2018-10-05
  • 1970-01-01
  • 2014-05-31
相关资源
最近更新 更多