How do I force MSBuild to clean or rebuild?

后端 未结 3 1520
北恋
北恋 2021-02-12 03:28

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:



        
相关标签:
3条回答
  • 2021-02-12 03:53

    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.

    0 讨论(0)
  • 2021-02-12 03:55

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

    0 讨论(0)
  • 2021-02-12 04:04

    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.

    0 讨论(0)
提交回复
热议问题