Visual Studio:Adding project file via Power Console is failing


I've a task to add 384 existing projects in one solution in order to replace binary file dependency with project dependency and build with msbuild. To achieve this, I'm trying to use Visual Studio API in order to automate the adding of projects to a solution.

I'm actually newbie to Windows Power Shell and I'm using Power Console plugin for Visual Studio to add project (*.csproj, *.vcxproj) files in presently opened solution using $DTE.Solution.AddFromFile (, but it doesn't seems to be working. Here is the error output:

PS> $DTE.Solution.AddFromFile('WpfApplication1.csproj')
Exception calling "AddFromFile" with "2" argument(s): "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALID
At line:1 char:26
+ $DTE.Solution.AddFromFile <<<< ('WpfApplication1.csproj')
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Anyone have any tips to use Visual Studio API methods via Power Console?



2 Answers


You need to use full path to the project file. Like this:

PS> $DTE.Solution.AddFromFile('C:\Users\sv\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication2\ConsoleApplication2.csproj')
answered on Stack Overflow Sep 9, 2013 by Sergey Vlasov

While @Sergey Vlasov solved this, I also discovered this method:

$DTE.ExecuteCommand("File.AddExistingProject",'C:\Users\sv\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication2\ConsoleApplication2.csproj‌​')

That is, invoking "Add Existing Dialog" while passing file path as parameter and this also worked similarly.

answered on Stack Overflow Sep 9, 2013 by Farrukh Waheed

User contributions licensed under CC BY-SA 3.0