Unable to build project from PowerShell

Asked 2 years ago, Updated 2 years ago, 79 views


From PowerShell the specified project in the solution I would like to build via VisualStudio.DTE.
It doesn't work
I probably need to go down the hierarchy of solution folders in the solution
I don't know how to do it

The solution consists of:
Solution Folder
│ -- Project 1 folder
│ │Yes -Project.csproj
│ <
│ -- Project 2 folder
│ --Projec2.csproj
<
--Solution.sln
--Build.ps1

Here's the code:

$VSDTE=New-Object-ComObject VisualStudio.DTE
$VSDTE.MainWindow.Visible=$True
$VSDTE.Solution.Open("$PSScriptRoot\○○○○.sln")
foreach ($prj in $VSDTE.Solution.Projects)
{
    // I want to get out of the hierarchy here.
    $VSDTE.Solution.SolutionBuild.BuildProject("Release", $prj.UniqueName, $true)
}

$VSDTE.Quit()
System.Runtime.Interopservices.Marshal :: ReleaseComObject($VSDTE)

Reference
MicroSoft Docs EnvDTE Namespace

visual-studio powershell

2022-09-29 21:34

1 Answers

You can get the path to MSBuild by using vswhere, which is not a question.For your information – nee 2 days ago

We have decided to deal with it this time
Thank you all for your reply


2022-09-29 21:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.