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 (http://msdn.microsoft.com/en-us/library/envdte80.solutionfolder.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 ARG))" 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? Farrukh -
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 (http://msdn.microsoft.com/en-us/library/envdte80.solutionfolder.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 ARG))" 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? Farrukh -
Parameter 1 should be a string as described in the documentation[^]. That means it requires double quotes as terminators, you have single quotes.
Veni, vidi, abiit domum
-
Did you read the documentation? It statesthat parameter 1 is Required. The full path and file name of the project file.. Your sample contains no path information.
Veni, vidi, abiit domum
-
First I tried with full path. Then I did "CD C:\Projects" and then given only the file name. But same error happened.
-
Did you read the documentation? It statesthat parameter 1 is Required. The full path and file name of the project file.. Your sample contains no path information.
Veni, vidi, abiit domum
Richard, Some how this worked fine as replied by another member at stackoverflow:
$DTE.Solution.AddFromFile('C:\Users\sv\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication2\ConsoleApplication2.csproj')
In the mean time, I also discovered this as a working solution:
$DTE.ExecuteCommand("File.AddExistingProject",'C:\Users\sv\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication2\ConsoleApplication2.csproj')
So now both are working in similar way for me. Thanks a bunch for your efforts... ;)