|
1 |
| -@{ |
2 |
| - Layout = "~/_ContentLayout.cshtml"; |
3 |
| -} |
4 |
| - |
5 |
| -@section headerBody { |
6 |
| - <h1>Creating Packages</h1> |
7 |
| - <p class="lead">Boxstarter includes some commands that can automate a lot of the "grunt" work involved with creating and packing NuGet packages.</p> |
8 |
| -} |
9 |
| - |
10 |
| -<h3>Do you really need to create a package?</h3> |
11 |
| -<p>Maybe not. For simple "One-Off" packages or packages that do not need a home in a public NuGet feed and do not need any additional scripts or resources outside of the ChocolateyInstall.ps1 script, Boxstarter provides a means of creating "on the fly" packages from a single script file or URL. You may pass a file path or URL to the -PackageName parameter of <code>Install-BoxstarterPackage</code> and Boxstarter will generate a temporary package to install the script. If using a URL, the URL content must be plain text and not contain any markup.</p> |
12 |
| -<pre> |
13 |
| -Install-BoxstarterPackage -PackageName https://gist.github.com/mwrock/8066325/raw/e0c830528429cd68a8c71dbff6f48298576d8d20/gistfile1.txt |
14 |
| -</pre> |
15 |
| - |
16 |
| -<h3>New-PackageFromScript</h3> |
17 |
| -<p>The simplest way to create a NuGet package is using the <code>New-PackageFromScript</code> command.</p> |
18 |
| -<pre> |
19 |
| -New-PackageFromScript MyScript.ps1 MyPackage |
20 |
| -</pre> |
21 |
| -<p>This command takes either a file or http URL (like a <a href="https://gist.github.com">Github Gist</a>) that represents the install script. The <code>New-PackageFromScript</code> command will create a Chocolatey NuGet package with the contents of the script moved to the ChocolateyInstall.ps1 file. While this is an incredibly simple way to create a package for your Boxstarter installations, it does not provide much flexibility in customizing the nuspec manifest or adding other files to your install package.</p> |
22 |
| - |
23 |
| -<h3>New-BoxstarterPackage</h3> |
24 |
| -<p>The New-BoxstarterPackage command creates a skeletal package with a minimal *.nuspec file and ChocolateyInstall.ps1 file.</p> |
25 |
| -<pre> |
26 |
| -New-BoxstarterPackage -Name MyPackage -Description "I hope you enjoy MyPackage" |
27 |
| -</pre> |
28 |
| -<p>This creates a MyPackage.nuspec file that looks like:</p> |
29 |
| -<pre> |
30 |
| -<?xml version="1.0" ?> |
31 |
| -<package> |
32 |
| - <metadata> |
33 |
| - <id>MyPackage</id> |
34 |
| - <version>1.0.0</version> |
35 |
| - <authors>Matt</authors> |
36 |
| - <owners>Matt</owners> |
37 |
| - <description>I hope you enjoy MyPackage</description> |
38 |
| - <tags>Boxstarter</tags> |
39 |
| - </metadata> |
40 |
| -</package> |
41 |
| -</pre> |
42 |
| -<p>And a tools/ChocolateyInstall.ps1 with this code:</p> |
43 |
| -<pre> |
44 |
| -try { |
45 |
| - Write-ChocolateySuccess 'MyPackage' |
46 |
| -} catch { |
47 |
| - Write-ChocolateyFailure 'MyPackage' $($_.Exception.Message) |
48 |
| - throw |
49 |
| -} |
50 |
| -</pre> |
51 |
| - |
52 |
| -<h3>The Boxstarter Local Repository</h3> |
53 |
| -<p> |
54 |
| - These files are saved to your local Boxstarter Repository. This is where Boxstarter will store your local packages and running the Install-BoxstarterPackage command will look here first before any external feed. The repository is located in your AppData directory but you can always find out exactly where by inspecting the global Boxstarter variable <code>$Boxstarter.LocalRepo</code>. |
55 |
| -</p> |
56 |
| -<img class="img-responsive" src="Images/global.png"/> |
57 |
| -<p>You can change the location by using the Set-BoxstarterConfig command:</p> |
58 |
| -<pre> |
59 |
| -Set-BoxstarterConfig -LocalRepo "c:\some\other\location" |
60 |
| -</pre> |
61 |
| -<h3>Editing and adding resources to your package</h3> |
62 |
| -<p>Optionally, you can call the New-BoxstarterPackage command with a path argument and supply a directory that contains files you want to be included in the package:</p> |
63 |
| -<pre> |
64 |
| - New-BoxstarterPackage -Name MyPackage -Description "I hope you enjoy MyPackage" -Path "c:\somePath" |
65 |
| -</pre> |
66 |
| -<p>Boxstarter will copy all files at, and below, c:\somepath and you can refer to these files in your ChocolateyInstall.ps1 using <code>Get-PackageRoot</code>.</p> |
67 |
| -<pre> |
68 |
| -Copy-Item (Join-Path -Path (Get-PackageRoot($MyInvocation)) -ChildPath 'console.xml') -Force $env:appdata\console\console.xml |
69 |
| -</pre> |
70 |
| -<p>Assuming you have a console.xml file at the root of the path you provided to <code>New-BoxstarterPackage</code>, you can access that file from your ChocolateyInstall.ps1 script.</p> |
71 |
| - |
72 |
| -<h3>Composing the ChocolateyInstall Script</h3> |
73 |
| -<p>If you are already familiar with authoring <a href="https://github.com/chocolatey/choco/wiki/CreatePackagesQuickStart">Chocolatey package scripts</a>, you know how to do this already. The only difference with Boxstarter scripts is that your script also has access to Boxstarter's API for configuring windows, running updates as well as logging and reboot control.</p> |
74 |
| -<p>Lets open the ChocolateyInstall.ps1 script that the New-BoxstarterPackage command created for our MyPackage package:</p> |
75 |
| -<pre> |
76 |
| -Notepad (Join-Path -Path $Boxstarter.LocalRepo -ChildPath "MyPackage\tools\ChocolateyInstall.ps1") |
77 |
| -</pre> |
78 |
| -<p>Replace the boilerplate code with something that will actually do something:</p> |
79 |
| -<pre> |
80 |
| -Update-ExecutionPolicy Unrestricted |
81 |
| -Move-LibraryDirectory "Personal" "$env:UserProfile\skydrive\documents" |
82 |
| -Set-ExplorerOptions -showHiddenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions |
83 |
| -Set-TaskbarSmall |
84 |
| -Enable-RemoteDesktop |
85 |
| - |
86 |
| -cinst VisualStudio2013ExpressWeb |
87 |
| -cinst fiddler4 |
88 |
| -cinst mssqlserver2012express |
89 |
| -cinst git-credential-winstore |
90 |
| -cinst console-devel |
91 |
| -cinst poshgit |
92 |
| -cinst windbg |
93 |
| - |
94 |
| -cinst Microsoft-Hyper-V-All -source windowsFeatures |
95 |
| -cinst IIS-WebServerRole -source windowsfeatures |
96 |
| -cinst IIS-HttpCompressionDynamic -source windowsfeatures |
97 |
| -cinst TelnetClient -source windowsFeatures |
98 |
| - |
99 |
| -Install-ChocolateyPinnedTaskBarItem "$env:windir\system32\mstsc.exe" |
100 |
| -Install-ChocolateyPinnedTaskBarItem "$env:programfiles\console\console.exe" |
101 |
| - |
102 |
| -Copy-Item (Join-Path -Path (Get-PackageRoot($MyInvocation)) -ChildPath 'console.xml') -Force $env:appdata\console\console.xml |
103 |
| - |
104 |
| -Install-ChocolateyVsixPackage xunit http://visualstudiogallery.msdn.microsoft.com/463c5987-f82b-46c8-a97e-b1cde42b9099/file/66837/1/xunit.runner.visualstudio.vsix |
105 |
| -Install-ChocolateyVsixPackage autowrocktestable http://visualstudiogallery.msdn.microsoft.com/ea3a37c9-1c76-4628-803e-b10a109e7943/file/73131/1/AutoWrockTestable.vsix |
106 |
| - |
107 |
| -Install-WindowsUpdate -AcceptEula |
108 |
| -</pre> |
109 |
| -<p>This script does several things and leverage's both Chocolatey and Boxstarter commands. Here is what this will do:</p> |
110 |
| -<ul> |
111 |
| - <li>Set the PowerShell execution policy to be able to run all scripts</li> |
112 |
| - <li>Move your personal folders to sync with SkyDrive</li> |
113 |
| - <li>Make Windows Explorer tolerable</li> |
114 |
| - <li>Enable Remote Desktop to the box</li> |
115 |
| - <li>Download and install a bunch of software</li> |
116 |
| - <li>Enable Windows Features Hyper-V, IIS and the Telnet client</li> |
117 |
| - <li>Create some shortcuts in the taskbar for common applications</li> |
118 |
| - <li>Copy your console configuration file with your favorite settings</li> |
119 |
| - <li>Install some Visual Studio extensions from the Visual Studio gallery</li> |
120 |
| - <li>Install all critical windows updates</li> |
121 |
| -</ul> |
122 |
| - |
123 |
| -<h3>Boxstarter ChocolateyInstall Considerations</h3> |
124 |
| -<p> Boxstarter can run any Chocolatey package and any valid PowerShell inside that package. However, there are a few things to consider that may make a Boxstarter Chocolatey package a better installation experience.</p> |
125 |
| -<ul> |
126 |
| - <li>Boxstarter Chocolatey packages should be repeatable. This is especially true if you anticipate the need to reboot. When Boxstarter reboots, it starts running the package from the beginning. So ensure that there is nothing that would cause the package to break if run twice.</li> |
127 |
| - <li>If you have several Chocolatey packages that you want to install during the Boxstarter session, it is preferable to call CINST directly from inside your ChocolateyInstall instead of declaring them as dependencies. This is because Boxstarter cannot intercept Chocolatey dependencies so those packages will not have any reboot protections.</li> |
128 |
| - <li>Do not use <code>Restart-Computer</code> or any other command that will reboot the computer. Instead use <code>Invoke-Reboot</code>. This will allow Boxstarter to get things in order first so that after the machine recovers from the reboot, Boxstarter can log the user back in and restart the install script.</li> |
129 |
| -</ul> |
130 |
| -<h3>Packing your Package .nupkg</h3> |
131 |
| -<p>Once you are finished composing your package contents, you can call the <code>Invoke-BoxstarterBuild MyPackage</code> command to generate the *.nupkg file for MyPackage. Boxstarter saves these files in the root of <code>$Boxstarter.LocalRepo</code>. If you have several packages in the local repository that you want to build all at once, omit the package name from the command to build all packages in the repository.</p> |
| 1 | +@{ |
| 2 | + Layout = "~/_ContentLayout.cshtml"; |
| 3 | +} |
| 4 | + |
| 5 | +@section headerBody { |
| 6 | + <h1>Creating Packages</h1> |
| 7 | + <p class="lead">Boxstarter includes some commands that can automate a lot of the "grunt" work involved with creating and packing NuGet packages.</p> |
| 8 | +} |
| 9 | + |
| 10 | +<h3>Do you really need to create a package?</h3> |
| 11 | +<p>Maybe not. For simple "One-Off" packages or packages that do not need a home in a public NuGet feed and do not need any additional scripts or resources outside of the ChocolateyInstall.ps1 script, Boxstarter provides a means of creating "on the fly" packages from a single script file or URL. You may pass a file path or URL to the -PackageName parameter of <code>Install-BoxstarterPackage</code> and Boxstarter will generate a temporary package to install the script. If using a URL, the URL content must be plain text and not contain any markup.</p> |
| 12 | +<pre> |
| 13 | +Install-BoxstarterPackage -PackageName https://gist.github.com/mwrock/8066325/raw/e0c830528429cd68a8c71dbff6f48298576d8d20/gistfile1.txt |
| 14 | +</pre> |
| 15 | + |
| 16 | +<h3>New-PackageFromScript</h3> |
| 17 | +<p>The simplest way to create a NuGet package is using the <code>New-PackageFromScript</code> command.</p> |
| 18 | +<pre> |
| 19 | +New-PackageFromScript MyScript.ps1 MyPackage |
| 20 | +</pre> |
| 21 | +<p>This command takes either a file or http URL (like a <a href="https://gist.github.com">Github Gist</a>) that represents the install script. The <code>New-PackageFromScript</code> command will create a Chocolatey NuGet package with the contents of the script moved to the ChocolateyInstall.ps1 file. While this is an incredibly simple way to create a package for your Boxstarter installations, it does not provide much flexibility in customizing the nuspec manifest or adding other files to your install package.</p> |
| 22 | + |
| 23 | +<h3>New-BoxstarterPackage</h3> |
| 24 | +<p>The New-BoxstarterPackage command creates a skeletal package with a minimal *.nuspec file and ChocolateyInstall.ps1 file.</p> |
| 25 | +<pre> |
| 26 | +New-BoxstarterPackage -Name MyPackage -Description "I hope you enjoy MyPackage" |
| 27 | +</pre> |
| 28 | +<p>This creates a MyPackage.nuspec file that looks like:</p> |
| 29 | +<pre> |
| 30 | +<?xml version="1.0" ?> |
| 31 | +<package> |
| 32 | + <metadata> |
| 33 | + <id>MyPackage</id> |
| 34 | + <version>1.0.0</version> |
| 35 | + <authors>Matt</authors> |
| 36 | + <owners>Matt</owners> |
| 37 | + <description>I hope you enjoy MyPackage</description> |
| 38 | + <tags>Boxstarter</tags> |
| 39 | + </metadata> |
| 40 | +</package> |
| 41 | +</pre> |
| 42 | +<p>And a tools/ChocolateyInstall.ps1 with this code:</p> |
| 43 | +<pre> |
| 44 | +try { |
| 45 | + Write-Host 'MyPackage' |
| 46 | +} catch { |
| 47 | + throw |
| 48 | +} |
| 49 | +</pre> |
| 50 | + |
| 51 | +<h3>The Boxstarter Local Repository</h3> |
| 52 | +<p> |
| 53 | + These files are saved to your local Boxstarter Repository. This is where Boxstarter will store your local packages and running the Install-BoxstarterPackage command will look here first before any external feed. The repository is located in your AppData directory but you can always find out exactly where by inspecting the global Boxstarter variable <code>$Boxstarter.LocalRepo</code>. |
| 54 | +</p> |
| 55 | +<img class="img-responsive" src="Images/global.png"/> |
| 56 | +<p>You can change the location by using the Set-BoxstarterConfig command:</p> |
| 57 | +<pre> |
| 58 | +Set-BoxstarterConfig -LocalRepo "c:\some\other\location" |
| 59 | +</pre> |
| 60 | +<h3>Editing and adding resources to your package</h3> |
| 61 | +<p>Optionally, you can call the New-BoxstarterPackage command with a path argument and supply a directory that contains files you want to be included in the package:</p> |
| 62 | +<pre> |
| 63 | + New-BoxstarterPackage -Name MyPackage -Description "I hope you enjoy MyPackage" -Path "c:\somePath" |
| 64 | +</pre> |
| 65 | +<p>Boxstarter will copy all files at, and below, c:\somepath and you can refer to these files in your ChocolateyInstall.ps1 using <code>Get-PackageRoot</code>.</p> |
| 66 | +<pre> |
| 67 | +Copy-Item (Join-Path -Path (Get-PackageRoot($MyInvocation)) -ChildPath 'console.xml') -Force $env:appdata\console\console.xml |
| 68 | +</pre> |
| 69 | +<p>Assuming you have a console.xml file at the root of the path you provided to <code>New-BoxstarterPackage</code>, you can access that file from your ChocolateyInstall.ps1 script.</p> |
| 70 | + |
| 71 | +<h3>Composing the ChocolateyInstall Script</h3> |
| 72 | +<p>If you are already familiar with authoring <a href="https://github.com/chocolatey/choco/wiki/CreatePackagesQuickStart">Chocolatey package scripts</a>, you know how to do this already. The only difference with Boxstarter scripts is that your script also has access to Boxstarter's API for configuring windows, running updates as well as logging and reboot control.</p> |
| 73 | +<p>Lets open the ChocolateyInstall.ps1 script that the New-BoxstarterPackage command created for our MyPackage package:</p> |
| 74 | +<pre> |
| 75 | +Notepad (Join-Path -Path $Boxstarter.LocalRepo -ChildPath "MyPackage\tools\ChocolateyInstall.ps1") |
| 76 | +</pre> |
| 77 | +<p>Replace the boilerplate code with something that will actually do something:</p> |
| 78 | +<pre> |
| 79 | +Update-ExecutionPolicy Unrestricted |
| 80 | +Move-LibraryDirectory "Personal" "$env:UserProfile\skydrive\documents" |
| 81 | +Set-ExplorerOptions -showHiddenFilesFoldersDrives -showProtectedOSFiles -showFileExtensions |
| 82 | +Set-TaskbarSmall |
| 83 | +Enable-RemoteDesktop |
| 84 | + |
| 85 | +cinst VisualStudio2013ExpressWeb |
| 86 | +cinst fiddler4 |
| 87 | +cinst mssqlserver2012express |
| 88 | +cinst git-credential-winstore |
| 89 | +cinst console-devel |
| 90 | +cinst poshgit |
| 91 | +cinst windbg |
| 92 | + |
| 93 | +cinst Microsoft-Hyper-V-All -source windowsFeatures |
| 94 | +cinst IIS-WebServerRole -source windowsfeatures |
| 95 | +cinst IIS-HttpCompressionDynamic -source windowsfeatures |
| 96 | +cinst TelnetClient -source windowsFeatures |
| 97 | + |
| 98 | +Install-ChocolateyPinnedTaskBarItem "$env:windir\system32\mstsc.exe" |
| 99 | +Install-ChocolateyPinnedTaskBarItem "$env:programfiles\console\console.exe" |
| 100 | + |
| 101 | +Copy-Item (Join-Path -Path (Get-PackageRoot($MyInvocation)) -ChildPath 'console.xml') -Force $env:appdata\console\console.xml |
| 102 | + |
| 103 | +Install-ChocolateyVsixPackage xunit http://visualstudiogallery.msdn.microsoft.com/463c5987-f82b-46c8-a97e-b1cde42b9099/file/66837/1/xunit.runner.visualstudio.vsix |
| 104 | +Install-ChocolateyVsixPackage autowrocktestable http://visualstudiogallery.msdn.microsoft.com/ea3a37c9-1c76-4628-803e-b10a109e7943/file/73131/1/AutoWrockTestable.vsix |
| 105 | + |
| 106 | +Install-WindowsUpdate -AcceptEula |
| 107 | +</pre> |
| 108 | +<p>This script does several things and leverage's both Chocolatey and Boxstarter commands. Here is what this will do:</p> |
| 109 | +<ul> |
| 110 | + <li>Set the PowerShell execution policy to be able to run all scripts</li> |
| 111 | + <li>Move your personal folders to sync with SkyDrive</li> |
| 112 | + <li>Make Windows Explorer tolerable</li> |
| 113 | + <li>Enable Remote Desktop to the box</li> |
| 114 | + <li>Download and install a bunch of software</li> |
| 115 | + <li>Enable Windows Features Hyper-V, IIS and the Telnet client</li> |
| 116 | + <li>Create some shortcuts in the taskbar for common applications</li> |
| 117 | + <li>Copy your console configuration file with your favorite settings</li> |
| 118 | + <li>Install some Visual Studio extensions from the Visual Studio gallery</li> |
| 119 | + <li>Install all critical windows updates</li> |
| 120 | +</ul> |
| 121 | + |
| 122 | +<h3>Boxstarter ChocolateyInstall Considerations</h3> |
| 123 | +<p> Boxstarter can run any Chocolatey package and any valid PowerShell inside that package. However, there are a few things to consider that may make a Boxstarter Chocolatey package a better installation experience.</p> |
| 124 | +<ul> |
| 125 | + <li>Boxstarter Chocolatey packages should be repeatable. This is especially true if you anticipate the need to reboot. When Boxstarter reboots, it starts running the package from the beginning. So ensure that there is nothing that would cause the package to break if run twice.</li> |
| 126 | + <li>If you have several Chocolatey packages that you want to install during the Boxstarter session, it is preferable to call CINST directly from inside your ChocolateyInstall instead of declaring them as dependencies. This is because Boxstarter cannot intercept Chocolatey dependencies so those packages will not have any reboot protections.</li> |
| 127 | + <li>Do not use <code>Restart-Computer</code> or any other command that will reboot the computer. Instead use <code>Invoke-Reboot</code>. This will allow Boxstarter to get things in order first so that after the machine recovers from the reboot, Boxstarter can log the user back in and restart the install script.</li> |
| 128 | +</ul> |
| 129 | +<h3>Packing your Package .nupkg</h3> |
| 130 | +<p>Once you are finished composing your package contents, you can call the <code>Invoke-BoxstarterBuild MyPackage</code> command to generate the *.nupkg file for MyPackage. Boxstarter saves these files in the root of <code>$Boxstarter.LocalRepo</code>. If you have several packages in the local repository that you want to build all at once, omit the package name from the command to build all packages in the repository.</p> |
0 commit comments