Question

I want to automatically add and install some wsp files. To check if the file is already installed I (think I) need the identity of the solution that I am about to deploy. How can I extract the Identity of the solution out of the WSP file?

foreach ($wspFIL in $solutionsARY) {
    $fileNameSTR = $filesDIR + $wspFIL
    $identitySTR = getIdentityFromWsp fileNameSTR#... this is what I need

    Add-SPSolution -LiteralPath  $fileNameSTR
    Install-SPSolution -Identity  $identitySTR
}
Était-ce utile?

La solution

Actually, you don't need to get the Id of the solution: solutions are identified by their file names (xxxx.wsp) OR their Id.
If a solution with the same file name is already added/deployed, you cannot add another one with the same file name...

[Update 1]
Manually, the Id can be extracted by renaming the .wsp to .cab, extracting the manifest.xml file and open it to find its SolutionId attribute.
There should be a way to automate this through PowerShell.

[Update 2]
Here's the PowerShell code to automate it:

#Create a temp folder
$tempFolder = "C:\temp"
New-Item -ItemType Directory -Force -Path $tempFolder

# Extract the manifest.xml file from the wsp file
expand $fileNameSTR /f:manifest.xml $tempFolder

# Read the XML file and create namespace
$xml = [xml](Get-Content "$tempFolder\manifest.xml")
$xmlNsManager = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$xmlNsManager.AddNamespace("ns", "http://schemas.microsoft.com/sharepoint/")

# Get the SolutionId attribute of the Solution node
$identitySTR = $xml.SelectSingleNode('//ns:Solution', $xmlNsManager).SolutionId
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top