How to copy the build logs (including build time ) using the post-build events to a log file from Visual studio
Asked
Active
Viewed 355 times
1 Answers
0
Based on my research, I find that there is no way to access build logs in a post build event. You can look at the link How to access build warnings in a post-build event in Visual Studio?
However, there is a workaround to use msbuild command to generate a log file.
Example: (Use the msbuild in the post-build event)
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe" "C:\Users\username\source\repos\ConsoleApp1\ConsoleApp1.csproj" -fileLogger
It will generate a log file named msbuild.log.
Also, you can know more about it from the link Obtain build logs with MSBuild.

Jack J Jun
- 5,633
- 1
- 9
- 27
-
I have a requirement like on visual studio build the console build logs should be write to a file so that can extract few details from the log for data processing. Is there any way other than post build to do so. It specifically needs it from visual studio IDE (Apart of manually saving) – Deepak Suresh Apr 19 '21 at 11:42
-
@DeepakSuresh, I am not full understand your meaning. If you don't want to use post build to get the log, you can try the method I provided about msbuild. – Jack J Jun Apr 21 '21 at 01:58
-
Thanks, Jack for the response, What my intention behind this is, From the Visual studio code build completion, I need to save the console build logs to a local file in the directory without manually saving it each time. I was thinking in the post-build event i could able to get the control over the console to save the logs. – Deepak Suresh Apr 23 '21 at 05:57
-
@Deepak Suresh, based on further test, I find that I can run the MSbuild command in the post build event. But I will get error that Failed to write to log file. I find that it is accessing the csproj file. So the access is denied. We only use the post command in the other project to get the current project build logs. – Jack J Jun Apr 26 '21 at 08:03