I am using MSBuild from a script to compile my project. I have noticed that it just does a build and not a clean/rebuild.
I have the following:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0"> <Target Name="Build"> <MSBuild Projects="$(MSBuildProjectDirectory)\myproj.csproj" Targets="Build" Properties="OutputPath=$(MSBuildProjectDirectory)\..\bin\" /> </Target>
How do I force a clean/rebuild?
Cleaning up specific projects: msbuild MyProjectFile1 /t:Clean msbuild MyProjectFile2 /t:Clean ... This has to be repeated for all projects you need to clean, because MSBuild only accepts single project on command line.
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).
To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.
"%windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild" Project.sln /p:Configuration=Release /t:Rebuild
Change
<MSBuild Projects="$(MSBuildProjectDirectory)\myproj.csproj" Targets="Build" Properties="OutputPath=$(MSBuildProjectDirectory)\..\bin\" />
to
<MSBuild Projects="$(MSBuildProjectDirectory)\myproj.csproj" Targets="Clean;Build" Properties="OutputPath=$(MSBuildProjectDirectory)\..\bin\" />
or
<MSBuild Projects="$(MSBuildProjectDirectory)\myproj.csproj" Targets="Rebuild" Properties="OutputPath=$(MSBuildProjectDirectory)\..\bin\" />
For more details, look at the MSBuild Task documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With