如何从源代码编译C#项目

时间:2023-01-16 15:43:44

So I mean compile without visual studio

所以我的意思是没有visual studio编译

7 个解决方案

#1


From here:

Compiles File.cs producing File.exe:

编译File.cs生成File.exe:

csc File.cs

Compiles File.cs producing File.dll:

编译File.cs生成File.dll:

csc /target:library File.cs

Compiles File.cs and creates My.exe:

编译File.cs并创建My.exe:

csc /out:My.exe File.cs

Compiles all the C# files in the current directory, with optimizations on and defines the DEBUG symbol. The output is File2.exe:

编译当前目录中的所有C#文件,并启用优化并定义DEBUG符号。输出是File2.exe:

csc /define:DEBUG /optimize /out:File2.exe *.cs

#2


Go to the project directory (I assume .NET framework is in your PATH):

转到项目目录(我假设.NET框架在您的PATH中):

msbuild <enter>

If you want to compile a bunch of C# source files (not in a project), you'd use the csc command. vbc is VB.NET compiler. jsc is JScript.NET compiler. cl is C++/CLI (& plain C++) compiler.

如果要编译一堆C#源文件(不在项目中),则使用csc命令。 vbc是VB.NET编译器。 jsc是JScript.NET编译器。 cl是C ++ / CLI(&plain C ++)编译器。

#3


If you already have a solution or project file, use msbuild tool. You can find it deeply inside folder "%windir%\Microsoft.NET\". For example, on my machine I run the following to compile my project:

如果您已有解决方案或项目文件,请使用msbuild工具。你可以在文件夹“%windir%\ Microsoft.NET \”中找到它。例如,在我的机器上运行以下命令来编译我的项目:

C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe MassiveMultithreading.sln

#4


I created a batch file that i use for this, so I can compile multiple projects in a row. This should help you get in the right direction:

我创建了一个我用于此的批处理文件,因此我可以连续编译多个项目。这应该可以帮助您朝着正确的方向前进:

cls
echo off
c:


cd windows
cd microsoft.net
cd framework
cd v3.5

msbuild c:\Project\Project.sln /t:rebuild /p:Configuration=Debug /p:Platform="any cpu" /clp:Nosummary 

#5


There are currently three ways to compile a C# project. The first is with Visual Studio, but you've stated that VS not installed is a constraint. The second is using the raw .NET SDK tools. The third way is to use Mono.

目前有三种编译C#项目的方法。第一个是使用Visual Studio,但是您已经声明VS未安装是一个约束。第二个是使用原始的.NET SDK工具。第三种方法是使用Mono。

Using msbuild requires Visual Studio to be installed. Using csc does NOT, however it does require the .NET SDK to be installed.

使用msbuild需要安装Visual Studio。使用csc不会,但它确实需要安装.NET SDK。

Using .NET:

  • Compiles File.cs producing File.exe:

    编译File.cs生成File.exe:

    csc File.cs

  • Compiles File.cs producing File.dll:

    编译File.cs生成File.dll:

    csc /target:library File.cs

    csc / target:library File.cs

  • Compiles File.cs and creates My.exe:

    编译File.cs并创建My.exe:

    csc /out:My.exe File.cs

    csc /out:My.exe File.cs

  • Compiles all of the C# files in the current directory, with optimizations on and defines the DEBUG symbol. The output is File2.exe:

    编译当前目录中的所有C#文件,并启用优化并定义DEBUG符号。输出是File2.exe:

    csc /define:DEBUG /optimize /out:File2.exe *.cs

    csc / define:DEBUG / optimize /out:File2.exe * .cs

Using Mono:

  • Compiles File.cs producing File.exe compat with .NET 1.1:

    使用.NET 1.1编译生成File.exe compat的File.cs:

    mcs File.cs

or for .NET 2.0 compatible

或者与.NET 2.0兼容

gmcs File.cs
  • Compiles File.cs producing File.dll:

    编译File.cs生成File.dll:

    msc /target:library File.cs

    msc / target:library File.cs

  • Compiles File.cs and creates My.exe:

    编译File.cs并创建My.exe:

    msc /out:My.exe File.cs

    msc /out:My.exe File.cs

  • Compiles all of the C# files in the current directory, with optimizations on and defines the DEBUG symbol. The output is File2.exe:

    编译当前目录中的所有C#文件,并启用优化并定义DEBUG符号。输出是File2.exe:

    msc /define:DEBUG /optimize /out:File2.exe *.cs

    msc / define:DEBUG / optimize /out:File2.exe * .cs

#6


use command line with csc.exe or msbuild

使用命令行与csc.exe或msbuild

#7


Set your path or change directory to C:\Windows\Microsoft.NET\Framework\v2.0.50727 ( note, if directory if using different framework version ).

设置路径或将目录更改为C:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727(注意,如果目录使用不同的框架版本)。

type:

MSBuild /path/to/your/project/projectname.solution /rebuild

MSBuild /path/to/your/project/projectname.solution / rebuild

Or, using csc from the commandline. Again, switch to the directory mentioned above, this time the command is

或者,使用命令行中的csc。再次,切换到上面提到的目录,这次是命令

csc /out:filename.exe /path/to/your/project/*.cs

csc /out:filename.exe /path/to/your/project/*.cs

Note, CSC.exe has a few hundred operations. Type csc -help for more details.

注意,CSC.exe有几百个操作。键入csc -help以获取更多详细信息。

#1


From here:

Compiles File.cs producing File.exe:

编译File.cs生成File.exe:

csc File.cs

Compiles File.cs producing File.dll:

编译File.cs生成File.dll:

csc /target:library File.cs

Compiles File.cs and creates My.exe:

编译File.cs并创建My.exe:

csc /out:My.exe File.cs

Compiles all the C# files in the current directory, with optimizations on and defines the DEBUG symbol. The output is File2.exe:

编译当前目录中的所有C#文件,并启用优化并定义DEBUG符号。输出是File2.exe:

csc /define:DEBUG /optimize /out:File2.exe *.cs

#2


Go to the project directory (I assume .NET framework is in your PATH):

转到项目目录(我假设.NET框架在您的PATH中):

msbuild <enter>

If you want to compile a bunch of C# source files (not in a project), you'd use the csc command. vbc is VB.NET compiler. jsc is JScript.NET compiler. cl is C++/CLI (& plain C++) compiler.

如果要编译一堆C#源文件(不在项目中),则使用csc命令。 vbc是VB.NET编译器。 jsc是JScript.NET编译器。 cl是C ++ / CLI(&plain C ++)编译器。

#3


If you already have a solution or project file, use msbuild tool. You can find it deeply inside folder "%windir%\Microsoft.NET\". For example, on my machine I run the following to compile my project:

如果您已有解决方案或项目文件,请使用msbuild工具。你可以在文件夹“%windir%\ Microsoft.NET \”中找到它。例如,在我的机器上运行以下命令来编译我的项目:

C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe MassiveMultithreading.sln

#4


I created a batch file that i use for this, so I can compile multiple projects in a row. This should help you get in the right direction:

我创建了一个我用于此的批处理文件,因此我可以连续编译多个项目。这应该可以帮助您朝着正确的方向前进:

cls
echo off
c:


cd windows
cd microsoft.net
cd framework
cd v3.5

msbuild c:\Project\Project.sln /t:rebuild /p:Configuration=Debug /p:Platform="any cpu" /clp:Nosummary 

#5


There are currently three ways to compile a C# project. The first is with Visual Studio, but you've stated that VS not installed is a constraint. The second is using the raw .NET SDK tools. The third way is to use Mono.

目前有三种编译C#项目的方法。第一个是使用Visual Studio,但是您已经声明VS未安装是一个约束。第二个是使用原始的.NET SDK工具。第三种方法是使用Mono。

Using msbuild requires Visual Studio to be installed. Using csc does NOT, however it does require the .NET SDK to be installed.

使用msbuild需要安装Visual Studio。使用csc不会,但它确实需要安装.NET SDK。

Using .NET:

  • Compiles File.cs producing File.exe:

    编译File.cs生成File.exe:

    csc File.cs

  • Compiles File.cs producing File.dll:

    编译File.cs生成File.dll:

    csc /target:library File.cs

    csc / target:library File.cs

  • Compiles File.cs and creates My.exe:

    编译File.cs并创建My.exe:

    csc /out:My.exe File.cs

    csc /out:My.exe File.cs

  • Compiles all of the C# files in the current directory, with optimizations on and defines the DEBUG symbol. The output is File2.exe:

    编译当前目录中的所有C#文件,并启用优化并定义DEBUG符号。输出是File2.exe:

    csc /define:DEBUG /optimize /out:File2.exe *.cs

    csc / define:DEBUG / optimize /out:File2.exe * .cs

Using Mono:

  • Compiles File.cs producing File.exe compat with .NET 1.1:

    使用.NET 1.1编译生成File.exe compat的File.cs:

    mcs File.cs

or for .NET 2.0 compatible

或者与.NET 2.0兼容

gmcs File.cs
  • Compiles File.cs producing File.dll:

    编译File.cs生成File.dll:

    msc /target:library File.cs

    msc / target:library File.cs

  • Compiles File.cs and creates My.exe:

    编译File.cs并创建My.exe:

    msc /out:My.exe File.cs

    msc /out:My.exe File.cs

  • Compiles all of the C# files in the current directory, with optimizations on and defines the DEBUG symbol. The output is File2.exe:

    编译当前目录中的所有C#文件,并启用优化并定义DEBUG符号。输出是File2.exe:

    msc /define:DEBUG /optimize /out:File2.exe *.cs

    msc / define:DEBUG / optimize /out:File2.exe * .cs

#6


use command line with csc.exe or msbuild

使用命令行与csc.exe或msbuild

#7


Set your path or change directory to C:\Windows\Microsoft.NET\Framework\v2.0.50727 ( note, if directory if using different framework version ).

设置路径或将目录更改为C:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727(注意,如果目录使用不同的框架版本)。

type:

MSBuild /path/to/your/project/projectname.solution /rebuild

MSBuild /path/to/your/project/projectname.solution / rebuild

Or, using csc from the commandline. Again, switch to the directory mentioned above, this time the command is

或者,使用命令行中的csc。再次,切换到上面提到的目录,这次是命令

csc /out:filename.exe /path/to/your/project/*.cs

csc /out:filename.exe /path/to/your/project/*.cs

Note, CSC.exe has a few hundred operations. Type csc -help for more details.

注意,CSC.exe有几百个操作。键入csc -help以获取更多详细信息。