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

4

2 回答 2

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')
于 2013-09-09T04:09:10.280 回答
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.

于 2013-09-09T09:42:43.153 回答