Entity Framework and Nuget both do this. They add powershell commandlets that can be launched from the visual studio package manager console.
It would be really great if I could write some project-centric utilities that could be committed to my source control and be available for all developers from that console.
How do I do this?
Note that I'm not looking for a 3rd party solution (eg StudioShell), and that I'm aware that I can just write normal powershell scripts to do many things. I'm interested specifically in how to write functions that are first-class citizens in the Visual Studio package manager console like Get-Package
and Update-Database
.
EntityFramework's integration is done via NuGet, so you can't really have it in a project in your solution easily. You'd have to go through a NuGet package. Although, you could probably make it work using a local folder for the package. Essentially, EF includes a normal powershell module in its package's tools folder along with an init.ps1
that loads the module. Its contents:
param($installPath, $toolsPath, $package, $project)
if (Get-Module | ?{ $_.Name -eq 'EntityFramework' })
{
Remove-Module EntityFramework
}
Import-Module (Join-Path $toolsPath EntityFramework.psd1)
init.ps1
is run by NuGet/VS when opening the solution file. From the NuGet docs:
Init.ps1 runs the first time a package is installed in a solution.
* If the same package is installed into additional projects in the solution, the script is not run during those installations.
* The script also runs every time the solution is opened (Package Manager Console window has to be open at the same for the script to run). For example, if you install a package, close Visual Studio, and then start Visual Studio and open the solution with Package Manager Console window, the Init.ps1 script runs again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With