Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running the Clean, Build and Rebuild through the Package Manager Console

I want to run the Clean, Build and Rebuild commands through the Package Manager Console in Visual Studio but so far I haven't been able to find how.

The following command gets me the first project inside the solution:

$project = Get-Project | select -First 1

When I run the $project | Get-Member, I can see the members of $project item.

#Members of the $project ($project | Get-Member)

#   TypeName: System.__ComObject#{866311e6-c887-4143-9833-645f5b93f6f1}
#
#Name                 MemberType            Definition                                                                                                                                   
#----                 ----------            ----------                                                                                                                                   
#ProjectName          CodeProperty          System.String ProjectName{get=GetCustomUniqueName;}                                                                                          
#Delete               Method                void Delete ()                                                                                                                               
#Save                 Method                void Save (string)                                                                                                                           
#SaveAs               Method                void SaveAs (string)                                                                                                                         
#Extender             ParameterizedProperty IDispatch Extender (string) {get}                                                                                                            
#CodeModel            Property              CodeModel CodeModel () {get}                                                                                                                 
#Collection           Property              Projects Collection () {get}                                                                                                                 
#ConfigurationManager Property              ConfigurationManager ConfigurationManager () {get}                                                                                           
#DTE                  Property              DTE DTE () {get}                                                                                                                             
#ExtenderCATID        Property              string ExtenderCATID () {get}                                                                                                                
#ExtenderNames        Property              Variant ExtenderNames () {get}                                                                                                               
#FileName             Property              string FileName () {get}                                                                                                                     
#FullName             Property              string FullName () {get}                                                                                                                     
#Globals              Property              Globals Globals () {get}                                                                                                                     
#IsDirty              Property              bool IsDirty () {get} {set}                                                                                                                  
#Kind                 Property              string Kind () {get}                                                                                                                         
#Name                 Property              string Name () {get} {set}                                                                                                                   
#Object               Property              IDispatch Object () {get}                                                                                                                    
#ParentProjectItem    Property              ProjectItem ParentProjectItem () {get}                                                                                                       
#ProjectItems         Property              ProjectItems ProjectItems () {get}                                                                                                           
#Properties           Property              Properties Properties () {get}                                                                                                               
#Saved                Property              bool Saved () {get} {set}                                                                                                                    
#UniqueName           Property              string UniqueName () {get}                                                                                                                   
#Type                 ScriptProperty        System.Object Type {get=switch ($this.Kind) {...       

I am not sure if I can get to the Clean Build and Rebuild method through the $project item or if I should I directly run the msbuild by targeting the project path.

Any idea?

like image 402
tugberk Avatar asked Aug 27 '12 07:08

tugberk


People also ask

How do I clean my Package Manager console?

Open Visual Studio, go to Tools -> NuGet Package Manager -> Package Manager Settings menu. Click Clear All NuGet Cache(s) button in options dialog then clearing process is started. Once NuGet cache location is cleared, click ok button.

Is rebuild the same as clean and build?

For a multi-project solution, "rebuild solution" does a "clean" followed by a "build" for each project (possibly in parallel). Whereas a "clean solution" followed by a "build solution" first cleans all projects (possibly in parallel) and then builds all projects (possibly in parallel).

What is build rebuild and clean solution in Visual Studio?

To build, rebuild, or clean an entire solutionChoose Rebuild All to "clean" the solution and then builds all project files and components. Choose Clean All to delete any intermediate and output files. With only the project and component files left, new instances of the intermediate and output files can then be built.

How do you clean the build command?

The clean build command refers to the command that you would run to rebuild your C/C++ project from scratch (ie it would first clean all possible past artifacts (already compiled files etc…) and rebuild everything. This command can be anything.


1 Answers

Visual Studio's object model provides a way to build the entire solution or a single project via the SolutionBuild object.

Building the solution is straightforward from the NuGet Package Manager Console.

$dte.Solution.SolutionBuild.Clean($true)
$dte.Solution.SolutionBuild.Build($true)

The $true flag indicates that the command should wait for the clean/build to finish.

Building an individual project is not as straightforward. The SolutionBuild object provides a BuildProject method which takes three parameters.

$project = Get-Project | select -First 1
$dte.Solution.SolutionBuild.BuildProject("Debug", $project.FullName, $true)

It also does not allow you to run a Clean build.

If you want to build an individual project then, as Pavel suggests, using MSBuild seems to be more straighforward.

like image 105
Matt Ward Avatar answered Oct 17 '22 15:10

Matt Ward