0
我创建了一个可执行文件,它在构建完成后对构件执行操作。Visual Studio中的详细构建事件错误处理
我希望此可执行文件在每次构建程序集时运行,以便它立即可以使用。为了做到这一点,我打开Visual Studio中的组件的Properties
(在项目上单击右键,选择Properties
),去Build Events
选项卡,并输入以下的地方说:Post-build event command line
:
C:\MyExePath\MyAssemblyManager.exe C:\MyProjectPath\obj\Release\MyProject.dll
而且每事情是应该的。每次构建项目时,可执行文件都会运行,并且程序集已准备就绪。
但这里是我的问题:说我有一些错误在我的可执行文件处理:
static void Main(string[] args)
{
try
{
string assemblyPath = args[0];
if (!System.IO.File.Exists(assemblyPath))
{
throw new System.IO.FileNotFoundException(String.Format("Path {0} is invalid.", assemblyPath);
}
// ...
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
Environment.Exit(9000);
}
}
如果可执行文件会出现此错误,则显示在Error List
标签Visual Studio中的以下内容:
The command C:\MyExePath\MyAssemblyManager.exe C:\MyAssemblyPath\MyAssembly.dll exited with error code 9000.
有没有办法通过可执行文件中的字符串传递错误消息,该消息可以显示在Visual Studio错误列表中而不是通用错误代码消息中?