DTE type loaded in Console

Sep 24, 2010 at 8:09 PM

I am trying to do some Package Console Automation against the DTE.  I think the following code should work...

 

PM> [System.Reflection.Assembly]::LoadWithPartialName("EnvDTE80")
GAC    Version        Location                                                                                                                                                                                  ---    -------        --------                                                                                                                                                                                  True   v1.0.3705      C:\Windows\assembly\GAC\EnvDTE80\8.0.0.0__b03f5f7f11d50a3a\EnvDTE80.dll                                                                                                                   

PM> $dte2 = [EnvDTE80.DTE2]$dteCannot convert the "EnvDTE.DTEClass" value of type "EnvDTE.DTEClass" to type "EnvDTE80.DTE2".At line:1 char:28+ $dte2 = [EnvDTE80.DTE2]$dte <<<<     + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException    + FullyQualifiedErrorId : RuntimeException

Sep 24, 2010 at 9:26 PM

This is a known issue of how PowerShell interacts with COM object. To achive what you are doing, try this:

$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])

Get-Interface is a helper function added by the PowerShell host.

Sep 24, 2010 at 9:28 PM

Btw, we should document this as an entry in the FAQ.

Coordinator
Sep 24, 2010 at 9:30 PM

Feel free. J

Sep 24, 2010 at 9:51 PM
Thanks,, I actually found this in the nupack.ps1.. I am putting together a full example on top of this.. I am put this in the FAQ.
 
On Fri, Sep 24, 2010 at 3:26 PM, dotnetjunky <notifications@codeplex.com> wrote:

From: dotnetjunky

This is a known issue of how PowerShell interacts with COM object. To achive what you are doing, try this:

$dte2 = Get-Interface $dte ([EnvDTE80.DTE2])

Get-Interface is a helper function added by the PowerShell host.

Read the full discussion online.

To add a post to this discussion, reply to this email (nupack@discussions.codeplex.com)

To start a new discussion for this project, email nupack@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Sep 24, 2010 at 9:59 PM

I've already added it to the FAQ.

Sep 24, 2010 at 10:11 PM

OK.. this was not as bad as I thought it could be..  here is the code to progrmatically create a test project for a MVC project.

$sln = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
$templatePath = $sln.GetProjectTemplate("ClassLibrary.zip","CSharp")
$path = split-path $sln.filename
$sln.AddFromTemplate($templatePath, $path+"\tests","tests")
update-defaultproject "tests"
add-package nunit
add-package rhinomocks
add-package mvccontrib-testhelper