Visual Studio:Adding project file via Power Console is failing

1

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

visual-studio-2010
powershell

2 Answers

1

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
0

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