Listen to build solution event in Rider
Answered
The Rider plugin I am working on needs to run code when the “build solution” starts, succeeds and fails. I tried implementing ProjectTaskListener to override the methods started and finished and use the result variable to know if the build failed or not, but while this works on IntelliJ IDEA, it did not work on Rider as ProjectTaskListener is not called. What listener to use instead? There are hundreds of extensions points and listeners in https://plugins.jetbrains.com/docs/intellij/intellij-platform-extension-point-list.html and every open source plugin I saw that did the same thing used ProjectTaskListener which is not called in Rider during the build solution event.
Please sign in to leave a comment.
Implement something like this:
and then register in your
plugin.xml
like this:The
buildSession
object has properties such asresult
that you may subscribe and analyze.“SolutionExtListener” is not found in my code, I basically simply created a new “IDE Plugin” project in IntelliJ IDEA with no additional setup, and this extension point “rd.solutionExtListener” is also sending errors of not found.
What version of Rider SDK do you use?
I am using Rider 2024.1.1, I do not know about any Rider SDK, I opened Intellij IDEA 2024.1, clicked on new “IDE Plugin” and that is it.
If you want to use Rider API, you are supposed to use Rider SDK. Take a look at the plugin template.
(Actually, it's the same process as for all the other IntelliJ-based IDEs: you set up the product name in your Gradle settings, and the APIs are available.)
Alright I set up the Rider SDK and now it is working the code you sent above.
How to subscribe to the buildSession.result to receive the compile start, compile success and compile fail events?
Try this:
Note that this event will be delivered asynchronously. Also, it may also be emitted on certain other operations, such as NuGet restore and publish/deployment.
If you are only interested in actual build operations, add a check for
buildSession.operation is BuildTarget
.Great, my plugin is working exactly as I wanted, all I wanted is to play sounds during these events as I like to hear feedback from the compilation progress, amazing support.
Although the documentation leaves a lot to be desired, I was able to create this plugin in about 3 hours for Visual Studio but it took me days to create the same thing for Rider due to the extreme amount of noise I found in the process and the result was just 46 lines of code, if you did not tell me about this very obscure “SolutionExtListener<BuildModel>” I would probably just give up because this would be impossible for me to know this is the right listener to hear build events.