mac上c#环境搭建

来源:互联网 发布:iphone音效增强软件 编辑:程序博客网 时间:2024/05/18 10:45

想要开始学习unity游戏开发,看了下,可以用c#也可以用js,但是c#毕竟是主流,于是需要先搭建c#环境。

对于学习一门新的语言,我的做法是通过命令行运行程序,而不是集成环境下的一键搞定。

于是查了下需要安装mono,这套环境可以让我们在其他操作系统平台上运行c#程序,于是我找到官方http://www.mono-project.com/下载了mac平台的安装包。

接着我尝试着写了一个c#的helloworld.cs程序,然后编译运行之。

using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication1{class Program    {static void Main(string[] args){Console.WriteLine("Hello, world!");Console.ReadLine();        }}}

具体操作如下:

csc helloworld.cs

编译成功,生成了一个helloworld.exe。我又找了下需要用mono运行之。

mono helloworld.exe

成功输出Hello,world!

csc顾名思义就是CSharpCompiler的意思,我想深入了解下,于是csc --help,csc -h,我靠都不行,查了下需要csc /help,,,,,

Microsoft (R) Visual C# Compiler version 2.3.1.61919 (57c81319)Copyright (C) Microsoft Corporation. All rights reserved.                              Visual C# Compiler Options                        - OUTPUT FILES - /out:<file>                   Specify output file name (default: base name of file with main class or first file) /target:exe                   Build a console executable (default) (Short form: /t:exe) /target:winexe                Build a Windows executable (Short form: /t:winexe) /target:library               Build a library (Short form: /t:library) /target:module                Build a module that can be added to another assembly (Short form: /t:module) /target:appcontainerexe       Build an Appcontainer executable (Short form: /t:appcontainerexe) /target:winmdobj              Build a Windows Runtime intermediate file that is consumed by WinMDExp (Short form: /t:winmdobj) /doc:<file>                   XML Documentation file to generate /refout:<file>                Reference assembly output to generate /platform:<string>            Limit which platforms this code can run on: x86, Itanium, x64, arm, anycpu32bitpreferred, or anycpu. The default is anycpu.                        - INPUT FILES - /recurse:<wildcard>           Include all files in the current directory and subdirectories according to the wildcard specifications /reference:<alias>=<file>     Reference metadata from the specified assembly file using the given alias (Short form: /r) /reference:<file list>        Reference metadata from the specified assembly files (Short form: /r) /addmodule:<file list>        Link the specified modules into this assembly /link:<file list>             Embed metadata from the specified interop assembly files (Short form: /l) /analyzer:<file list>         Run the analyzers from this assembly (Short form: /a) /additionalfile:<file list>   Additional files that don't directly affect code generation but may be used by analyzers for producing errors or warnings. /embed                        Embed all source files in the PDB. /embed:<file list>            Embed specific files in the PDB                        - RESOURCES - /win32res:<file>              Specify a Win32 resource file (.res) /win32icon:<file>             Use this icon for the output /win32manifest:<file>         Specify a Win32 manifest file (.xml) /nowin32manifest              Do not include the default Win32 manifest /resource:<resinfo>           Embed the specified resource (Short form: /res) /linkresource:<resinfo>       Link the specified resource to this assembly  (Short form: /linkres) Where the resinfo format is <file>[,<string name>[,public|private]]                        - CODE GENERATION - /debug[+|-]                   Emit debugging information /debug:{full|pdbonly|portable|embedded} Specify debugging type ('full' is default, 'portable' is a cross-platform format, 'embedded' is a cross-platform format embedded into the target .dll or .exe) /optimize[+|-]                Enable optimizations (Short form: /o) /deterministic                Produce a deterministic assembly (including module version GUID and timestamp) /refonly                      Produce a reference assembly in place of the main output /instrument:TestCoverage      Produce an assembly instrumented to collect  coverage information /sourcelink:<file>            Source link info to embed into PDB.                        - ERRORS AND WARNINGS - /warnaserror[+|-]             Report all warnings as errors /warnaserror[+|-]:<warn list> Report specific warnings as errors /warn:<n>                     Set warning level (0-4) (Short form: /w) /nowarn:<warn list>           Disable specific warning messages /ruleset:<file>               Specify a ruleset file that disables specific diagnostics. /errorlog:<file>              Specify a file to log all compiler and analyzer diagnostics. /reportanalyzer               Report additional analyzer information, such as execution time.                        - LANGUAGE - /checked[+|-]                 Generate overflow checks /unsafe[+|-]                  Allow 'unsafe' code /define:<symbol list>         Define conditional compilation symbol(s) (Short form: /d) /langversion:<string>         Specify language version mode: ISO-1, ISO-2, 3, 4, 5, 6, 7, 7.1, Default, or Latest                        - SECURITY - /delaysign[+|-]               Delay-sign the assembly using only the public portion of the strong name key /publicsign[+|-]              Public-sign the assembly using only the public portion of the strong name key /keyfile:<file>               Specify a strong name key file /keycontainer:<string>        Specify a strong name key container /highentropyva[+|-]           Enable high-entropy ASLR                        - MISCELLANEOUS - @<file>                       Read response file for more options /help                         Display this usage message (Short form: /?) /nologo                       Suppress compiler copyright message /noconfig                     Do not auto include CSC.RSP file /parallel[+|-]                Concurrent build. /version                      Display the compiler version number and exit.                        - ADVANCED - /baseaddress:<address>        Base address for the library to be built /checksumalgorithm:<alg>      Specify algorithm for calculating source file  checksum stored in PDB. Supported values are: SHA1 (default) or SHA256. /codepage:<n>                 Specify the codepage to use when opening source files /utf8output                   Output compiler messages in UTF-8 encoding /main:<type>                  Specify the type that contains the entry point (ignore all other possible entry points) (Short form: /m) /fullpaths                    Compiler generates fully qualified paths /filealign:<n>                Specify the alignment used for output file sections /pathmap:<K1>=<V1>,<K2>=<V2>,... Specify a mapping for source path names output by the compiler. /pdb:<file>                   Specify debug information file name (default:  output file name with .pdb extension) /errorendlocation             Output line and column of the end location of each error /preferreduilang              Specify the preferred output language name. /nostdlib[+|-]                Do not reference standard library (mscorlib.dll) /subsystemversion:<string>    Specify subsystem version of this assembly /lib:<file list>              Specify additional directories to search in for references /errorreport:<string>         Specify how to handle internal compiler errors: prompt, send, queue, or none. The default is queue. /appconfig:<file>             Specify an application configuration file containing assembly binding settings /moduleassemblyname:<string>  Name of the assembly which this module will be a part of /modulename:<string>          Specify the name of the source module

再看了看mono的帮助

mono --help

Usage is: mono [options] program [program-options]Development:    --aot[=<options>]      Compiles the assembly to native code    --debug[=<options>]    Enable debugging support, use --help-debug for details    --debugger-agent=options Enable the debugger agent    --profile[=profiler]   Runs in profiling mode with the specified profiler module    --trace[=EXPR]         Enable tracing, use --help-trace for details    --jitmap               Output a jit method map to /tmp/perf-PID.map    --help-devel           Shows more options available to developersRuntime:    --config FILE          Loads FILE as the Mono config    --verbose, -v          Increases the verbosity level    --help, -h             Show usage information    --version, -V          Show version information    --runtime=VERSION      Use the VERSION runtime, instead of autodetecting    --optimize=OPT         Turns on or off a specific optimization                           Use --list-opt to get a list of optimizations    --security[=mode]      Turns on the unsupported security manager (off by default)                           mode is one of cas, core-clr, verifiable or validil    --attach=OPTIONS       Pass OPTIONS to the attach agent in the runtime.                           Currently the only supported option is 'disable'.    --llvm, --nollvm       Controls whenever the runtime uses LLVM to compile code.    --gc=[sgen,boehm]      Select SGen or Boehm GC (runs mono or mono-sgen)    --arch=[32,64]         Select architecture (runs mono32 or mono64)    --handlers             Install custom handlers, use --help-handlers for details.    --aot-path=PATH        List of additional directories to search for AOT images.


啊哈,c#环境貌似搞好了,具体的编译和运行参照上面就可以了。

原创粉丝点击