File tree Expand file tree Collapse file tree 2 files changed +40
-6
lines changed
Expand file tree Collapse file tree 2 files changed +40
-6
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments