编译/中执行命令提示符C#源文件 [英] Compiling/Executing a C# Source File in Command Prompt

查看:139
本文介绍了编译/中执行命令提示符C#源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你怎么编译和从命令提示符窗口中执行一个cs文件?

How do you compile and execute a .cs file from a command-prompt window?

推荐答案

CSC.EXE是包括在.NET Framework中的CSHARP的编译器,可以用来在命令提示符下进行编译。 EXE或DLL中,如果您使用/目标:库如果使用/目标输出可以是一个可执行文件(.exe)。 CSC.EXE是在.NET Framework目录中,
例如,对于.NET 3.5, C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v3.5版本\\

CSC.exe is the CSharp compiler included in the .NET Framework and can be used to compile from the command prompt. The output can be an executable (.exe) if you use /target:exe, or a DLL if you use /target:library. CSC.exe is found in the .NET Framework directory, eg for .NET 3.5, c:\windows\Microsoft.NET\Framework\v3.5\.

要运行它,首先打开一个命令提示符。单击开始......然后键入的cmd.exe 。那么您可能需要cd到保存源文件的目录。

To run it, first open a command prompt. click Start... then type cmd.exe. You may then have to cd into the directory that holds your source files.

运行C#编译器是这样的:

Run the C# compiler like this:

  c:\windows\Microsoft.NET\Framework\v3.5\bin\csc.exe 
            /t:exe /out:MyApplication.exe MyApplication.cs  ...

(全部在一行)

如果您必须编译多个源模块,你可以把它同一个命令行上。如果您有其他程序集参考,使用 /r:AssemblyName.dll

If you have more than one source module to be compiled, you can put it on that same command line. If you have other assemblies to reference, use /r:AssemblyName.dll .

确保你在你的类来充当切入点的一个定义的静态Main()方法。

Ensure you have a static Main() method defined in one of your classes to act as the "entry point".

要运行生成的EXE,只需键入后跟&LT MyApplicaction ;进入> 在命令提示符。

To run the resulting EXE, just type MyApplicaction followed by <ENTER> at the command prompt.

MSDN上的这篇文章进入到上的选项更详细对于命令行编译器。您可以嵌入资源,集图标,标志集 - 你可以在Visual Studio中做的一切。

This article on MSDN goes in to more detail on the options for the command-line compiler. You can embed resources, set icons, sign assemblies - everything you could do within Visual Studio.

如果您已经安装了Visual Studio,在开始菜单(在Visual Studio工具),你可以打开一个Visual Studio命令提示符,将设置所有必需的环境和路径变量的命令行编译。

If you have Visual Studio installed, in the Start menu (under Visual Studio Tools) you can open a "Visual Studio Command Prompt" that will set up all required environment and path variables for command line compilation.

虽然这是非常方便的知道这一点,你应该有一些构建工具的知识结合起来,如,< A HREF =htt​​p://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx> MSBuild的,的FinalBuilder 等,这些工具提供了完整的编译环境,而不仅仅是基本的编译器。

While it's very handy to know of this, you should combine it with knowledge of some sort of build tool such as NAnt, MSBuild, FinalBuilder etc. These tools provide a complete build environment, not just the basic compiler.

这篇关于编译/中执行命令提示符C#源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆