How to programmatically detect if a solution is deployed?
-
07-12-2019 - |
Frage
Situation:
There's a sharepoint farm with ~60 solutions. On some not specified time someone can deploy a new /update an existing solution to this farm. Everytime a deployment is successfull I need to remove some items from the Cache.
Problem:
How can I detect that some deployed some solution to the farm programmatically?
Infos:
I'm using Sharepoint 2010 Server, C# and Visual Studio 2010. because the Production Environment is hosted by a third-party I have no access to the central administration to activate timer jobs. So It would be very nice if there's another way to solve this issue.
Lösung
Introduce a policy that everyone must announce solution deploymements beforehand. In you case it might be good practice in any case to have a calendar saying who is going to install what and when to prevent conflicts.
Andere Tipps
When a solution is deployed globally, all SharePoint application pools, including Central Administration’s, are recycled automatically. When a web application targeted solution is deployed or retracted, only the application pools of the targeted web applications are recycled.
So when the application pool recycles, I believe cache will be destroyed and refreshed too.
Also you just don't want how to know if solution was deployed programmatically, but also react immediately when a solution is deployed and AFAIK, there is no event receiver exposed by SharePoint which allows you to plug-in your own code when solution deploys in the farm.
And the actual answer to the question:
SPFarm farm = new SPFarm();
SPSolution solution = farm.Solutions["solutionname.wsp"];
and a few properties to inspect that may be what you're looking for:
solution.Deployed
solution.DeployedWebApplications
solution.DeployedServers
solution.DeploymentState
and for more details: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spsolution_members.aspx
or just use powershell and pipe your SPSolution object to get-member like i did.