Last active
August 17, 2016 08:15
-
-
Save baywet/de2fba740adb70332ca8 to your computer and use it in GitHub Desktop.
adding support of incrementation of upgrade ranges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Reflection.Assembly]::Load("Microsoft.VisualStudio.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); | |
[System.Reflection.Assembly]::Load("Microsoft.VisualStudio.SharePoint.Designers.Models.Features, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); | |
$featureFiles = get-childitem -Filter "*.feature" -Recurse; | |
$featureTemplateFiles = get-childitem -Filter "*.Template.xml" -Recurse | Where-Object {$_.Directory.Name -ne "Package"} | |
$featureRegex = [Regex]"(?<buildnumber>\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4})"; | |
$templateRegex = [Regex]'EndVersion=\"(?<buildnumber>\d{1,4}\.\d{1,4}\.\d{1,4}\.\d{1,4})\"'; | |
function getVersionObject($stringVersion) | |
{ | |
return New-Object -TypeName System.Version -ArgumentList $stringVersion; | |
} | |
function getCleanBuildNumber() | |
{ | |
$match = $featureRegex.Match($Env:BUILD_BUILDNUMBER); | |
return $match.Groups["buildnumber"].Value; | |
} | |
$buildNumber = getVersionObject(getCleanBuildNumber); | |
foreach($featureFile in $featureFiles) | |
{ | |
$feature = [Microsoft.VisualStudio.SharePoint.Designers.Models.Features.FeatureManager]::ReadFeature($featureFile.FullName); | |
$transaction = $feature.Store.TransactionManager.BeginTransaction("Load Feature Manifest"); | |
$version = $feature.Version; | |
if($version -eq $null) | |
{ | |
$version = New-Object -TypeName System.Version -ArgumentList "1.0.0.0"; | |
} | |
$newVersion = New-Object -TypeName System.Version -ArgumentList ($version.Major.ToString()+"." + $version.Minor.ToString() + "."+ $buildNumber.Build.ToString() + "."+ ($buildNumber.Revision).ToString()); | |
Write-Host "updated feature " + $feature.Id + " to version " + $newVersion.ToString(); | |
$Feature.Version = $newVersion; | |
[Microsoft.VisualStudio.SharePoint.Designers.Models.Features.FeatureManager]::WriteFeature($feature, $featureFile.FullName); | |
$transaction.Commit(); | |
$transaction.Dispose(); | |
} | |
foreach($featureTemplateFile in $featureTemplateFiles) | |
{ | |
$templateFileContent = Get-Content $featureTemplateFile.FullName; | |
$matches = $templateRegex.Matches($templateFileContent); | |
foreach($match in $matches) | |
{ | |
$templateVersion = getVersionObject($match.Groups["buildnumber"].Value); | |
$newTemplateVersion = getVersionObject(($templateVersion.Major.ToString()+"."+$templateVersion.Minor.ToString()+"."+$buildNumber.Build.ToString()+"."+($buildNumber.Revision+1).ToString())); | |
$templateFileContent = ($templateFileContent -replace $match.Value, ('EndVersion="'+$newTemplateVersion.ToString()+'"')) | |
} | |
$templateFileContent | Out-File -FilePath $featureTemplateFile.FullName -Verbose -Encoding utf8; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment