Ada*_*gle 6 .net c# mono nuget
我在Ubuntu 17.10上使用Mono 5.4.1.7编写C#代码。
这是我想从命令行执行的所有操作:
但是我看不到任何简单的方法可以做到这一点,所以我一定会缺少一些东西。
这是我尝试过的。我为程序创建了目录“ foo”。在那个目录里,我跑了
$ nuget install MathNet.Numerics
Run Code Online (Sandbox Code Playgroud)
那下载了MathNet.Numerics库并将其放在子目录'MathNet.Numerics.3.20.2'中。到目前为止,一切都很好。
然后,我创建了测试程序foo.cs,如下所示:
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
class Foo {
static void Main() {
Vector<double> A = DenseVector.OfArray(new double[] { 1, 2, 3, 4 });
}
}
Run Code Online (Sandbox Code Playgroud)
但是现在我不能简单地使用mcs进行构建:
$ mcs Foo.cs
foo.cs(1,7): error CS0246: The type or namespace name `MathNet' could not be found. Are you missing an assembly reference?
foo.cs(2,7): error CS0246: The type or namespace name `MathNet' could not be found. Are you missing an assembly reference?
Run Code Online (Sandbox Code Playgroud)
如果我明确指定已安装的程序集,它将起作用:
$ mcs -reference:MathNet.Numerics.3.20.2/lib/net40/MathNet.Numerics.dll foo.csfoo.cs(6,20): warning CS0219: The variable `A' is assigned but its value is never used
Compilation succeeded - 1 warning(s)
Run Code Online (Sandbox Code Playgroud)
现在,如果我尝试运行生成的可执行文件,它将失败:
$ mono foo.exe
$ mono foo.exe
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'MathNet.Numerics, Version=3.20.2.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'MathNet.Numerics, Version=3.20.2.0, Culture=neutral, PublicKeyToken=null'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'MathNet.Numerics, Version=3.20.2.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'MathNet.Numerics, Version=3.20.2.0, Culture=neutral, PublicKeyToken=null'
Run Code Online (Sandbox Code Playgroud)
仅当我将库DLL复制到当前目录时,它才有效:
$ cp MathNet.Numerics.3.20.2/lib/net40/MathNet.Numerics.dll .
$ mono foo.exe
$
Run Code Online (Sandbox Code Playgroud)
所以,是的,我找到了一种使它工作的方法,但是这似乎很尴尬,如果我使用的是NuGet提供的许多不同的库,那就更尴尬了。
所以我一定想念一些东西。我应该使用一些构建系统来使所有这些自动化吗?请注意,我在Linux上,如果可能的话,宁愿留在命令行中,也不愿使用大型的IDE(例如MonoDevelop)。
正是这样的任务就是构建系统的用途 - >要么创建你自己的构建脚本来为你完成工作,要么使用已经实现它们的脚本,就像已经提到的 MonoDevelop 一样。
如果您只想留在控制台上,可以查看 .NET Core,因为有一个命令行构建工具/系统: https: //learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build ?tabs=netcore2x
| 归档时间: |
|
| 查看次数: |
1177 次 |
| 最近记录: |