Open samsnowy opened 5 years ago
I have this problem too. I created a ticket in the Visual Studio tracker but haven't header much: https://developercommunity.visualstudio.com/content/problem/478625/i-cant-use-a-custom-msbuild-logger-from-visual-stu.html
There's still no way to do this built into VS. The Project System Tools extension allows you to capture binary logs of builds in VS, which can then be replayed throuh your custom logger (but doesn't allow hooking a custom logger directly in AFAIK).
One problem with trying to do this is that there are many subsystems of VS that can trigger a build: a project is owned by a "project system" which may be independently implemented, or use a library to abstract away some details. In order to intercept all calls to MSBuild, you'd have to plug into every project system (C#/VB/F#, the older C# implementation csproj.dll
, C++, etc.). That's not easy, so I don't forsee this coming as a general VS feature.
I have discovered through experimentation that MSBuild opens the MSBuild.rsp file (but not the Directory.Build.rsp file) when it starts a build from Visual Studio but doesn't seem to take any arguments from there. Could that mechanism be used for this, assuming it can be made to work?
No, I wouldn't expect that to work. I'm surprised we're even touching the file; that seems like a bug to me.
This would be an incredibly useful feature for me, even if it was only available for C++ projects. It is 95% working, would it really be so much work to make it usable from within VS?
I'd be happy with being able to register a logger for VS builds using a VS extension. If MSBuild could take loggers from ProjectCollection.GlobalProjectCollection.Loggers, that would solve the problem. @samsnowy What is your use-case? Which project system would you need integration with?
@rebnridgway, we want to get some telemetry from local developers who uses VS as their build system instead of command line. Stuff like most commonly built project/target, build time, etc.
One way forward where I am experimenting with is the same way that project system tools is doing: Basically I'm creating a custom VS extension with a class that implements IVsBuildLoggerProvider. Then we export this interface and the VS build will pick this up as a logger.
Edit: We only care about C# projects, which probably made our use case easier.
@samsnowy , have your tried creating logger implementing IBuildLoggerProviderAsync? Take a look at this extension: https://github.com/dotnet/project-system-tools
Any update on this issue? This seems important to gather telemetry on build issues. I'm interested in getting data for, local build failures, time to build, etc.
As far as I can tell Microsoft have no interest in adding this feature. I hacked around it by creating an MSBuild target that runs as early as possible and calls a custom task to attach a custom logger, it's not perfect because you miss the opening milliseconds and first few lines of output but it was good enough for my purposes. I'm just praying Microsoft don't 'fix' my workaround :)
Can you elaborate on how you attached the custom logger? How to you configure the custom logger? I can't seem to have access to the buildengine api to register it
We've created a custom build logger and attached it to the build with the "-logger" switch and it worked great for command line builds. (Docs were awesome: https://docs.microsoft.com/en-us/visualstudio/msbuild/build-loggers?view=vs-2017)
However, we're can't find a way to attach the custom logger for Visual Studio builds which also uses MSBuild. The only method mentioned online is a hack that overrides the Build target: https://stackoverflow.com/questions/28733875/can-a-msbuild-custom-logger-be-specified-within-a-project-file/28806181#28806181
I was wondering if there is any changes in VS 2017 or MSBuild that allows custom build loggers to be attached to VS builds. If there isn't any, are there any plans to enable them for VS in the future?