Skip to content

Commit f3fb03b

Browse files
committed
.
1 parent da2ceae commit f3fb03b

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

buildTransitive/EmptyFiles.targets

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
3-
<ItemGroup Condition="$(DesignTimeBuild) != true">
4-
<ContentWithTargetPath
5-
Include="$(MSBuildThisFileDirectory)..\files\**\*.*"
6-
CopyToOutputDirectory="PreserveNewest"
7-
TargetPath="EmptyFiles\%(RecursiveDir)%(Filename)%(Extension)" />
8-
</ItemGroup>
3+
<PropertyGroup>
4+
<EmptyFilesSourcePath>$(MSBuildThisFileDirectory)..\files</EmptyFilesSourcePath>
5+
<EmptyFilesTargetPath>$(OutDir)EmptyFiles</EmptyFilesTargetPath>
6+
<EmptyFilesMarker>$(EmptyFilesTargetPath)\.copied</EmptyFilesMarker>
7+
</PropertyGroup>
8+
9+
<Target Name="CopyEmptyFilesIncremental"
10+
BeforeTargets="Build"
11+
Condition="$(DesignTimeBuild) != true"
12+
Inputs="$(MSBuildThisFileFile)"
13+
Outputs="$(EmptyFilesMarker)">
14+
15+
<ItemGroup>
16+
<EmptyFilesToCopy Include="$(EmptyFilesSourcePath)\**\*.*" />
17+
</ItemGroup>
18+
19+
<Copy SourceFiles="@(EmptyFilesToCopy)"
20+
DestinationFiles="@(EmptyFilesToCopy->'$(EmptyFilesTargetPath)\%(RecursiveDir)%(Filename)%(Extension)')"
21+
SkipUnchangedFiles="true" />
22+
23+
<Touch Files="$(EmptyFilesMarker)" AlwaysCreate="true" />
24+
</Target>
925
</Project>

src/EmptyFiles/EmptyFileTargets.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
How it works:
2+
3+
1. Inputs="$(MSBuildThisFileFile)" - Tracks the package file timestamp
4+
2. Outputs="$(EmptyFilesMarker)" - Tracks a marker file in the output directory
5+
3. MSBuild automatically skips the target if all outputs are newer than all inputs
6+
4. SkipUnchangedFiles="true" - Additional optimization to skip individual unchanged files
7+
5. Touch - Updates the marker file timestamp after successful copy
8+
9+
This will only copy files when:
10+
11+
1. The targets is newer than the marker file, OR
12+
2. The marker file doesn't exist (first build/clean build)
13+
14+
Benefits:
15+
16+
* Dramatically reduces IO on incremental builds
17+
* Works with dotnet clean (removes marker file)
18+
* Still respects individual file changes via SkipUnchangedFiles

0 commit comments

Comments
 (0)