.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可以做到不?或是有没有其它的工具可以呢?
...全文
656 4 打赏 收藏 转发到动态 举报
写回复
用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]

110,502

社区成员

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

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

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