I want to add solution folders and solution items (not projects) to a solution file via a NuGet package. I imagine this would be accomplished through Powershell. I've looked through the documentation for NuGet, Powershell, and EnvDTE and can't figure out:
- Which commands/methods I would use?
- Which standard script I would do this in, Init.ps1, Install.ps1, or somewhere else?
Here is a PowerShell script that will create a solution folder called Parent and another solution folder called Child inside that one. It also adds a project file (MyProject.csproj) inside the Child solution folder.
The two main Visual Studio interfaces being used here are Solution2 and SolutionFolder. It also uses the Get-Interface function which is provided by NuGet.
For a solution-only package you should place your script in init.ps1 because install.ps1 is only invoked for project-based packages. Init.ps1 runs once for a solution when the package is first installed and every time the solution is re-opened in Visual Studio.
To add arbitrary files (non-project files) to a solution folder you will need to do something similar to the following:
What is missing from this PowerShell script is the standard parameter declarations at the top of file.
What is also missing is checking whether the solution folder and folder item already exist. I shall leave that as an exercise for you to do.