Having a 4.2 solution that you will then publish in a 5.0 server, I cannot see any easy way to do what you want. I guess the best alternative is to publish the 4.2 solution and then, based on the warnings given about eSpaces and extension already on the server, you can publish them back to their most recent version.
To ease the situation, you could also create a new solution on your server with all the common eSpaces and extensions (RichWidgets, etc.) and you could then publish it's last version right after publishing the 4.2 solution. This way you easily restore these common components to their most recent version.
Nevertheless, if you were talking about publishing a 5.0 solution, I think I have some ideas that could help you. I will leave them here in case they are useful in the future.
The Upload Solution Operation
You can use the Upload Solution operation to understand which eSpaces or extensions of a Solution Pack are already on your server with the same content. The Upload Solution operation simply uploads all eSpaces and extensions contained in the Solution Pack to the server. In case any of the eSpaces or extensions is already in the server with the same content, the tool will show warning messages informing you about that.
The new "Include Dependencies in download" option in the Download Solution operation
There is a new feature in the OutSystems Agile Platform 5.0 - the Include Dependencies in download option. If you go to the Versions tab of your solution in Service Center, you have this option available in the bottom right corner. If you set the Include Dependencies in download to false and then download your solution, only the eSpaces and extensions in the solution Components list will be included in the generated Solution Pack - i.e. the Dependencies will not be included.
When you publish a solution pack which does not have the dependencies included in a server, you will see warnings about each eSpace or extension that is missing, but the solution will publish without problems using the currently published version of the dependencies.
This Include Dependencies in download is very helpful if you want to pass a solution from one environment to another, but you are sure you do not want to publish the solution dependencies (because they are older or not valid in the new environment). Of course, when using this option you must be cautious, because for the solution to work you must guarrantee that the eSpaces and extensions from which it depends are already published in the new environment and are compatible with the solution components.
I hope this information might be helpful for you in the future,
I was making some tests, and my conclusions are the following:
This means, for instance, that in a situation where you have newer versions of your dependencies in the Development Environment that you do not want to take to the Quality Environment, you can use this feature. Nevertheless, for you use case it will not be usefull, because old versions will always be detected and rolled back.
That in fact a solution for the problem. The thing is that Evert was trying to find if there was an alternative that could be automated making use of Solution Pack's.