如何更改 MSBuild 任务的详细程度?
我希望从命令行调用的 msbuild 项目和从项目内的 MSBuild 任务调用的项目具有不同的详细程度。例如:
在 my.proj 内部:
<Target Name=Foo>
<MSBuild Projects="a.csproj;b.csproj;c.csproj"/>
</Target>
在命令行上:
msbuild /v:d my.proj
现在,当 MSBuild 任务生成 .csproj 文件时,它也会详细地执行此操作。不过我想用最少的冗长来构建它。
我知道可以像这样手动调用 msbuild:
<Target Name=Foo>
<Exec Command="msbuild /v:m a.csproj"/>
<Exec Command="msbuild /v:m b.csproj"/>
<Exec Command="msbuild /v:m c.csproj"/>
</Target>
或者在实践中
<Target Name=Foo>
<Exec Command="msbuild /v:m %(Projectlist.Identity)"/>
</Target>
,这当然工作得很好,但是我无法再获得 BuildInParallel
开关的功能(我认为不可能从命令行调用带有多个项目的 msbuild,而不将它们包含在解决方案中?)
更新
我选择了 Ludwo 的选项:基本上创建一个自定义记录器,其中包含两个 ConsoleLoggers 作为成员。一种是在命令行中传递的详细信息,另一种是“最小”的。记录器注册所有事件,并将它们传递给其中一个记录器,具体取决于当前是否正在构建 csproj 文件。输出看起来与正常情况完全一样,只是它不包含 csproj 文件中的数千行。
I'd like to have a different verbosity for the msbuild project invoked from the commandline, and those invoked by the MSBuild task from within the project. For example:
Inside my.proj:
<Target Name=Foo>
<MSBuild Projects="a.csproj;b.csproj;c.csproj"/>
</Target>
On the commandline:
msbuild /v:d my.proj
now when the MSBuild task builds the .csproj files, it does it with detailed verbosity as well. However I'd want to build it with minimal verbosity.
I know it is possible to invoke msbuild manually like so:
<Target Name=Foo>
<Exec Command="msbuild /v:m a.csproj"/>
<Exec Command="msbuild /v:m b.csproj"/>
<Exec Command="msbuild /v:m c.csproj"/>
</Target>
or in practice
<Target Name=Foo>
<Exec Command="msbuild /v:m %(Projectlist.Identity)"/>
</Target>
and this works well off course, but then I cannot get the functionality of the BuildInParallel
switch anymore (I do not think it is possible to invoke msbuild from the commandline with multiple projects without them being contained in a solution?)
Update
I went with Ludwo's option: basically create a custom logger that holds two ConsoleLoggers as a member. One has the verbosity passed at command line, the other one is 'minimal'. The logger registers for all events and passes them to one of the loggers depending on whether a csproj file is currently being built or not. Output looks exactly like normal, except it doesn't include thousands of lines from the csproj files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您(至少)有两个选择:)
创建一个额外的 msbuild 脚本来构建 abc 项目
“BuildABC.proj”
在您的父脚本中使用 Exec 任务执行 MSBuild 并调用
简洁的“BuildABC.proj”
您必须将 BuildABC 项目中所需的所有父属性显式传递给 msbuild /p 参数。
使用自定义记录器。 查看操作方法。在这种情况下,您可以使用原始脚本:
在您的自定义记录器中,不要在 ProjectStarted 和 ProjectFinished 事件之间记录与“a.csproj”项目相关的任何内容,其中 e.ProjectFile ==“a.csproj”(以在构建时禁用“a.csproj”项目上的诊断日志记录)具有诊断详细信息的父项目)
You have two options (at least) :)
Create one additional msbuild script for building abc projects
"BuildABC.proj"
In your parent script execute MSBuild using Exec task and call
"BuildABC.proj" with minimal verbosity
You have to pass explicitly all parent properties needed in the BuildABC project to msbuild /p parameter.
Use custom logger. See this how to do it. In this case you can use your original script:
In your custom logger do not log anything related to e.g. "a.csproj" project between ProjectStarted and ProjectFinished events where e.ProjectFile == "a.csproj" (to disable diagnostic logging on "a.csproj" project while building parent project with diagnostic verbosity)