.Net 的csc.exe文件可以对.cs文件编译,那怎么对整个.sln,即整个解决方案都编译一下呢?

Jave.Lin 2009-12-14 10:37:33
.Net 的csc.exe文件可以对.cs文件编译,那怎么对整个.sln,即整个解决方案都编译一下呢?

如上面/题目内容。

因为我想写个小程序。通过调用.Net 的编译器去编绎我整个.sln所对应的所有相关文件,资源,等等的信息,都一起编译,就像我们在VS里打开了项目后,选择了:生成解决方案,或是/重新生成解决方案,的效果,设置项目生成的顺序,并可以指定一些相应的生成属性设置(就是右键项目->属性->生成标签里对应的设置内容),通过这些设置后,就在对应的输出目录下生成(Debug/Release):.exe。

总之,就是写一个小软件,可以实现VS里的"生成解方案"(就是快捷键F6的功能)的效果。

csc.exe可以做到不?或是有没有其它的工具可以呢?
...全文
745 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jave.Lin 2009-12-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dobzhansky 的回复:]
msbuild 就是用来干这个的

使用 vs 命令行即可使用, 也可以自己设置环境变量, 能找到 msbuild.exe 即可

msbuild solutionfilename.sln

引用
Microsoft (R) Build Engine Version 2.0.50727.3053
[Microsoft .NET Framework, Version 2.0.50727.3053]
Copyright (C) Microsoft Corporation 2005. All rights reserved.

Syntax:              MSBuild.exe [options] [project file]

Description:        Builds the specified targets in the project file. If
                    a project file is not specified, MSBuild searches the
                    current working directory for a file that has a file
                    extension that ends in "proj" and uses that file.

Switches:

  /help              Display this usage message. (Short form: /? or /h)

  /nologo            Do not display the startup banner and copyright message.

  /version          Display version information only. (Short form: /ver)

  @ <file>            Insert command-line settings from a text file. To specify
                    multiple response files, specify each response file
                    separately.

  /noautoresponse    Do not auto-include the MSBuild.rsp file. (Short form:
                    /noautorsp)

  /target: <targets>  Build these targets in this project. Use a semicolon or a
                    comma to separate multiple targets, or specify each
                    target separately. (Short form: /t)
                    Example:
                      /target:Resources;Compile

  /property: <n>= <v>  Set or override these project-level properties. <n> is
                    the property name, and <v> is the property value. Use a
                    semicolon or a comma to separate multiple properties, or
                    specify each property separately. (Short form: /p)
                    Example:
                      /property:WarningLevel=2;OutDir=bin\Debug\

  /logger: <logger>  Use this logger to log events from MSBuild. To specify
                    multiple loggers, specify each logger separately.
                    The <logger> syntax is:
                        [ <logger class>,] <logger assembly>[; <logger parameters>]
                    The <logger class> syntax is:
                        [ <partial or full namespace>.] <logger class name>
                    The <logger assembly> syntax is:
                        { <assembly name>[, <strong name>] | <assembly file>}
                    The <logger parameters> are optional, and are passed
                    to the logger exactly as you typed them. (Short form: /l)
                    Examples:
                      /logger:XMLLogger,MyLogger,Version=1.0.2,Culture=neutral
                      /logger:XMLLogger,C:\Loggers\MyLogger.dll;OutputAsHTML

  /verbosity: <level> Display this amount of information in the event log.
                    The available verbosity levels are: q[uiet], m[inimal],
                    n[ormal], d[etailed], and diag[nostic]. (Short form: /v)
                    Example:
                      /verbosity:quiet

  /consoleloggerparameters: <parameters>
                    Parameters to console logger. (Short form: /clp)
                    The available parameters are:
                        PerformanceSummary--show time spent in tasks, targets
                            and projects.
                        NoSummary--don't show error and warning summary at the
                            end.
                        NoItemAndPropertyList--don't show list of items and
                            properties at the start of each project build.                         
                    Example:
                        /consoleloggerparameters:PerformanceSummary;NoSummary

  /noconsolelogger  Disable the default console logger and do not log events
                    to the console. (Short form: /noconlog)

  /validate          Validate the project against the default schema. (Short
                    form: /val)

  /validate: <schema> Validate the project against the specified schema. (Short
                    form: /val)
                    Example:
                      /validate:MyExtendedBuildSchema.xsd

Examples:

        MSBuild MyApp.sln /t:Rebuild /p:Configuration=Release
        MSBuild MyApp.csproj /t:Clean /p:Configuration=Debug


[/Quote]

先谢谢,虽然我现在用不上,但准备要用上。

还是全英文的说明使用呢,看来又要词典翻统了。

到时看看还有其它什么问题没有。
xiangxiao_bobo 2009-12-14
  • 打赏
  • 举报
回复
学习了!~~~
Dobzhansky 2009-12-14
  • 打赏
  • 举报
回复
另外, 如果你愿意, 也可以自己写程序来编译工程.

看看 MSDN 中以下几个名字空间, 再搜索一下就够用拉.

using Microsoft.Build.Framework;
using Microsoft.Build.BuildEngine;
using Microsoft.Build.Utilities;

Dobzhansky 2009-12-14
  • 打赏
  • 举报
回复
msbuild 就是用来干这个的

使用 vs 命令行即可使用, 也可以自己设置环境变量, 能找到 msbuild.exe 即可

msbuild solutionfilename.sln

[Quote]
Microsoft (R) Build Engine Version 2.0.50727.3053
[Microsoft .NET Framework, Version 2.0.50727.3053]
Copyright (C) Microsoft Corporation 2005. All rights reserved.

Syntax: MSBuild.exe [options] [project file]

Description: Builds the specified targets in the project file. If
a project file is not specified, MSBuild searches the
current working directory for a file that has a file
extension that ends in "proj" and uses that file.

Switches:

/help Display this usage message. (Short form: /? or /h)

/nologo Do not display the startup banner and copyright message.

/version Display version information only. (Short form: /ver)

@<file> Insert command-line settings from a text file. To specify
multiple response files, specify each response file
separately.

/noautoresponse Do not auto-include the MSBuild.rsp file. (Short form:
/noautorsp)

/target:<targets> Build these targets in this project. Use a semicolon or a
comma to separate multiple targets, or specify each
target separately. (Short form: /t)
Example:
/target:Resources;Compile

/property:<n>=<v> Set or override these project-level properties. <n> is
the property name, and <v> is the property value. Use a
semicolon or a comma to separate multiple properties, or
specify each property separately. (Short form: /p)
Example:
/property:WarningLevel=2;OutDir=bin\Debug\

/logger:<logger> Use this logger to log events from MSBuild. To specify
multiple loggers, specify each logger separately.
The <logger> syntax is:
[<logger class>,]<logger assembly>[;<logger parameters>]
The <logger class> syntax is:
[<partial or full namespace>.]<logger class name>
The <logger assembly> syntax is:
{<assembly name>[,<strong name>] | <assembly file>}
The <logger parameters> are optional, and are passed
to the logger exactly as you typed them. (Short form: /l)
Examples:
/logger:XMLLogger,MyLogger,Version=1.0.2,Culture=neutral
/logger:XMLLogger,C:\Loggers\MyLogger.dll;OutputAsHTML

/verbosity:<level> Display this amount of information in the event log.
The available verbosity levels are: q[uiet], m[inimal],
n[ormal], d[etailed], and diag[nostic]. (Short form: /v)
Example:
/verbosity:quiet

/consoleloggerparameters:<parameters>
Parameters to console logger. (Short form: /clp)
The available parameters are:
PerformanceSummary--show time spent in tasks, targets
and projects.
NoSummary--don't show error and warning summary at the
end.
NoItemAndPropertyList--don't show list of items and
properties at the start of each project build.
Example:
/consoleloggerparameters:PerformanceSummary;NoSummary

/noconsolelogger Disable the default console logger and do not log events
to the console. (Short form: /noconlog)

/validate Validate the project against the default schema. (Short
form: /val)

/validate:<schema> Validate the project against the specified schema. (Short
form: /val)
Example:
/validate:MyExtendedBuildSchema.xsd

Examples:

MSBuild MyApp.sln /t:Rebuild /p:Configuration=Release
MSBuild MyApp.csproj /t:Clean /p:Configuration=Debug

[/Quote]
资源下载链接为: https://pan.quark.cn/s/9e7ef05254f8 在 IT 领域,C# 是一种极为重要的编程语言,尤其在开发 Windows 桌面应用程序时占据着核心地位。当一个 C# 项目开发完成,通常需要将其打包成一个 .exe 可执行文件,以便用户无需安装复杂的开发环境就能直接运行。这背后涉及编译、构建以及部署等关键环节。 C# 程序的编译过程是整个打包流程的基础。C# 的源代码文件(.cs)首先通过 Microsoft 提供的 C# 编译器(csc.exe)被转换为中间语言(IL)。随后,借助 .NET 框架的 Just-In-Time(JIT)编译器,IL 被进一步编译成机器码,从而让程序能够在目标平台上顺利运行。不过,为了方便分发和使用,我们一般会将程序及其所有依赖文件和程序集整合到一个单独的 .exe 文件中。 目前,C# 打包成 .exe 文件的工具多种多样。其中,Visual Studio IDE 自带的发布功能是最常用的一种。在项目属性的“发布”选项卡中,可以配置各种发布选项,例如单文件发布功能,它能够将所有必要的文件(如 DLLs 和配置文件)都打包到一个 .exe 文件里。此外,还有一些第三方工具可供选择。比如 ILMerge,它可以将多个 .NET 程序集合并到一个文件中,包括主程序及其依赖项。另外,像 NSIS(Nullsoft Scriptable Install System)或 Inno Setup 这样的安装脚本生成器也非常实用。它们不仅能创建 .exe 安装程序,还能处理文件复制、注册表操作等复杂任务,为软件部署提供更专业的解决方案。 在一些压缩包中,可能会包含“C# 打包成 exe 文件”的示例项目。这些示例项目通常包含项目的解决方案文件(.sln)、项目文件(.csproj)、源代码文件(.cs)以及相关的资

111,112

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧