是否可以在没有 Visual Studio 的情况下安装 C# 编译器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/861384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:38:06  来源:igfitidea点击:

Is it possible to install a C# compiler without Visual Studio?

c#compiler-constructionmsbuildcsc

提问by Pavel Bastov

I want to build projects from the command line. Is it possible to deploy a C# compiler without installing Visual Studio?

我想从命令行构建项目。是否可以在不安装Visual Studio 的情况下部署 C# 编译器?

采纳答案by lc.

Sure, the framework includes a compiler, csc.exe. Look at this articlefor a quick how-to. The important parts:

当然,该框架包含一个编译器 csc.exe。查看这篇文章以获取快速操作方法。重要部分:

You can get the command-line compiler (csc.exe) from Microsoft site http://msdn2.microsoft.com/en-us/netframework/aa731542.aspx.

Download the redistributable package of the .NET Framework, which includes the compiler and the .NET Framework with C# 2005 syntax support.

The compiler is located in the following directory: %windir%\Microsoft.NET\Framework\

您可以从 Microsoft 站点http://msdn2.microsoft.com/en-us/netframework/aa731542.aspx获取命令行编译器 (csc.exe) 。

下载 .NET Framework 的可再发行包,其中包括编译器和支持 C# 2005 语法的 .NET Framework。

编译器位于以下目录:%windir%\Microsoft.NET\Framework\

Also look at this MSDN articlefor a full guide and explanation.

另请查看此 MSDN 文章以获取完整指南和解释。

Note that for more recent versions, you will be looking for the MSBuild standalone package rather than the framework -- see @Vadzim's answer.

请注意,对于较新的版本,您将寻找 MSBuild 独立包而不是框架 - 请参阅@Vadzim 的回答

回答by Brian

Yes, if you have the .NET SDK, it's there. For example,

是的,如果您有.NET SDK,它就在那里。例如,

C:\WINDOWS\Microsoft.NET\Framework\v[your version number]\csc.exe

msbuild.exeshould be there too, and you can use that to build project (.csproj) files.

msbuild.exe也应该在那里,您可以使用它来构建项目 ( .csproj) 文件。

回答by Vadim

Yes, but you need to download and install .NET Framework SDK.

可以,但您需要下载并安装.NET Framework SDK

Here's a linkthat can help you.

这是一个可以帮助您的链接

回答by MRFerocius

You only need the .NET framework. You can use Notepadto edit and the CSC.exe to compile.

您只需要 .NET 框架。可以使用记事本编辑,CSC.exe 编译。

回答by Matthew Flaschen

Of course. Do:

当然。做:

sudo apt-get install mono-gmcs

Everyone else assumed Windows and MS .NET, but...

其他人都假设 Windows 和 MS .NET,但是......

回答by Dan

Yes, there is even an open source one, IDE SharpDevelop. You can set the compiler as a command in UltraEdit(or some other editor of preference), etc.

是的,甚至还有一个开源的IDE SharpDevelop。您可以将编译器设置为UltraEdit(或其他首选编辑器)等中的命令。

回答by bsneeze

Contrary to what some of the other answerers say, you do NOT need the SDK, just the .NET Framework to get the C# compiler, csc.exe.

与其他一些回答者所说的相反,您不需要 SDK,只需要 .NET Framework 即可获得 C# 编译器、csc.exe.

Also, consider other (free) IDEs like MonoDevelop, #develop, and Visual C# Express. (You said you don't want Visual Studio, not that you don't want an IDE at all ;) )

此外,请考虑其他(免费)IDE,如MonoDevelop#developVisual C# Express。(你说你不需要 Visual Studio,并不是说你根本不需要 IDE ;))

回答by Sayed Ibrahim Hashimi

Like some others have mentioned MSBuildis deployed with the .NET Framework (versions 2.0 and 3.5) so if you have either of those installed you can build your applications without needing Visual Studio installed on the machine.

就像其他人提到的那样,MSBuild是使用 .NET Framework(版本 2.0 和 3.5)部署的,因此如果您安装了其中任何一个,您就可以构建应用程序,而无需在机器上安装 Visual Studio。

Sayed Ibrahim Hashimi

赛义德·易卜拉欣·哈希米

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

我的书:Microsoft Build Engine 内部:使用 MSBuild 和 Team Foundation Build

回答by Carlos F

I was just looking for a solution like this so that I could just make small console applications using C#.

我只是在寻找这样的解决方案,以便我可以使用 C# 制作小型控制台应用程序。

The method that worked for me was mentioned by Brian, all I did was, after creating my file to simply do:

布赖恩提到了对我有用的方法,我所做的只是在创建文件后简单地执行以下操作:

C:\WINDOWS\Microsoft.NET\Framework\v[your version number]\csc.exe myfile.cs

and it will generate your .exe file that you can then use :)

它将生成您可以使用的 .exe 文件:)

回答by Vadzim

Latest Microsoft .NET Framework 4.7doesn't include C# compiler anymore.

最新的Microsoft .NET Framework 4.7不再包含 C# 编译器。

But it can be installed as part of standalone MSBuildtool.

但它可以作为独立MSBuild工具的一部分安装。

Go to https://www.visualstudio.com/downloads/, scroll down to "Other Tools and Frameworks" and choose "Build Tools for Visual Studio 2017".

转到https://www.visualstudio.com/downloads/,向下滚动到“其他工具和框架”并选择“Visual Studio 2017 的构建工具”。

After "Visual Studio Build Tools 2017" Online Installer runs, switch to "Individual components" tab and check "C# and Visual Basic Roslyn compilers". This would also check MSBuild dependency. All together less than a hundred of megabytes.

运行“Visual Studio Build Tools 2017”在线安装程序后,切换到“独立组件”选项卡并选中“C# 和 Visual Basic Roslyn 编译器”。这也将检查 MSBuild 依赖项。总共不到一百兆字节。

The compiler installs at C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn\csc.exe.

编译器安装在C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn\csc.exe.