Skip to content

Commit a8f3bd6

Browse files
authored
Avoid file io (#199)
1 parent b3c6746 commit a8f3bd6

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-5
lines changed

buildTransitive/EmptyFiles.targets

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project>
3+
<PropertyGroup>
4+
<EmptyFilesSourcePath>$(MSBuildThisFileDirectory)..\files</EmptyFilesSourcePath>
5+
</PropertyGroup>
6+
7+
<Target Name="CopyEmptyFilesIncremental"
8+
AfterTargets="Build"
9+
Condition="$(DesignTimeBuild) != true"
10+
Inputs="$(MSBuildThisFileFullPath)"
11+
Outputs="$(IntermediateOutputPath)EmptyFiles.copied">
12+
13+
<PropertyGroup>
14+
<EmptyFilesTargetPath>$(TargetDir)EmptyFiles</EmptyFilesTargetPath>
15+
<EmptyFilesMarker>$(IntermediateOutputPath)EmptyFiles.copied</EmptyFilesMarker>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<EmptyFilesToCopy Include="$(EmptyFilesSourcePath)\**\*.*" />
20+
</ItemGroup>
21+
22+
<Message Text="Copying EmptyFiles to $(EmptyFilesTargetPath)" Importance="high" />
23+
24+
<MakeDir Directories="$(EmptyFilesTargetPath)" />
25+
26+
<Copy SourceFiles="@(EmptyFilesToCopy)"
27+
DestinationFiles="@(EmptyFilesToCopy->'$(EmptyFilesTargetPath)\%(RecursiveDir)%(Filename)%(Extension)')"
28+
SkipUnchangedFiles="true" />
29+
30+
<Touch Files="$(EmptyFilesMarker)" AlwaysCreate="true" />
31+
</Target>
32+
</Project>

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project>
33
<PropertyGroup>
44
<NoWarn>CS1591;CS0649;NU5119;NU1608;NU1109</NoWarn>
5-
<Version>8.17.0</Version>
5+
<Version>8.17.1</Version>
66
<LangVersion>preview</LangVersion>
77
<AssemblyVersion>1.0.0</AssemblyVersion>
88
<Description>A collection of minimal binary files.</Description>

src/EmptyFiles.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Solution>
22
<Folder Name="/Solution Items/">
33
<File Path="../.gitattributes" />
4+
<File Path="../buildTransitive/EmptyFiles.targets" />
45
<File Path="../readme.md" />
56
<File Path=".editorconfig" />
67
<File Path="appveyor.yml" />

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

src/EmptyFiles/EmptyFiles.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<PackageReference Include="System.ValueTuple" Condition="'$(TargetFramework)' == 'net462'" />
1313
<PackageReference Include="Polyfill" PrivateAssets="all" />
1414
<PackageReference Include="Microsoft.Sbom.Targets" PrivateAssets="all" />
15-
<None Include="..\EmptyFiles.targets" Pack="True" PackagePath="build\EmptyFiles.targets" CopyToOutputDirectory="PreserveNewest" />
16-
<None Include="..\EmptyFiles.targets" Pack="True" PackagePath="buildTransitive\EmptyFiles.targets" CopyToOutputDirectory="PreserveNewest" />
17-
<None Include="$(ProjectDir)..\..\files\**\empty.*">
15+
<None Include="$(SolutionDir)..\buildTransitive\EmptyFiles.targets" Pack="True" PackagePath="build\EmptyFiles.targets" CopyToOutputDirectory="PreserveNewest" />
16+
<None Include="$(SolutionDir)..\buildTransitive\EmptyFiles.targets" Pack="True" PackagePath="buildTransitive\EmptyFiles.targets" CopyToOutputDirectory="PreserveNewest" />
17+
<None Include="$(SolutionDir)..\files\**\empty.*">
1818
<Pack>true</Pack>
1919
<PackagePath>files</PackagePath>
2020
</None>

src/Tests/Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
<Using Include="NUnit.Framework.Legacy.ClassicAssert" Static="True" />
1717
<Using Include="NUnit.Framework.Assert" Static="True" />
1818
</ItemGroup>
19-
<Import Project="$(ProjectDir)..\EmptyFiles.targets" />
19+
<Import Project="$(SolutionDir)..\buildTransitive\EmptyFiles.targets" />
2020
</Project>

0 commit comments

Comments
 (0)