Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. Visual Studio:Adding project file via Power Console is failing

Visual Studio:Adding project file via Power Console is failing

Scheduled Pinned Locked Moved Visual Studio
visual-studiocsharpcomlinuxjson
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Farrukhw
    wrote on last edited by
    #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

    L 1 Reply Last reply
    0
    • F Farrukhw

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      F 1 Reply Last reply
      0
      • L Lost User

        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

        F Offline
        F Offline
        Farrukhw
        wrote on last edited by
        #3

        Thanks Richard. Actually I tried with both but getting same result :^)

        L 1 Reply Last reply
        0
        • F Farrukhw

          Thanks Richard. Actually I tried with both but getting same result :^)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          F 2 Replies Last reply
          0
          • L Lost User

            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

            F Offline
            F Offline
            Farrukhw
            wrote on last edited by
            #5

            First I tried with full path. Then I did "CD C:\Projects" and then given only the file name. But same error happened.

            L 1 Reply Last reply
            0
            • F Farrukhw

              First I tried with full path. Then I did "CD C:\Projects" and then given only the file name. But same error happened.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              OK, one last suggestion, try:

              $DTE.Solution.AddFromFile("full path to csproj file", 0);

              Veni, vidi, abiit domum

              1 Reply Last reply
              0
              • L Lost User

                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

                F Offline
                F Offline
                Farrukhw
                wrote on last edited by
                #7

                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... ;)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups