How do I force MSBuild to clean or rebuild?

梦想的初衷 提交于 2019-12-05 09:06:45

问题


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?


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/12494248/how-do-i-force-msbuild-to-clean-or-rebuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!