Skip to content

Commit

Permalink
The extensions are now being built correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwmkerr committed Mar 30, 2014
1 parent 0ba581a commit c3ccdfd
Show file tree
Hide file tree
Showing 61 changed files with 2,165 additions and 16 deletions.
44 changes: 31 additions & 13 deletions release/BuildRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ if ((Test-Path $msbuild) -eq $false) {

# Load useful functions.
. .\Resources\PowershellFunctions.ps1
. .\Resources\VsixTools.ps1

# Keep track of the 'release' folder location - it's the root of everything else.
# We can also build paths to the key locations we'll use.
$scriptParentPath = Split-Path -parent $MyInvocation.MyCommand.Definition
$folderReleaseRoot = $scriptParentPath
$folderSourceRoot = Split-Path -parent $folderReleaseRoot
$folderSolutionsRoot = Join-Path $folderSourceRoot "source\SharpGL"
$folderSharpGLRoot = Join-Path $folderSourceRoot "source\SharpGL"
$folderNuspecRoot = Join-Path $folderSourceRoot "build\nuspec"

# Part 1 - Build the core libraries.
Write-Host "Preparing to build the core libraries..."
$solutionCoreLibraries = Join-Path $folderSolutionsRoot "SharpGL.sln"
$solutionCoreLibraries = Join-Path $folderSharpGLRoot "SharpGL.sln"
. $msbuild $solutionCoreLibraries /p:Configuration=Release /verbosity:minimal

# Part 2 - Get the version number of the SharpGL core library, use this to build the destination release folder.
$folderBinariesSharpGL = Join-Path $folderSolutionsRoot "Core\SharpGL\bin\Release"
$folderBinariesSharpGLSceneGraph = Join-Path $folderSolutionsRoot "Core\SharpGL.SceneGraph\bin\Release"
$folderBinariesSharpGLSerialization = Join-Path $folderSolutionsRoot "Core\SharpGL.Serialization\bin\Release"
$folderBinariesSharpGLWinForms = Join-Path $folderSolutionsRoot "Core\SharpGL.WinForms\bin\Release"
$folderBinariesSharpGLWPF = Join-Path $folderSolutionsRoot "Core\SharpGL.WPF\bin\Release"
$folderBinariesSharpGL = Join-Path $folderSharpGLRoot "Core\SharpGL\bin\Release"
$folderBinariesSharpGLSceneGraph = Join-Path $folderSharpGLRoot "Core\SharpGL.SceneGraph\bin\Release"
$folderBinariesSharpGLSerialization = Join-Path $folderSharpGLRoot "Core\SharpGL.Serialization\bin\Release"
$folderBinariesSharpGLWinForms = Join-Path $folderSharpGLRoot "Core\SharpGL.WinForms\bin\Release"
$folderBinariesSharpGLWPF = Join-Path $folderSharpGLRoot "Core\SharpGL.WPF\bin\Release"
$releaseVersion = [Reflection.Assembly]::LoadFile((Join-Path $folderBinariesSharpGL "SharpGL.dll")).GetName().Version
Write-Host "Built Core Libraries. Release Version: $releaseVersion"

Expand All @@ -42,13 +43,13 @@ CopyItems (Join-Path $folderBinariesSharpGLWPF "*.*") (Join-Path $folderReleaseC

# Part 4 - Build the Samples
Write-Host "Preparing to build the samples..."
$solutionSamples = Join-Path $folderSolutionsRoot "Samples.sln"
$solutionSamples = Join-Path $folderSharpGLRoot "Samples.sln"
. $msbuild $solutionSamples /p:Configuration=Release /verbosity:quiet

# Part 5 - Copy the samples to the release.
$folderReleaseSamples = Join-Path $folderRelease "Samples"
EnsureEmptyFolderExists($folderReleaseSamples)
$releaseFolders = gci (Join-Path $folderSolutionsRoot "Samples") -Recurse -Directory -filter "Release" | select FullName
$releaseFolders = gci (Join-Path $folderSharpGLRoot "Samples") -Recurse -Directory -filter "Release" | select FullName
$releaseFolders | ForEach {
$releaseFolder = $_.FullName
$sampleName = (Get-Item (Split-Path -parent (Split-Path -parent $releaseFolder))).Name
Expand All @@ -59,13 +60,13 @@ Write-Host "Built samples."

# Part 6 - Build the Tools
Write-Host "Preparing to build the tools..."
$solutionTools = Join-Path $folderSolutionsRoot "Tools.sln"
$solutionTools = Join-Path $folderSharpGLRoot "Tools.sln"
. $msbuild $solutionTools /p:Configuration=Release /verbosity:quiet

# Part 7 - Copy the tools to the release.
$folderReleaseTools = Join-Path $folderRelease "Tools"
EnsureEmptyFolderExists($folderReleaseTools)
$releaseFolders = gci (Join-Path $folderSolutionsRoot "Tools") -Recurse -Directory -filter "Release" | select FullName
$releaseFolders = gci (Join-Path $folderSharpGLRoot "Tools") -Recurse -Directory -filter "Release" | select FullName
$releaseFolders | ForEach {
$releaseFolder = $_.FullName
$toolName = (Get-Item (Split-Path -parent (Split-Path -parent $releaseFolder))).Name
Expand All @@ -76,7 +77,7 @@ Write-Host "Built tools."

# Part 8 - Move the core libraries to the dependencies folders of the extensions, then build the extensions.
Write-Host "Preparing to build the extensions..."
$folderExtensionsRoot = Join-Path $folderSolutionsRoot "Extensions"
$folderExtensionsRoot = Join-Path $folderSourceRoot "source\Extensions"
$dllSharpGL = Join-Path $folderReleaseCore "SharpGL\SharpGL.dll"
$dllSharpGLSceneGraph = Join-Path $folderReleaseCore "SharpGL.SceneGraph\SharpGL.SceneGraph.dll"
$dllSharpGLWPF = Join-Path $folderReleaseCore "SharpGL.WPF\SharpGL.WPF.dll"
Expand All @@ -86,6 +87,10 @@ Copy-Item $dllSharpGL -Destination (Join-Path $folderExtensionsRoot "WinformsTem
Copy-Item $dllSharpGLSceneGraph -Destination (Join-Path $folderExtensionsRoot "WinformsTemplate\Dependencies")
Copy-Item $dllSharpGLWinForms -Destination (Join-Path $folderExtensionsRoot "WinformsTemplate\Dependencies")

Copy-Item $dllSharpGL -Destination (Join-Path $folderExtensionsRoot "WinformsTemplateProject.2010\Dependencies")
Copy-Item $dllSharpGLSceneGraph -Destination (Join-Path $folderExtensionsRoot "WinformsTemplateProject.2010\Dependencies")
Copy-Item $dllSharpGLWinForms -Destination (Join-Path $folderExtensionsRoot "WinformsTemplateProject.2010\Dependencies")

Copy-Item $dllSharpGL -Destination (Join-Path $folderExtensionsRoot "WinformsTemplateProject\Dependencies")
Copy-Item $dllSharpGLSceneGraph -Destination (Join-Path $folderExtensionsRoot "WinformsTemplateProject\Dependencies")
Copy-Item $dllSharpGLWinForms -Destination (Join-Path $folderExtensionsRoot "WinformsTemplateProject\Dependencies")
Expand All @@ -94,19 +99,32 @@ Copy-Item $dllSharpGL -Destination (Join-Path $folderExtensionsRoot "WpfTemplate
Copy-Item $dllSharpGLSceneGraph -Destination (Join-Path $folderExtensionsRoot "WpfTemplate\Dependencies")
Copy-Item $dllSharpGLWPF -Destination (Join-Path $folderExtensionsRoot "WpfTemplate\Dependencies")

Copy-Item $dllSharpGL -Destination (Join-Path $folderExtensionsRoot "WpfTemplateProject.2010\Dependencies")
Copy-Item $dllSharpGLSceneGraph -Destination (Join-Path $folderExtensionsRoot "WpfTemplateProject.2010\Dependencies")
Copy-Item $dllSharpGLWPF -Destination (Join-Path $folderExtensionsRoot "WpfTemplateProject.2010\Dependencies")

Copy-Item $dllSharpGL -Destination (Join-Path $folderExtensionsRoot "WpfTemplateProject\Dependencies")
Copy-Item $dllSharpGLSceneGraph -Destination (Join-Path $folderExtensionsRoot "WpfTemplateProject\Dependencies")
Copy-Item $dllSharpGLWPF -Destination (Join-Path $folderExtensionsRoot "WpfTemplateProject\Dependencies")

$solutionExtensions = Join-Path $folderSolutionsRoot "Extensions.sln"
$solutionExtensions2010 = Join-Path $folderExtensionsRoot "Extensions.2010.sln"
. $msbuild $solutionExtensions2010 /p:Configuration=Release /verbosity:quiet
$solutionExtensions = Join-Path $folderExtensionsRoot "Extensions.sln"
. $msbuild $solutionExtensions /p:Configuration=Release /verbosity:quiet

# Part 9 - Copy the extensions to the release.
$folderReleaseExtensions = Join-Path $folderRelease "Extensions"
EnsureEmptyFolderExists($folderReleaseExtensions)
CopyItems (Join-Path $folderExtensionsRoot "SharpGL.2010\bin\Release\SharpGL.2010.vsix") $folderReleaseExtensions
CopyItems (Join-Path $folderExtensionsRoot "SharpGL\bin\Release\SharpGL.vsix") $folderReleaseExtensions
Write-Host "Built extensions."

# Now use vsix tools to tweak the extensions.
Vsix-SetVersion -VsixPath (Join-Path $folderReleaseExtensions "SharpGL.2010.vsix") -Version $releaseVersion
Vsix-SetVersion -VsixPath (Join-Path $folderReleaseExtensions "SharpGL.vsix") -Version $releaseVersion
Vsix-FixInvalidMultipleFiles -VsixPath (Join-Path $folderReleaseExtensions "SharpGL.2010.vsix")
Vsix-FixInvalidMultipleFiles -VsixPath (Join-Path $folderReleaseExtensions "SharpGL.vsix")

# Part 10 - Build the Nuget Packages
Write-Host "Preparing to build the Nuget Packages..."
$folderReleasePackages = Join-Path $folderRelease "Packages"
Expand Down
252 changes: 252 additions & 0 deletions release/Resources/VsixTools.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )

# Unzips a zip file at $path to the folder $destination.
function Unzip($path, $destination)
{
[System.IO.Compression.ZipFile]::ExtractToDirectory($path, $destination)
}

# Given a path such as 'c:\test.vsix' this function
# extracts the contents to c:\test.
function ExtractVsixToWorkingFolder($vsixPath) {

# Create the destination directory.
$extractFolderName = [System.Io.Path]::GetFileNameWithoutExtension($vsixPath)
$extractFolderPath = (Join-Path (Split-Path $vsixPath) $extractFolderName)

# Throw if it already exists.
if(Test-Path $extractFolderPath) {
throw "Cannot extract the vsix to folder '$extractFolderPath' as it already exists and might cause data loss."
}

# Extract the zip to the folder.
Unzip $vsixPath $extractFolderPath

# Return the extract folder path, which is essentially our working directory.
return $extractFolderPath
}

# Given a path to a vsix, overwrites it with the contents of the s
# associated working folder.
function ZipWorkingFolderToVsix($workingFolder, $vsixPath) {

# Delete the vsix (as we will overwrite it).
Copy-Item $vsixPath -Destination ($vsixPath + ".backup")
Remove-Item $vsixPath -Force

# Note we don't use the .NET method below - for some reason the package
# seems to not have the templates extracted.
# Zip the working folder up and save it at the vsix path
#[System.IO.Compression.ZipFile]::CreateFromDirectory($workingFolder, $vsixPath)

# Remove the working folder.
#Remove-Item $workingFolder -Force -Recurse

$vsixZip = [System.IO.Path]::ChangeExtension($vsixPath, "zip")
if(!(test-path($vsixZip)))
{
set-content $vsixZip ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $vsixZip).IsReadOnly = $false
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($vsixZip)
$items = Get-ChildItem $workingFolder
foreach($file in $items)
{
$zipPackage.CopyHere($file.FullName)
do {
Start-sleep 2
} until ( $zipPackage.Items() | select {$_.Name -eq $file.Name} )
}
Move-Item $vsixZip -Destination $vsixPath -Force
Remove-Item $workingFolder -Force -Recurse
}

# Gets the vsix manifest version. Could be:
# 1: Visual Studio 2010
# 2: Visual Studio 2012 onwards
function GetManifestVersion($manifestXml) {

# Version 1 if we have a Vsix node with Version attribute = 1.
if($manifestXml.DocumentElement.Name -eq "Vsix" -and $manifestXml.Vsix.Version -eq "1.0.0") {
return 1;
}

# Version 2 if we have a Package manifest node with Version attribute = 2.
if($manifestXml.DocumentElement.Name -eq "PackageManifest" -and $manifestXml.PackageManifest.Version -eq "2.0.0") {
return 2;
}

throw "Unable to determine the version of the Vsix manifest."
}

function GetManifestNamespaceManager($manifestXml) {
$ns = New-Object System.Xml.XmlNamespaceManager($manifestXml.NameTable)
$ns.AddNamespace("ns", $manifestXml.DocumentElement.NamespaceURI)
return ,$ns
}

# Sets the version of the vsix.
# Version should be a string in the format "a.b" "a.b.c" or "a.b.c.d"
function Vsix-SetVersion {
param(
[Parameter(Mandatory=$true)]
[string]$VsixPath,
[Parameter(Mandatory=$true)]
[string]$Version
)

# First, create the working directory.
$workingFolder = ExtractVsixToWorkingFolder $VsixPath

# Now load the manifest.
$manifestPath = Join-Path $workingFolder "extension.vsixmanifest"
$manifestXml = New-Object XML
$manifestXml.Load($manifestPath)

# Set the package version. The xml structure depends on the manifest version.
$manifestVersion = GetManifestVersion($manifestXml)
if($manifestVersion -eq 1) {
$manifestXml.Vsix.Identifier.Version = $Version
} elseif($manifestVersion -eq 2) {
$manifestXml.PackageManifest.Metadata.Identity.Version = $Version
} else {
throw "Unsupported manifest version"
}

# Save the manifest.
$manifestXml.save($manifestPath)

# Finally, save the updated working folder as the vsix.
ZipWorkingFolderToVsix $workingFolder $vsixPath
}

function Vsix-FixInvalidMultipleFiles {
param(
[Parameter(Mandatory=$true)]
[string]$VsixPath
)

# Folder names need to be more than one letter and have different starting letters and numbers.
$folderNames = @("Alpha1","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whiskey","Xray","Yankee","Zulu")
# $folderNames = @("F1","F2","F3","F4")

# The gist is this. Find every zip file in Project Templates, e.g:
# ProjectTemplates\CSharp\1033\PlumsProject.zip
# ProjectTemplates\CSharp\1033\ApplesProject.zip
# Then put *each one* into a uniquely named folder by replacing
# 'project templates' in the path with a new unique id
# A\CSharp\1033\PlumsProject.zip
# B\CSharp\1033\ApplesProject.zip
# don't use numbers, as the Visual Studio Gallery site fails
# if you use 1, 11, 111 etc.

# First, create the working directory.
$workingFolder = ExtractVsixToWorkingFolder $VsixPath

# Get the zip paths. Also create an array that will store the new project template folders.
$projectTemplateFolders = @()
$folderNameIndex = 0
Get-ChildItem -Path (Join-Path $workingFolder '.\ProjectTemplates') -Filter *.zip -Recurse | ForEach-Object {
$from = $_.FullName
$newPath = $from.Replace('\ProjectTemplates\', '\' + $folderNames[$folderNameIndex] + '\')
$projectTemplateFolders += $folderNames[$folderNameIndex]
$folderNameIndex++

# Copy the file from the old location to the new one, creating a directory chain as necessary.
New-Item -ItemType File -Path $newPath -Force
Copy-Item $from $newPath -Force
}

# Delete the project templates folder.
Remove-Item (Join-Path $workingFolder '.\ProjectTemplates') -Force -Recurse

# Now load the manifest.
$manifestPath = Join-Path $workingFolder "extension.vsixmanifest"
$manifestXml = New-Object XML
$manifestXml.Load($manifestPath)

# Get the manifest version - this will determine what nodes we need to change to match the
# new folder structure.
$manifestVersion = GetManifestVersion($manifestXml)
$ns = GetManifestNamespaceManager($manifestXml)
if($manifestVersion -eq 1) {

# Manifest v1:
# Remove all Vsix/Content/ProjectTemplate nodes and replace with A/B/C etc, e.g.:
# <Content>
# <ProjectTemplate>ProjectTemplates</ProjectTemplate>
# </Content>
# to
# <Content>
# <ProjectTemplate>A</ProjectTemplate>
# <ProjectTemplate>B</ProjectTemplate>
# <ProjectTemplate>C</ProjectTemplate>
# </Content>
$contentNode = $manifestXml.Vsix.SelectSingleNode("ns:Content", $ns)
$projectTemplateNode = $manifestXml.Vsix.Content.SelectSingleNode("ns:ProjectTemplate", $ns)
$manifestXml.Vsix.Content.RemoveChild($projectTemplateNode)

foreach ($projectTemplateFolder in $projectTemplateFolders) {
$newnode = $projectTemplateNode.CloneNode($true)
$newnode.InnerText = $projectTemplateFolder
$contentNode.AppendChild($newnode)
}
} elseif($manifestVersion -eq 2) {

# Manifest v2:
# Remove all PackageManifest/Assets/Asset (project templat) nodes and replace with A/B/C etc, e.g.:
# <Assets>
# <Asset Type="Microsoft.VisualStudio.ProjectTemplate" Path="ProjectTemplates" />
# </Assets>
# to
# <Assets>
# <Asset Type="Microsoft.VisualStudio.ProjectTemplate" Path="A" />
# <Asset Type="Microsoft.VisualStudio.ProjectTemplate" Path="B" />
# <Asset Type="Microsoft.VisualStudio.ProjectTemplate" Path="C" />
# </Assets>

# Get all the existing project template nodes.
$assetsNode = $manifestXml.PackageManifest.SelectSingleNode("ns:Assets", $ns)
$projectTemplateNodes = $manifestXml.PackageManifest.Assets.SelectNodes("ns:Asset[@Type='Microsoft.VisualStudio.ProjectTemplate']", $ns)
foreach($projectTemplateNode in $projectTemplateNodes) {
$manifestXml.PackageManifest.Assets.RemoveChild($projectTemplateNode)
}
foreach ($projectTemplateFolder in $projectTemplateFolders) {
$newnode = $projectTemplateNodes[0].CloneNode($true)
$newnode.Path = $projectTemplateFolder
$assetsNode.AppendChild($newnode)
}
} else {
throw "Unsupported manifest version"
}

# Save the manifest.
$manifestXml.save($manifestPath)


# Finally, save the updated working folder as the vsix.
ZipWorkingFolderToVsix $workingFolder $vsixPath
}

function Vsix-GetManifestVersion {
param(
[Parameter(Mandatory=$true)]
[string]$VsixPath
)

# First, create the working directory.
$workingFolder = ExtractVsixToWorkingFolder $VsixPath

# Now load the manifest.
$manifestPath = Join-Path $workingFolder "extension.vsixmanifest"

# Get the manifest version.
$manifestXml = New-Object XML
$manifestXml.Load($manifestPath)
$manifestVersion = GetManifestVersion($manifestXml)

# Finally, clean up the working folder.
Remove-Item $workingFolder -Force -Recurse
return $manifestVersion
}
Loading

0 comments on commit c3ccdfd

Please sign in to comment.