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:
Always Try to use
<MSBuild Projects="$(MSBuildProjectDirectory)\myproj.csproj"
Targets="Clean;Build"
Properties="OutputPath=$(MSBuildProjectDirectory)\..\bin\" />
Because according to this MSDN article, when you have multiple projects in your solution using "Rebuild" as the target, may cause clean and build to happen in parallel manner. Which may cause problems in project dependencies.
But when you use "Clean and Build" as the target, build will start only after all the projects are cleaned.
"%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.