Skip to content

Instantly share code, notes, and snippets.

@baywet
Last active August 17, 2016 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baywet/de2fba740adb70332ca8 to your computer and use it in GitHub Desktop.
Save baywet/de2fba740adb70332ca8 to your computer and use it in GitHub Desktop.
adding support of incrementation of upgrade ranges
[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