-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Microsoft.NET.Sdk.StaticWebAssets.ServiceWorker.targets
330 lines (275 loc) · 15.3 KB
/
Microsoft.NET.Sdk.StaticWebAssets.ServiceWorker.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!--
***********************************************************************************************
Microsoft.NET.Sdk.BlazorWebAssembly.ServiceWorker.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project>
<UsingTask
TaskName="Microsoft.AspNetCore.StaticWebAssets.Tasks.GenerateServiceWorkerAssetsManifest"
AssemblyFile="$(StaticWebAssetsSdkBuildTasksAssembly)"
Condition="'$(StaticWebAssetsSdkBuildTasksAssembly)' != ''" />
<UsingTask
TaskName="Microsoft.AspNetCore.StaticWebAssets.Tasks.UpdateServiceWorkerFileWithVersion"
AssemblyFile="$(StaticWebAssetsSdkBuildTasksAssembly)"
Condition="'$(StaticWebAssetsSdkBuildTasksAssembly)' != ''" />
<PropertyGroup>
<!--
ResolveBuildRelatedStaticWebAssets
ResolveBuildServiceWorkerStaticWebAssets
GenerateBuildServiceWorkerStaticWebAssets
ResolveBuildServiceWorkerStaticWebAssetsConfiguration
-->
<ResolveBuildRelatedStaticWebAssetsDependsOn>
ResolveBuildServiceWorkerStaticWebAssets;
$(ResolveBuildRelatedStaticWebAssetsDependsOn)
</ResolveBuildRelatedStaticWebAssetsDependsOn>
<ResolveBuildServiceWorkerStaticWebAssetsDependsOn>
GenerateBuildServiceWorkerStaticWebAssets;
$(ResolveBuildServiceWorkerStaticWebAssetsDependsOn)
</ResolveBuildServiceWorkerStaticWebAssetsDependsOn>
<GenerateBuildServiceWorkerStaticWebAssetsDependsOn>
ResolveBuildServiceWorkerStaticWebAssetsConfiguration;
$(GenerateBuildServiceWorkerStaticWebAssetsDependsOn)
</GenerateBuildServiceWorkerStaticWebAssetsDependsOn>
<!--
ResolvePublishRelatedStaticWebAssets
ResolvePublishServiceWorkerStaticWebAssets
GeneratePublishServiceWorkerStaticWebAssets
ResolvePublishServiceWorkerStaticWebAssetsConfiguration
-->
<ResolvePublishRelatedStaticWebAssetsDependsOn>
ResolvePublishServiceWorkerStaticWebAssets;
$(ResolvePublishRelatedStaticWebAssetsDependsOn)
</ResolvePublishRelatedStaticWebAssetsDependsOn>
<ResolvePublishServiceWorkerStaticWebAssetsDependsOn>
GeneratePublishServiceWorkerStaticWebAssets;
$(ResolvePublishServiceWorkerStaticWebAssetsDependsOn)
</ResolvePublishServiceWorkerStaticWebAssetsDependsOn>
<GeneratePublishServiceWorkerStaticWebAssetsDependsOn>
ResolvePublishServiceWorkerStaticWebAssetsConfiguration;
$(GeneratePublishServiceWorkerStaticWebAssetsDependsOn)
</GeneratePublishServiceWorkerStaticWebAssetsDependsOn>
</PropertyGroup>
<!-- Build -->
<Target Name="ResolveBuildServiceWorkerStaticWebAssets" DependsOnTargets="$(ResolveBuildServiceWorkerStaticWebAssetsDependsOn)">
<DefineStaticWebAssets Condition="Exists('$(_BuildServiceWorkerFile)')"
CandidateAssets="@(_BuildServiceWorker);@(_BuildServiceWorkerManifest)"
RelativePathPattern="wwwroot/**"
SourceType="Computed"
SourceId="$(PackageId)"
ContentRoot="$(IntermediateOutputPath)service-worker\"
BasePath="$(StaticWebAssetBasePath)"
AssetMergeSource="$(StaticWebAssetMergeTarget)"
>
<Output TaskParameter="Assets" ItemName="_ServiceWorkersBuildStaticWebAsset" />
</DefineStaticWebAssets>
<DefineStaticWebAssetEndpoints
CandidateAssets="@(_ServiceWorkersBuildStaticWebAsset)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
>
<Output TaskParameter="Endpoints" ItemName="_ServiceWorkersBuildStaticWebAssetEndpoint" />
</DefineStaticWebAssetEndpoints>
<ItemGroup>
<StaticWebAsset Include="@(_ServiceWorkersBuildStaticWebAsset)" />
<StaticWebAssetEndpoint Include="@(_ServiceWorkersBuildStaticWebAssetEndpoint)" />
</ItemGroup>
</Target>
<Target Name="GenerateBuildServiceWorkerStaticWebAssets" DependsOnTargets="$(GenerateBuildServiceWorkerStaticWebAssetsDependsOn)">
<ComputeStaticWebAssetsForCurrentProject
Assets="@(_BuildAssetsForManifestCandidate)"
ProjectMode="$(StaticWebAssetProjectMode)"
AssetKind="Build"
Source="$(PackageId)"
>
<Output TaskParameter="StaticWebAssets" ItemName="_BuildAssetsForManifest" />
</ComputeStaticWebAssetsForCurrentProject>
<ComputeStaticWebAssetsTargetPaths Assets="@(_BuildAssetsForManifest)" PathPrefix="$(StaticWebAssetBasePath)" UseAlternatePathDirectorySeparator="true">
<Output TaskParameter="AssetsWithTargetPath" ItemName="_BuildAssetsForManifestWithTargetPath" />
</ComputeStaticWebAssetsTargetPaths>
<ItemGroup>
<_BuildServiceWorkItem Include="@(_BuildAssetsForManifestWithTargetPath)">
<AssetUrl>%(_BuildAssetsForManifestWithTargetPath.TargetPath)</AssetUrl>
</_BuildServiceWorkItem>
</ItemGroup>
<GenerateServiceWorkerAssetsManifest
Version="$(ServiceWorkerAssetsManifestVersion)"
Assets="@(_BuildServiceWorkItem)"
OutputPath="$(_BuildServiceWorkerManifestIntermediatePath)">
<Output TaskParameter="CalculatedVersion" PropertyName="_BuildServiceWorkerAssetsManifestVersion" />
</GenerateServiceWorkerAssetsManifest>
<UpdateServiceWorkerFileWithVersion
Condition="Exists('$(_BuildServiceWorkerSourcePath)') and '$(_BuildServiceWorkerAssetsManifestVersion)' != ''"
ServiceWorkerSource="$(_BuildServiceWorkerSourcePath)"
ServiceWorkerDestination="$(_BuildServiceWorkerFile)"
ManifestVersion="$(_BuildServiceWorkerAssetsManifestVersion)" />
<ItemGroup>
<FileWrites Include="$(_BuildServiceWorkerManifestIntermediatePath)" />
<FileWrites Include="$(_BuildServiceWorkerFile)" />
</ItemGroup>
</Target>
<Target Name="ResolveBuildServiceWorkerStaticWebAssetsConfiguration" DependsOnTargets="ResolveStaticWebAssetsInputs">
<PropertyGroup>
<_BuildServiceWorkerManifestIntermediatePath>$(IntermediateOutputPath)service-worker\$(ServiceWorkerAssetsManifest).build</_BuildServiceWorkerManifestIntermediatePath>
</PropertyGroup>
<PropertyGroup Condition="'@(ServiceWorker)' != ''">
<_BuildServiceWorkerSourcePath>%(ServiceWorker.Identity)</_BuildServiceWorkerSourcePath>
<_BuildServiceWorkerFile>$(IntermediateOutputPath)service-worker\@(ServiceWorker->'%(FileName)%(Extension)').build</_BuildServiceWorkerFile>
</PropertyGroup>
<ItemGroup Condition="'@(ServiceWorker)' != ''">
<!-- Service workers are defined as follows: <ServiceWorker Include="wwwroot\serviceworkers\my-service-worker.js" PublishedContent="wwwroot\serviceworkers\my-prod-service-worker.js" />
The item in the Include attribute indicates the "development version" of the service worker file.
The item on the PublishedContent attribute indicates the "publish version" of the service worker file.
For PWAs we need to do the following:
* At publish time, generate a file (typically service-worker-assets.js) that contains a list of resources (this is, all publish static web assets minus the assets we are about to define).
* At publish time, after generating the manifest, we'll have a "version" hash. We need to update the "publish manifest" with that version.
-->
<!-- This is the dev service worker, which is defined as a Build static web asset -->
<_BuildServiceWorker
Condition="Exists('$(_BuildServiceWorkerSourcePath)')"
Include="$(_BuildServiceWorkerFile)"
>
<OriginalItemSpec>$(_BuildServiceWorkerSourcePath)</OriginalItemSpec>
<SourceType>Computed</SourceType>
<AssetKind>Build</AssetKind>
<TargetPath>$(_BuildServiceWorkerSourcePath)</TargetPath>
<ContentRoot>$(IntermediateOutputPath)service-worker</ContentRoot>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
<AssetTraitName>BlazorServiceWorker</AssetTraitName>
<AssetTraitValue>ServiceWorkerJs</AssetTraitValue>
</_BuildServiceWorker>
<!-- This is the build service worker manifest file -->
<_BuildServiceWorkerManifest
Include="$(_BuildServiceWorkerManifestIntermediatePath)"
>
<OriginalItemSpec>$(_BuildServiceWorkerManifestIntermediatePath)</OriginalItemSpec>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
<AssetKind>Build</AssetKind>
<ContentRoot>$(IntermediateOutputPath)service-worker</ContentRoot>
<TargetPath>wwwroot\$(ServiceWorkerAssetsManifest)</TargetPath>
<AssetTraitName>BlazorServiceWorker</AssetTraitName>
<AssetTraitValue>ServiceWorkerManifest</AssetTraitValue>
</_BuildServiceWorkerManifest>
</ItemGroup>
<ItemGroup>
<_BuildAssetsForManifestCandidate Include="@(StaticWebAsset)" Condition="'%(AssetRole)' != 'Alternative' and Exists('%(Identity)')" />
<_BuildAssetsForManifestCandidate Include="@(StaticWebAsset->'%(OriginalItemSpec)')" Condition="'%(AssetRole)' != 'Alternative' and !Exists('%(Identity)')" />
</ItemGroup>
<MakeDir Directories="$(IntermediateOutputPath)service-worker" />
</Target>
<!-- Publish -->
<Target Name="ResolvePublishServiceWorkerStaticWebAssets" DependsOnTargets="$(ResolvePublishServiceWorkerStaticWebAssetsDependsOn)">
<DefineStaticWebAssets Condition="Exists('$(_PublishServiceWorkerFile)')"
CandidateAssets="@(_PublishServiceWorker);@(_PublishServiceWorkerManifest)"
RelativePathPattern="wwwroot/**"
SourceType="Computed"
SourceId="$(PackageId)"
ContentRoot="$(IntermediateOutputPath)service-worker\"
BasePath="$(StaticWebAssetBasePath)"
AssetMergeSource="$(StaticWebAssetMergeTarget)"
>
<Output TaskParameter="Assets" ItemName="_ServiceWorkersPublishStaticWebAsset" />
</DefineStaticWebAssets>
<DefineStaticWebAssetEndpoints
CandidateAssets="@(_ServiceWorkersPublishStaticWebAsset)"
ExistingEndpoints="@(StaticWebAssetEndpoint)"
ContentTypeMappings="@(StaticWebAssetContentTypeMapping)"
>
<Output TaskParameter="Endpoints" ItemName="_ServiceWorkersPublishStaticWebAssetEndpoint" />
</DefineStaticWebAssetEndpoints>
<ItemGroup>
<StaticWebAsset Include="@(_ServiceWorkersPublishStaticWebAsset)" />
<StaticWebAssetEndpoint Include="@(_ServiceWorkersPublishStaticWebAssetEndpoint)" />
</ItemGroup>
</Target>
<Target Name="GeneratePublishServiceWorkerStaticWebAssets" DependsOnTargets="$(GeneratePublishServiceWorkerStaticWebAssetsDependsOn)">
<ComputeStaticWebAssetsForCurrentProject
Assets="@(_PublishAssetsForManifestCandidate)"
ProjectMode="$(StaticWebAssetProjectMode)"
AssetKind="Publish"
Source="$(PackageId)"
>
<Output TaskParameter="StaticWebAssets" ItemName="_PublishAssetsForManifest" />
</ComputeStaticWebAssetsForCurrentProject>
<ComputeStaticWebAssetsTargetPaths Assets="@(_PublishAssetsForManifest)" PathPrefix="$(StaticWebAssetBasePath)" UseAlternatePathDirectorySeparator="true">
<Output TaskParameter="AssetsWithTargetPath" ItemName="_PublishAssetsForManifestWithTargetPath" />
</ComputeStaticWebAssetsTargetPaths>
<ItemGroup>
<_PublishServiceWorkItem Include="@(_PublishAssetsForManifestWithTargetPath)">
<AssetUrl>%(_PublishAssetsForManifestWithTargetPath.TargetPath)</AssetUrl>
</_PublishServiceWorkItem>
</ItemGroup>
<GenerateServiceWorkerAssetsManifest
Version="$(ServiceWorkerAssetsManifestVersion)"
Assets="@(_PublishServiceWorkItem)"
OutputPath="$(_PublishServiceWorkerManifestIntermediatePath)"
>
<Output TaskParameter="CalculatedVersion" PropertyName="_PublishServiceWorkerAssetsManifestVersion" />
</GenerateServiceWorkerAssetsManifest>
<UpdateServiceWorkerFileWithVersion
Condition="Exists('$(_PublishServiceWorkerSourcePath)') and '$(_PublishServiceWorkerAssetsManifestVersion)' != ''"
ServiceWorkerSource="$(_PublishServiceWorkerSourcePath)"
ServiceWorkerDestination="$(_PublishServiceWorkerFile)"
ManifestVersion="$(_PublishServiceWorkerAssetsManifestVersion)" />
<ItemGroup>
<FileWrites Include="$(_PublishServiceWorkerManifestIntermediatePath)" />
<FileWrites Include="$(_PublishServiceWorkerFile)" />
</ItemGroup>
</Target>
<Target Name="ResolvePublishServiceWorkerStaticWebAssetsConfiguration" DependsOnTargets="ResolvePublishStaticWebAssets">
<PropertyGroup>
<_PublishServiceWorkerManifestIntermediatePath>$(IntermediateOutputPath)service-worker\$(ServiceWorkerAssetsManifest).publish</_PublishServiceWorkerManifestIntermediatePath>
</PropertyGroup>
<PropertyGroup Condition="'@(ServiceWorker)' != ''">
<_PublishServiceWorkerSourcePath>@(ServiceWorker->'%(PublishedContent)')</_PublishServiceWorkerSourcePath>
<_PublishServiceWorkerFile>$(IntermediateOutputPath)service-worker\$([System.IO.Path]::GetFileName('$(_PublishServiceWorkerSourcePath)')).publish</_PublishServiceWorkerFile>
</PropertyGroup>
<ItemGroup Condition="'@(ServiceWorker)' != ''">
<!-- This is the publish service worker, which will be generated during publish and that is defined here as a Publish
static web asset.
-->
<_PublishServiceWorker
Include="$(_PublishServiceWorkerFile)"
>
<TargetPath>@(ServiceWorker->'%(Identity)')</TargetPath>
<ContentRoot>$(IntermediateOutputPath)service-worker</ContentRoot>
<AssetTraitName>BlazorServiceWorker</AssetTraitName>
<AssetTraitValue>ServiceWorkerJs</AssetTraitValue>
<AssetKind>Publish</AssetKind>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<OriginalItemSpec>$(_PublishServiceWorkerSourcePath)</OriginalItemSpec>
</_PublishServiceWorker>
<!-- This is the publish service worker manifest file -->
<_PublishServiceWorkerManifest
Include="$(_PublishServiceWorkerManifestIntermediatePath)"
>
<OriginalItemSpec>$(_PublishServiceWorkerManifestIntermediatePath)</OriginalItemSpec>
<ContentRoot>$(IntermediateOutputPath)service-worker</ContentRoot>
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<AssetKind>Publish</AssetKind>
<TargetPath>wwwroot\$(ServiceWorkerAssetsManifest)</TargetPath>
<AssetTraitName>BlazorServiceWorker</AssetTraitName>
<AssetTraitValue>ServiceWorkerManifest</AssetTraitValue>
</_PublishServiceWorkerManifest>
</ItemGroup>
<ItemGroup>
<_PublishAssetsForManifestCandidate Include="@(StaticWebAsset)" Condition="'%(StaticWebAsset.AssetTraitName)' != 'BlazorServiceWorker' and '%(AssetRole)' != 'Alternative'" />
</ItemGroup>
<MakeDir Directories="$(IntermediateOutputPath)service-worker" />
</Target>
<Target Name="_OmitServiceWorkerContent"
BeforeTargets="ResolveProjectStaticWebAssets">
<ItemGroup>
<!-- Don't emit the service worker source files to the output -->
<Content Remove="@(ServiceWorker)" />
<Content Remove="@(ServiceWorker->'%(PublishedContent)')" />
</ItemGroup>
</Target>
</Project>