Skip to content

Commit b1221ba

Browse files
committed
Scripts and content for creating NuGet package
Based on scripts in https://github.com/akoeplinger/WiX.Toolset.NuGet
1 parent 99df6cd commit b1221ba

12 files changed

+126
-4
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,5 @@ $RECYCLE.BIN/
155155
# Mac desktop service store files
156156
.DS_Store
157157
/Libs
158+
/NuGet/tools/lib
159+
/NuGet/*.nupkg

Create-Package.ps1

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
msbuild /p:Configuration=Release
2+
3+
Write-Host "Expect 1 warning"
4+
.\nuget.exe pack .\PowerShellWixExtension.nuspec -OutputDirectory .\NuGet
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This file is used to invoke the PowerShell scripts during NuGet package installation.
2+
It should be removed automatically after the package is installed. If this file is still present in your project, you can safely delete it.

NuGet/tools/Install.ps1

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Created by Alexander Köplinger, 2013
2+
3+
param($installPath, $toolsPath, $package, $project)
4+
5+
# ensure that we are installing into a WiX project
6+
if ($project.Kind -ne '{930c7802-8a8c-48f9-8165-68863bccd9dd}')
7+
{
8+
throw "'$($project.Name)' is not a WiX project! This package will only work on WiX projects."
9+
}
10+
11+
# remove dummy file from project
12+
$dummy = $project.ProjectItems.Item("PowerShellWixExtension.DummyFile.txt").Delete()
13+
14+
$msBuildProj = @([Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName))[0]
15+
16+
# remove previous changes (for cases where Uninstall.ps1 wasn't executed properly)
17+
Import-Module (Join-Path $toolsPath "Remove.psm1")
18+
Remove-Changes $msBuildProj
19+
20+
# add the property group directly before the WixTargetsPath-Import, according to http://wixtoolset.org/documentation/manual/v3/msbuild/daily_builds.html
21+
$itemGroup = $msBuildProj.Xml.CreateItemGroupElement()
22+
23+
$wixImport = $msBuildProj.Xml.Children | Where-Object { $_.Project -eq '$(WixTargetsPath)' }
24+
$msBuildProj.Xml.InsertBeforeChild($itemGroup, $wixImport)
25+
26+
# Calculate relative path to package from project
27+
$projectDir = [System.IO.Path]::GetDirectoryName($project.FullName)
28+
29+
Push-Location $projectDir
30+
31+
$hintPath = Resolve-Path ($toolsPath + '\lib\PowerShellWixExtension.dll') -Relative
32+
33+
Pop-Location
34+
35+
# <WixExtension Include="PowerShellWixExtension">
36+
# <HintPath>..\..\Libs\PowerShellWixExtension\PowerShellWixExtension.dll</HintPath>
37+
# <Name>PowerShellWixExtension</Name>
38+
# </WixExtension>
39+
40+
$metadata = New-Object 'System.Collections.Generic.Dictionary[String, String]'
41+
$metadata.Add("HintPath", $hintPath)
42+
$metadata.Add("Name", "PowerShellWixExtension")
43+
$itemGroup.AddItem('WixExtension', 'PowerShellWixExtension', $metadata)
44+
45+
# save changes
46+
$project.Save($null)
47+
$msBuildProj.ReevaluateIfNecessary()

NuGet/tools/Remove.psm1

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Created by Alexander Köplinger, 2013
2+
3+
function Remove-Changes
4+
{
5+
param(
6+
[parameter(Position = 0, Mandatory = $true)]
7+
[Microsoft.Build.Evaluation.Project]$msBuildProj
8+
)
9+
10+
#TODO: this can probably be improved
11+
$wixToolPathProperties = $msBuildProj.Xml.AllChildren | Where-Object { $_.Include -eq 'PowerShellWixExtension' }
12+
13+
if ($wixToolPathProperties)
14+
{
15+
foreach($item in $wixToolPathProperties)
16+
{
17+
$itemGroup = $item.Parent
18+
$itemGroup.RemoveChild($item)
19+
}
20+
}
21+
}

NuGet/tools/Uninstall.ps1

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Originally created by Alexander Köplinger, 2013
2+
3+
param($installPath, $toolsPath, $package, $project)
4+
5+
$msBuildProj = @([Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName))[0]
6+
7+
# remove changes
8+
Import-Module (Join-Path $toolsPath "Remove.psm1")
9+
Remove-Changes $msBuildProj
10+
11+
# need to add and remove a dummy item, otherwise saving the project doesn't work.
12+
$project.ProjectItems.AddFolder("PowerShellWixExtension.DummyFolder", $null).Delete()
13+
14+
# save changes
15+
$project.Save($null)
16+
$msBuildProj.ReevaluateIfNecessary()

PowerShellActions/CustomAction.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Text;
3-
using System.Web;
43
using System.Xml.Linq;
54
using Microsoft.Deployment.WindowsInstaller;
65

@@ -33,8 +32,7 @@ public static ActionResult PowerShellFilesImmediate(Session session)
3332

3433
foreach (Record row in view)
3534
{
36-
// XML comes in with entities already. We need to decode these before putting them back into XML again
37-
var args = HttpUtility.HtmlDecode(session.Format(row["Arguments"].ToString()));
35+
var args = session.Format(row["Arguments"].ToString());
3836

3937
session.Log("args '{0}'", args);
4038

@@ -75,6 +73,8 @@ public static ActionResult PowerShellFilesImmediate(Session session)
7573
public static ActionResult PowerShellFilesDeferred(Session session)
7674
{
7775
session.Log("PowerShellFilesDeferred start");
76+
77+
7878
var hActionRec = new Record(3);
7979
var hProgressRec = new Record(3);
8080

PowerShellActions/PowerShellActions.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<SpecificVersion>False</SpecificVersion>
3939
<HintPath>..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll</HintPath>
4040
</Reference>
41-
<Reference Include="System.Web" />
4241
<Reference Include="System.Xml.Linq" />
4342
<Reference Include="Microsoft.CSharp" />
4443
<Reference Include="System.Xml" />

PowerShellWixExtension.nuspec

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-16"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
3+
<metadata minClientVersion="2.7">
4+
<id>PowerShellWixExtension</id>
5+
<version>1.1</version>
6+
<title>Wix Extension for PowerShell</title>
7+
<summary>Wix Extension that allows running PowerShell scripts</summary>
8+
<description>An extension for Wix that allows running PowerShell scripts, either from .ps1 files included in the MSI, or by embedding PowerShell script directly</description>
9+
<authors>David Gardiner</authors>
10+
<owners>David Gardiner</owners>
11+
<projectUrl>https://github.com/flcdrg/PowerShellWixExtension/</projectUrl>
12+
<licenseUrl>https://github.com/flcdrg/PowerShellWixExtension/blob/master/LICENSE.txt</licenseUrl>
13+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
14+
<tags>WiX PowerShell MSI Installer XML</tags>
15+
<releaseNotes>
16+
Initial release
17+
</releaseNotes>
18+
</metadata>
19+
<files>
20+
<file src="NuGet\content\*.*" target="content" />
21+
<file src="NuGet\tools\**\*.*" target="tools" />
22+
</files>
23+
24+
</package>

PowerShellWixExtension/PowerShellWixExtension.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,7 @@
8181
-->
8282
<Target Name="AfterBuild">
8383
<Copy SourceFiles="$(TargetDir)$(TargetName).pdb; $(TargetPath)" DestinationFolder="..\Libs" SkipUnchangedFiles="true" />
84+
<MakeDir Directories="..\NuGet\tools\lib" Condition="!exists('..\NuGet\tools\lib')"/>
85+
<Copy SourceFiles="$(TargetDir)$(TargetName).pdb; $(TargetPath)" DestinationFolder="..\NuGet\tools\lib" SkipUnchangedFiles="true" />
8486
</Target>
8587
</Project>

Publish-Package.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Get latest nupkg
2+
3+
$nupkg = Get-ChildItem .\Nuget\*.nupkg | Sort-Object -Descending -Property LastWriteTime | Select-Object -First 1
4+
5+
.\NuGet Push $nupkg

nuget.exe

1.59 MB
Binary file not shown.

0 commit comments

Comments
 (0)