Skip to content

Commit 34143c0

Browse files
KirillOsenkovCopilot
authored andcommitted
Make copying project templates incremental (#11164)
Use item transforms to specify destination item paths Declare Inputs and Outputs on targets that copy templates to obj Set WriteLinesToFile.WriteOnlyWhenDifferent
1 parent acb8eee commit 34143c0

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

src/Aspire.ProjectTemplates/Aspire.ProjectTemplates.csproj

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,38 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22+
<!-- see https://github.com/dotnet/aspire/pull/1225 -->
2223
<None Include="templates\**\*" />
2324
</ItemGroup>
2425

26+
<ItemGroup>
27+
<TemplateProjectFiles Include="$(MSBuildThisFileDirectory)templates\**\*.csproj">
28+
<PackagePath>content/templates/%(RecursiveDir)</PackagePath>
29+
<DestinationFile>$(IntermediateOutputPath)content\templates\%(RecursiveDir)%(Filename)%(Extension)</DestinationFile>
30+
</TemplateProjectFiles>
31+
<TemplateProjectFilesObj Include="@(TemplateProjectFiles->'%(DestinationFile)')" />
32+
33+
<TemplateFiles Include="$(MSBuildThisFileDirectory)templates\**\*"
34+
Exclude="$(MSBuildThisFileDirectory)templates\**\bin\**;$(MSBuildThisFileDirectory)templates\**\obj\**;$(MSBuildThisFileDirectory)templates\**\*.csproj">
35+
<PackagePath>content/templates/%(RecursiveDir)</PackagePath>
36+
</TemplateFiles>
37+
<TemplateFilesObj Include="@(TemplateFiles->'$(IntermediateOutputPath)content\templates\%(RecursiveDir)%(Filename)%(Extension)')" />
38+
</ItemGroup>
39+
2540
<!-- When building a package, this target will run to copy all the templates into the intermediate directory,
2641
replaces the package versions, and adds them to the package.-->
2742
<Target Name="AddTemplatesToPackageAsContent"
2843
DependsOnTargets="ReplacePackageVersionOnTemplates">
29-
30-
<!-- Creating a temporary item instead of defining content items directly in order to avoid MSBuild MSB4120
31-
message shown when an item within a target references itself which may cuase unintended expansion. -->
32-
<ItemGroup>
33-
<_TemplatesForPackage Include="$(IntermediateOutputPath)\content\templates\**\*" />
34-
</ItemGroup>
3544
<ItemGroup>
36-
<Content Include="%(_TemplatesForPackage.Identity)"
37-
PackagePath="content/templates/%(_TemplatesForPackage.RecursiveDir)" />
45+
<Content Include="@(TemplateFilesObj);@(TemplateProjectFilesObj)" />
3846
</ItemGroup>
3947
</Target>
4048

4149
<!-- Replaces the versions referenced by the templates projects to use the version of the packages being live-built -->
4250
<Target Name="ReplacePackageVersionOnTemplates"
43-
DependsOnTargets="CopyTemplatesToIntermediateOutputPath">
44-
45-
<ItemGroup>
46-
<TemplateProjectFiles Include="templates\**\*.csproj" />
47-
<TemplateProjectFiles>
48-
<DestinationFile>$(IntermediateOutputPath)\content\templates\%(RecursiveDir)%(Filename)%(Extension)</DestinationFile>
49-
</TemplateProjectFiles>
50-
</ItemGroup>
51+
DependsOnTargets="CopyTemplatesToIntermediateOutputPath"
52+
Inputs="@(TemplateProjectFiles)"
53+
Outputs="@(TemplateProjectFilesObj)">
5154

5255
<WriteLinesToFile File="%(TemplateProjectFiles.DestinationFile)"
5356
Lines="$([System.IO.File]::ReadAllText('%(TemplateProjectFiles.FullPath)')
@@ -61,19 +64,18 @@
6164
.Replace('!!REPLACE_WITH_OTEL_ASPNETCORE_VERSION!!', '$(OpenTelemetryInstrumentationAspNetCoreVersion)')
6265
.Replace('!!REPLACE_WITH_OTEL_HTTP_VERSION!!', '$(OpenTelemetryInstrumentationHttpVersion)')
6366
.Replace('!!REPLACE_WITH_OTEL_RUNTIME_VERSION!!', '$(OpenTelemetryInstrumentationRuntimeVersion)') )"
67+
WriteOnlyWhenDifferent="True"
6468
Overwrite="true" />
6569
</Target>
6670

6771
<!-- Grabs the contents of the templates folder and copies them to IntermediateOutputPath directory -->
68-
<Target Name="CopyTemplatesToIntermediateOutputPath">
69-
70-
<ItemGroup>
71-
<_ContentFilesToPackage Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**;templates\**\*.csproj" />
72-
</ItemGroup>
72+
<Target Name="CopyTemplatesToIntermediateOutputPath"
73+
Inputs="@(TemplateFiles)"
74+
Outputs="@(TemplateFilesObj)">
7375

74-
<Copy SourceFiles="@(_ContentFilesToPackage)"
75-
SkipUnchangedFiles="true"
76-
DestinationFolder="$(IntermediateOutputPath)\content\templates\%(RecursiveDir)" />
76+
<Copy SourceFiles="@(TemplateFiles)"
77+
DestinationFiles="@(TemplateFilesObj)"
78+
SkipUnchangedFiles="true" />
7779
</Target>
7880

7981
</Project>

0 commit comments

Comments
 (0)