如何将此C#代码作为独立文件(相当于.exe)部署到Mac上?
我需要一个小应用程序,用户可以从网上下载并在Mac上运行。其目的是在本地计算机上的xml文件中设置一个值。(这是针对Parallels的-基本上,脚本将读取其Mac序列号,并将其设置为/users//Parallels/.pvm/config.pvs下虚拟机的序列号。) 我相当擅长在Windows上编程,但对Mac编程不太熟悉。如果我在Windows上这样做,我会编写一个小的C#EXE,用户可以下载并运行它 这是我目前掌握的代码:如何将此C#代码作为独立文件(相当于.exe)部署到Mac上?,c#,macos,xamarin,C#,Macos,Xamarin,我需要一个小应用程序,用户可以从网上下载并在Mac上运行。其目的是在本地计算机上的xml文件中设置一个值。(这是针对Parallels的-基本上,脚本将读取其Mac序列号,并将其设置为/users//Parallels/.pvm/config.pvs下虚拟机的序列号。) 我相当擅长在Windows上编程,但对Mac编程不太熟悉。如果我在Windows上这样做,我会编写一个小的C#EXE,用户可以下载并运行它 这是我目前掌握的代码: string serialNumber; using (var
string serialNumber;
using (var p = new Process())
{
var serialRegex = new Regex("\"IOPlatformSerialNumber\" = \"(\\S+)\"");
p.StartInfo = new ProcessStartInfo("/usr/sbin/ioreg",
"-c IOPlatformExpertDevice");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
serialNumber = serialRegex.Match(p.StandardOutput.ReadToEnd()).Groups[1].Captures[0].Value;
p.WaitForExit();
}
Console.WriteLine("The following Virtual Machines were detected. Please enter the nunber of the Windows installation you plan to use as your Analysys Mason virtual machine.");
var profilePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var parallelsDir = Path.Combine(profilePath, "Parallels");
bool carryOn = false;
int i = 1;
string[] vms = Directory.GetDirectories(parallelsDir, "*.pvm").OrderByDescending(f => f).ToArray();
foreach (var vm in vms)
{
Console.WriteLine(i + ". " + vm.Split('/').Last());
i++;
}
int index = 0;
while (!carryOn) {
Console.WriteLine("Enter the number of the Virtual Machine");
var entry = Console.ReadLine();
Console.WriteLine(Environment.NewLine);
if (Int32.TryParse(entry, out index)) {
if (index > 0 && index <= vms.Length){
carryOn = true;
} else {
Console.WriteLine("Please enter a number of a virtual machine from the list above");
}
} else {
Console.WriteLine("Please enter a valid number");
}
}
Console.WriteLine("You selected: " + vms[index - 1]);
字符串序列号;
使用(var p=new Process())
{
var serialRegex=new Regex(“\”IOPlatformSerialNumber\“=\”(\\S+)”);
p、 StartInfo=newprocessstartinfo(“/usr/sbin/ioreg”,
“-c IOPlatformExpertDevice”);
p、 StartInfo.UseShellExecute=false;
p、 StartInfo.RedirectStandardOutput=true;
p、 Start();
serialNumber=serialRegex.Match(p.StandardOutput.ReadToEnd())。组[1]。捕获[0]。值;
p、 WaitForExit();
}
Console.WriteLine(“检测到以下虚拟机。请输入您计划用作易观梅森虚拟机的Windows安装编号。”);
var profilePath=Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var parallelsDir=Path.Combine(profilePath,“Parallels”);
布尔携带=假;
int i=1;
字符串[]vms=Directory.GetDirectories(parallelsDir,*.pvm”).OrderByDescending(f=>f.ToArray();
foreach(vms中的var-vm)
{
Console.WriteLine(i+“+vm.Split('/').Last());
i++;
}
int指数=0;
而(!carryOn){
Console.WriteLine(“输入虚拟机的编号”);
var entry=Console.ReadLine();
Console.WriteLine(Environment.NewLine);
if(Int32.TryParse(输入,输出索引)){
如果(index>0&&index)您可以运行一个带有.net内核的mac程序,您所需要的只是创建一个自包含的应用程序@Gabriel,该代码可能需要适应core tho,请查看“如何从Visual Studio/Xamarin执行此操作?”中的“.net内核注释”部分除非我错过了最近的新闻,否则看起来像Xamarin.Forms for MAC仍在预览中。@bradbury9-因此,如果我读对了,这意味着虽然我目前只能为Android/iOS制作Xamarin Forms应用程序,但它应该(很快)请允许我也制作一个MacOS应用程序。这些应用程序是可以按照我上面描述的方式部署的,还是需要通过各自的应用程序商店进行部署?不知道,我对Xamarin不太感兴趣