Skip to content

Commit 699c690

Browse files
committed
migrating from hq
0 parents  commit 699c690

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

readme.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
SolutionScripts is a Nuget package that sources custom scripts and includes custom powershell modules
2+
3+
Installation instructions:
4+
---
5+
6+
Install-Package SolutionScripts
7+
8+
9+
Why?
10+
---
11+
12+
When Visual Studio opens a solution, Nuget looks at each installed package for an init.ps1 script in the package's tools directory. If that script exists it will be executed. [This is the way that package authors enhance the package manager console experience for consumers of their packages](http://haacked.com/archive/2011/04/19/writing-a-nuget-package-that-adds-a-command-to-the.aspx).
13+
14+
_However_, sometimes developers want to add functions or custom script that will execute in the package manager console independent of a particular package. In this case, a lone developer can customize the [powershell profile that the package manager console uses](http://docs.nuget.org/docs/start-here/using-the-package-manager-console#Setting_up_a_NuGet_Powershell_Profile).
15+
16+
This doesn't scale. When sharing custom scripts and global functions across an entire team for a particular project, it doesn't make sense to edit each developer's profile. The profile works across multiple solutions. That would also be weird, to edit a user's profile automaticaly. It also doesn't make sense to install a custom package just for each global function you wanted to register. You could do that, but you'd then have a billion highly targetted packages in your solution.
17+
18+
With SolutionScripts you can check in custom scripts in the `SolutionScripts` directory (which by convention sits at the same level as the packages directory). SolutionScripts will run them every time you load up the solution. If you want to refresh the scripts in the `SolutionScripts` directory without reloading the solution, just issue the `Update-SolutionScripts` command in the package manager console.
19+
20+
How?
21+
---
22+
23+
SolutionScripts looks for (or creates) a directory called `SolutionScripts` at the same level as the packages directory.
24+
25+
It looks in that directory for ps1 files. If any exist, it [dot sources](http://technet.microsoft.com/en-us/library/ee176949.aspx#ECAA) them.
26+
27+
It also looks for psm1 files (modules). If any exist, init will [import](http://technet.microsoft.com/en-us/library/dd819454.aspx) them.
28+
29+
What else?---
30+
31+
That's it, as far as SolutionScripts goes.
32+
33+
Package Manager Console Tips
34+
---
35+
36+
- If you want to see all the global functions, issue `dir function:`
37+
38+
- If you want to see all the imported modules, issue `Get-Module`

tools/init.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
param($installPath, $toolsPath, $package, $project)
2+
3+
$parentFolder = resolve-path "$package\..";
4+
$global:solutionScriptsContainer = Join-Path $parentFolder "SolutionScripts"
5+
6+
function global:Update-SolutionScripts()
7+
{
8+
if(!(test-path $solutionScriptsContainer -pathtype container))
9+
{
10+
new-item $solutionScriptsContainer -type directory
11+
}
12+
13+
$files = Get-ChildItem $solutionScriptsContainer
14+
15+
foreach ($file in $files)
16+
{
17+
if ($file.extension -eq ".ps1")
18+
{
19+
Write-Host " Sourcing: $file"
20+
. $file.fullname
21+
}
22+
if ($file.extension -eq ".psm1")
23+
{
24+
Write-Host "Importing Module: $file"
25+
Import-Module $file.fullname -Force
26+
}
27+
}
28+
}
29+
30+
Update-SolutionScripts

0 commit comments

Comments
 (0)