How do I force MSBuild to clean or rebuild?
Asked Answered
F

3

40

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?

Florous answered 19/9, 2012 at 11:57 Comment(1)
What file is this?Offutt
A
37

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.

Allanson answered 19/9, 2012 at 14:10 Comment(2)
Seems obvious when you see the answer. Should prob have got that one. Thanks for the answerFlorous
How about the new csproj?Bleach
M
54

"%windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild" Project.sln /p:Configuration=Release /t:Rebuild

Muzhik answered 7/5, 2015 at 20:58 Comment(3)
In the question, msbuild is used in a project file. Not directly in the command prompt.Commonable
In question "I am using msbuild from a script to compile my project" from a script better use command promptMuzhik
Whether or not it answers the original question, the snippet helped me get where I needed to go.. thanks!Camire
A
37

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.

Allanson answered 19/9, 2012 at 14:10 Comment(2)
Seems obvious when you see the answer. Should prob have got that one. Thanks for the answerFlorous
How about the new csproj?Bleach
U
1

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.

Unmindful answered 2/8, 2017 at 7:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.