Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is incremental clean in msbuild and when is it triggered?

Tags:

I am debugging a bug in my build process that happens occasionally but I can't directly reproduce it. I'm using msbuild with teamcity.

I have a dependency hierarchy like this:

Some.Interop.dll
   Dependency-> SharedDllABC.dll

SomeService.exe
   Depenendcy-> Some.Interop

Usually the final service exectuable gets in its release directory:

Some.Interop
SharedDllABC.Dll
ServiceExectuable.exe

However I can see in our msbuild logs that sometimes the tertiary dependency gets deleted during an Incremental Clean after everything is built resulting in:

Some.Interop
ServiceExectuable.exe

You can see it here in the msbuild log:

[src\SomeService\SomeService.csproj] _TimeStampAfterCompile
[12:32:43]:  [src\SomeService\SomeService.csproj] Compile

// some other targets

[12:32:43]:  [src\SomeService\SomeService.csproj] _CopyFilesMarkedCopyLocal
[12:32:43]:      [_CopyFilesMarkedCopyLocal] Copy
[12:32:43]:          [Copy] Copying file from "C:Projects\trunk\src\Some.Interop\bin\Release\Some.Interop.dll" to "bin\Release\Some.Interop.dll".

// some other targets

[src\Project\SomeService\SomeService.csproj] IncrementalClean
[18:54:42]:         [IncrementalClean] Delete
[18:54:42]:             [Delete] Deleting file "C:\Projects\trunk\src\Project\SomeService\bin\Release\SharedDllABC.dll".
[18:54:42]:             [Delete] Deleting file "C:\Projects\trunk\src\Project\SomeServiceService\bin\Release\SharedDllABC.pdb".
[18:54:42]:     [src\Project\SomeService\SomeService.csproj] CoreBuild
[18:54:42]:     [src\Project\SomeService\SomeService.csproj] AfterBuild
[18:54:42]:     [src\Project\SomeService\SomeService.csproj] Build

This is my direct msbuild output, I just changed the project names/dll names to match my example. By the time this Incremental Clean has occurred the SomeService.csproj has already been built. You can see that its not getting copied. However in other msbuild logs it does properly get copied and then the incremental clean doesn't delete it.

I think incrementeal clean from this post is supposed to clean dll's that were created from previous builds, but that doesn't explain how this dll didn't get built when most of the time it does. In visual studio this always works as well.

I guess I just want to know what exactly is Incremental clean, what causes it to kick in, and maybe what things I should look for when debugging a situation like this (assembly versions, timestamps, etc?)

like image 628
devshorts Avatar asked Jun 28 '12 21:06

devshorts


People also ask

How does incremental build work?

The incremental build model is a method of software development where the product is designed, implemented and tested incrementally (a little more is added each time) until the product is finished. It involves both development and maintenance.

What does MSBuild clean do?

When you clean a build, all intermediate and output files are deleted, leaving only the project and component files. From the project and component files, new instances of the intermediate and output files can then be built.

Will MSBuild compile a file without any target?

If MSBuild determines that any output files are out of date with respect to the corresponding input file or files, then MSBuild executes the target. Otherwise, MSBuild skips the target. After the target is executed or skipped, any other target that lists it in an AfterTargets attribute is run.

What are targets in MSBuild?

A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.


2 Answers

Try the following:

Add:

<Target Name="IncrementalClean" />

to a .targets file that's included in all projects.

From --> https://github.com/Microsoft/msbuild/issues/1054

like image 92
ListenFirst Avatar answered Oct 12 '22 01:10

ListenFirst


@Kebabbi recommends a good fix by editing a csproj file. As of MSBuild 15, there is a simple way to make this apply to all CSPROJ files, instead of editing each csproj file.

https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2017

Directory.Build.props and Directory.Build.targets Prior to MSBuild version 15, if you wanted to provide a new, custom property to projects in your solution, you had to manually add a reference to that property to every project file in the solution. Or, you had to define the property in a .props file and then explicitly import the .props file in every project in the solution, among other things.

However, now you can add a new property to every project in one step by defining it in a single file called Directory.Build.props in the root folder that contains your source. When MSBuild runs, Microsoft.Common.props searches your directory structure for the Directory.Build.props file (and Microsoft.Common.targets looks for Directory.Build.targets). If it finds one, it imports the property. Directory.Build.props is a user-defined file that provides customizations to projects under a directory.

Create a file Directory.Build.props, and place it adjacent to the SLN file.

<Project>
   <Target
     Name="ForceAssignProjectConfigurationBeforeSplitProjectReferencesByFileExistence_KLUDGE" 
     BeforeTargets="_SplitProjectReferencesByFileExistence" 
     DependsOnTargets="AssignProjectConfiguration" />
</Project>
like image 38
JJS Avatar answered Oct 12 '22 01:10

JJS