我如何使用cmd编译我的C#progrom [英] How I compile my C# progrom using cmd

查看:83
本文介绍了我如何使用cmd编译我的C#progrom的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我有麻烦我想用命令promt编译我的一个简单的c#程序使用cmd.exe

但问题是c#

的最新版本我是使用Visual Studio 2013 Profssional安装了4.6框架,包括c#版本6

但是每当我尝试使用cmd进行编译时它失败了......我该怎么做请帮帮我



我尝试过:



使用cmd

解决方案 prgram编译/ div>

使用csc.exe进行命令行构建 - MSDN [ ^ ]


首先,对您的软件产品进行一键式完整构建(批量构建)非常重要,特别是当它积极开发和/或进入生产阶段时。



但它与CMD无关。有些人将CMD与使用命令行启动应用程序混淆。不,CMD本身就是一个常规应用程序,与其他任何应用程序都没有区别。它启动一个命令行解释器,它与您的问题无关。许多其他应用程序可以通过命令行启动进程,包括您可以开发的进程。你真正需要的是一键式对象:你点击它,它构建所有项目而不必加载Visual Studio,就是这样。这种文件的适当形式可以是批处理类型之一的批处理文件:.bat,.WSF,.ps1(最好与.lnk一起使用),。lnk ...因为这个目的所需的脚本非常简单(见下文);所有的复杂性都隐藏在你的解决方案和项目文件中,我甚至不考虑编写这样的脚本作为编程技巧的技巧;它更接近高级用户的水平。



你可以构建(这是比编译更精确的表达,因为构建是你真正做的,它可以包括编译和更多步骤)您的项目在不同级别:通过使用单独的源代码文件(请参阅解决方案2),按项目,通过解决方案。



最多通用方法是使用MSBuild构建整个解决方案,MSBuild是使用标准化项目文件格式的标准化工具。 (您可以编写自定义任务,自定义项目类型,调整自己的编程语言等。)您还可以使用MSBuild构建一个单独的项目,在您的情况下,将创建一个输出目录并输出构建工件,对应于单个输出组件。



MSBuild是Visual Studio实际使用的。请参阅:

MSBuild [ ^ ],

MSBuild Reference [ ^ ]。



但此时你只需要MSBuild命令行:< a href =https://msdn.microsoft.com/en-us/library/ms164311.aspx> MSBuild命令行参考 [ ^ ]。



首先,你需要找到MSBuild.EXE文件并写入其完整路径名。这是简单批处理的示例:

 set build =%windir%\ ... full-path-name ...... ... \ MSBuild。 exe 
%build%mySolution.sln



这是一个更复杂的例子,用两个配置Debug,然后Release构建相同的产品;每个项目都规定了输出目录:

 set build =%windir%\ ... full-path-name ...... ... \ MSBuild .exe 
set solution = mySolution.sln

%build %% solution%/ p:Configuration = Debug
%build %% solution%/ p:Configuration = Release



-SA


从命令提示符编译并运行

粘贴将上述过程中的代码放入任何文本编辑器,然后将该文件另存为文本文件。 ...

执行以下步骤之一打开命令提示符窗口:...

在命令提示符窗口中,导航到包含您的文件夹Hello.cs文件。


Hello i m in trouble i want to compile my a simple c# program from command promt using cmd.exe
but the problem is the latest versio of c#
I am Using Visual Studio 2013 Profssional installed 4.6 framework including c# version 6
but whenever i try to compile using cmd its failed..what should i Do Please Help Me

What I have tried:

trying c# prgram compilation using cmd

解决方案

Command-line Building With csc.exe - MSDN[^]


First of all, it's very important to have one-click full build (batch build) of your software product, especially when it is actively develop and/or enter the phase of production.

But it has nothing to do with "CMD". Some confuse CMD with starting application with a command line. No, CMD is a regular application itself, no different from any other. It starts a command-line interpreter, which is irrelevant to your problem. Many other application can start a process via a command line, including the one you can develop. What you really need is one-click object: you click on it, and it build all the project without having to load Visual Studio, that's it. The adequate form of such file could be a batch file of one of the batch types: .bat, .WSF, .ps1 (should better be used with .lnk), .lnk… As the script you would need for this purpose is very simple (see below); all complexity is hidden in your solution and project files, I don't even consider the skills of writing such scripts as programming skills; it's closer to the level of "advanced user".

You can build (this is more precise expression than "compile", because build is what you really do, it can include compilation and many more steps) your project on different levels: by using separate source code files (see Solution 2), by project, by solution.

The most universal approach is the build of whole solution using MSBuild, which is standardized tool using standardized project file format. (You can write custom tasks, custom project types, adapt your own programming languages, and so on.) You can also use MSBuild to build a separate project, which, in your case, will create an output directory and output the build artifact which corresponds to a single output assembly.

MSBuild is what Visual Studio actually use. Please see:
MSBuild[^],
MSBuild Reference[^].

But at this moment you only need MSBuild command line: MSBuild Command-Line Reference[^].

First, you need to locate the MSBuild.EXE file and write its full path name. This is the example of simple batch:

set build=%windir%\...full-path-name... ...\MSBuild.exe
%build% mySolution.sln


This is a bit more complex example to build the same product in two configurations "Debug", and then "Release"; the output directories are prescribed in each project:

set build=%windir%\...full-path-name... ...\MSBuild.exe
set solution=mySolution.sln

%build% %solution% /p:Configuration=Debug
%build% %solution% /p:Configuration=Release


—SA


To compile and run from a command prompt
Paste the code from the preceding procedure into any text editor, and then save the file as a text file. ...
Perform one of the following steps to open a command-prompt window: ...
In the command-prompt window, navigate to the folder that contains your Hello.cs file.


这篇关于我如何使用cmd编译我的C#progrom的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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