Here is what the console applications has to do :
- Create a folder "SolutionsToDeploy" where the WSPs will be extracted and the command file created.
- Iterate through the solutions in the solutions store, extract the wsp file and generate the Stsadm command needed to install it.
Here is the code :
Imports System.TextImports System.IOImports SystemImports Microsoft.SharePointImports Microsoft.SharePoint.AdministrationImports System.XmlImports System.WebModule ExtractSolutionsSub Main(ByVal args() As String)
TryDim solutions As SPSolutionCollection = SPFarm.Local.Solutions
Dim Path As String = "SolutionsToDeploy/"
Dim AllowGac As Boolean = False
Dim AllowCas As Boolean = False
' Create the folder if it does not existIf Not System.IO.Directory.Exists(Path) Then
System.IO.Directory.CreateDirectory(Path)
End If
'Create a file stream where StsAdm command will be addedDim wrt As System.IO.TextWriter = New StreamWriter(Path + "DeploySolutions.cmd")
For Each sol As SPSolution In solutions
'See if the parameters -AllowGacDeployment and -AllowCasPolicies are neededAllowGac = IIf(sol.ContainsGlobalAssembly, True, False)
AllowCas = IIf(sol.ContainsCasPolicy, True, False)
Dim strline As String = String.Empty
'Extract the solution into a fileDim wsp As SPPersistedFile = sol.SolutionFile
wsp.SaveAs(Path + sol.Name)
'For every solution we need two commands : AddSolution and DeploySolution strline = "Stsadm -o AddSolution -FileName " + sol.Namewrt.WriteLine(strline)
If sol.DeploymentState = SPSolutionDeploymentState.GlobalAndWebApplicationDeployed Or sol.DeploymentState = SPSolutionDeploymentState.WebApplicationDeployed Then
For Each wapp As SPWebApplication In sol.DeployedWebApplications
strline = "Stsadm -o DeploySolution -name " + sol.Name + " -url " + wapp.GetResponseUri(SPUrlZone.Default).ToString() + IIf(AllowGac, " -AllowGacDeployment", "") + IIf(AllowCas, " -AllowCasPolicies", "") + " -Immediate"
Next Elsestrline = "Stsadm -o DeploySolution -name " + sol.Name + IIf(AllowGac, " -AllowGacDeployment", "") + IIf(AllowCas, " -AllowCasPolicies", "") + " -Immediate"
End If
wrt.WriteLine(strline)
' Execute the timer job strline = "Stsadm -o ExecAdmSvcJobs"wrt.WriteLine(strline)
wrt.WriteLine()
Next 'Write the command file to disk and close the streamwrt.Flush()
wrt.Close()
wrt = NothingCatch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End ModuleI executed the console application, copied the new folder created (SolutionsToDeploy) to the new farm and ran the command file (DeploySolutions.cmd). With one shot, all my 50 solutions were added and deployed to the new farm.
Hope this helps.
No comments:
Post a Comment