Whenever I start a project I want to install the NuGet packages Elmah, Glimpse, MvcScaffolding, Squishit and … – well those are the ones I am aware of. Maybe I should be installing others as well?
Anyway, instead of having to remember all these it would be good to put this all in a script and all I have to do is run that. However, this is the first time I have come into contact with PowerShell and I am not sure how to do this.
I have looked at an example project and the script looks simple enough, but I am confused as to why there is a need to install the package with a .test suffix? Why also the -Project parameter?
For example,
Install-Package SqlServerCompact -Project MileageStats.Data.SqlCe
Install-Package SqlServerCompact -Project MileageStats.Data.SqlCe.tests
I have done a Google search to find out more, but I think I am looking in the wrong places.
Creating a project template with the required NuGet packages, as Fabrice has already suggested, is probably the approach I would take. To get the latest versions of the NuGet packages you could use the NuGet Package Updater package. That would get around the project template currently only supporting installing a specific version of a NuGet package.
Alternatively you can store useful PowerShell scripts inside the NuGet profile. Create a file called NuGet_profile.ps1 in the %UserProfile%\Documents\WindowsPowerShell directory (e.g. C:\Users[YourUserName]\Documents\WindowsPowerShell\NuGet_profile.ps1).
Inside the NuGet_profile.ps1 you can add PowerShell functions that you can call from the Package Manager Console window inside Visual Studio. You will need to restart Visual Studio before the functions can be called. An example NuGet_profile.ps1 file is shown below.
Now with these functions defined you could run the following in the Package Manager Console to install elmah and SqlServerCompact into a project called MyProject.
Or you could install elmah and SqlServerCompact into all projects in the currently open solution by running the following in the Package Manager Console.
The -ProjectName parameter in the Install-Package command is used to specify the name of the project that the package will be installed into. The tests suffix looks like it is part of the name of the project containing unit tests.