MSBuild 的 Exec 自带有错误和警告的标准格式,按照此格式输出,将被识别为编译错误和编译警告。ui
而格式只是简简单单的 error: 开头或者 warning: 开头。冒号前面也能够加上空格。spa
using System; namespace Walterlv.Demo { internal class Program { private static void Main(string[] args) { Console.WriteLine("warning: 这是一个警告信息。"); Console.WriteLine("error: 这是一个错误信息。"); } } }
对于这样一段在编译期间执行的程序,编译时将显示以下信息,并产生编译错误和编译警告。code
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net47</TargetFramework> <Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Exec Command="$(OutputPath)$(AssemblyName).exe" /> </Target> </Project>
实际上,上面的 warning
、error
只是省略的格式,而完整的部分是这样的:orm
file_path(line_start,column_start,line_end,column_end): error_or_warning key: message
Demo.cs(344,59,344,78): warning CS0067: The event 'WalterlvClass.Foo' is never used.
固然,有可能你只是须要一个 error:
开头或者 warning:
开头的格式,并不但愿真的产生编译错误或者编译警告,那么只须要在执行 Exec
的时候设置 IgnoreStandardErrorWarningFormat="True"
。xml
<Exec IgnoreStandardErrorWarningFormat="True" Command="$(OutputPath)$(AssemblyName).exe" />