I am hoping to leverage powershell in visual studio to add multiple files that have been dropped in a project directory to the project. I have tried a few things to get this going, using hints found in this thread but am still running into a wall.
This first attempt looks in the solution directory for any .cs files and tries to add them to the solution (not sure if that is really correct, as I want them added to the project, not the solution).
Split-Path -Parent -Path $dte.Solution.FullName | '
Get-ChildItem -Include @("*.cs") -Recurse | '
%{ [string]$_.FullName; $dte.Solution.AddFromFile([string]$_.FullName) }
This throws an error: Exception calling "AddFromFile" with "1" argument(s): "The template specified cannot be found. Please check that the full path is correct." I am writing out the path to the file before I add it so I am able to verify that it is the correct path.
I have also tried to use ExecuteCommand to add an existing item to the project thusly
Split-Path -Parent -Path $dte.Solution.FullName | '
Get-ChildItem -Include @("*.cs") -Recurse | '
%{ $dte.ExecuteCommand("Project.AddExistingItem", $_.FullName) }
The error here is: Exception calling "ExecuteCommand" with "2" argument(s): "Command "Project.AddExistingItem" does not accept arguments or switches."
Has anyone tried to do something similar and had success?