【发布时间】:2018-07-28 06:02:16
【问题描述】:
我来frompowershellMono:
thufir@dur:~/mono$
thufir@dur:~/mono$ ls
hello.cs
thufir@dur:~/mono$
thufir@dur:~/mono$ cat hello.cs
using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}
}
thufir@dur:~/mono$
thufir@dur:~/mono$ mcs hello.cs
thufir@dur:~/mono$
thufir@dur:~/mono$ mono hello.exe
Hello Mono World
thufir@dur:~/mono$
thufir@dur:~/mono$ dotnet --version
2.1.4
thufir@dur:~/mono$
thufir@dur:~/mono$ lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 17.10
Release: 17.10
Codename: artful
thufir@dur:~/mono$
我想做这样的事情powershell one-liner:
Resolve-DnsName -Name localhost -Type ANY | Format-Table -AutoSize
但来自Mono。到目前为止,这里是what I have:
thufir@dur:~/mono$
thufir@dur:~/mono$ ls
dns.cs hello.cs
thufir@dur:~/mono$
thufir@dur:~/mono$ mcs dns.cs
dns.cs(10,35): error CS0117: `Dns' does not contain a definition for `GetHostEntry'
dns.cs(5,14): (Location of the symbol related to previous error)
dns.cs(11,28): error CS0118: `System.Net.IPAddress' is a `type' but a `variable' was expected
dns.cs(11,28): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Compilation failed: 3 error(s), 0 warnings
thufir@dur:~/mono$
thufir@dur:~/mono$ cat dns.cs
using System.Net.Sockets;
using System.Net;
using System;
public class Dns
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
Console.WriteLine (IPAddress);
}
}
thufir@dur:~/mono$
我有dotnet 的正确版本吗?导入是否正确?
我没有使用正确的类型正确声明和实例化 ipaddress 变量吗?
【问题讨论】:
-
您只是错过了程序集引用,因为
System.Net.Dns存在于另一个程序集中,您需要通过参数将其传递给mcs。了解mcs手册页以获取更多信息。如果您真的在学习如何使用 C# 编程,请放弃原始的mcs方法。大多数人使用项目 (.csproj) 和 MSBuild 来编写 C# 程序。
标签: linux powershell syntax mono .net-core