VisualStudio.DTE.Solution is null using Activator::CreateInstance
-
22-12-2019 - |
Question
I am running the following code in PowerShell ISE:
$scriptDirectory = "C:\Test"
$dteObj = [System.Activator]::CreateInstance([System.Type]::GetTypeFromProgId("VisualStudio.DTE.10.0"))
$slnName = "All"
$dteObj.Solution.Create($scriptDirectory, $slnName)
I get the error:
You cannot call a method on a null-valued expression.
At C:\DevHome\TFS\CreateMasterSolution.ps1:8 char:1
+ $dteObj.Solution.Create($scriptDirectory, $slnName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Why is the Solution Property on this COM Object always "null"? Is there something I am forgetting to do?
Solution 2
Seems that if you replace the above with the following it works:
$dteObj = New-Object -ComObject "VisualStudio.DTE.10.0"
OTHER TIPS
In Addition to that do also:
$solution = $dteObj.Solution
$solution.Open("<path to your solution>")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow