@@ -252,6 +252,111 @@ public async Task Publish_WithNoBuild_Works()
252
252
VerifyCompression ( result , blazorPublishDirectory ) ;
253
253
}
254
254
255
+ [ Fact ]
256
+ public async Task Publish_WithStaticWebBasePathWorks ( )
257
+ {
258
+ // Arrange
259
+ using var project = ProjectDirectory . Create ( "blazorwasm" , "razorclasslibrary" ) ;
260
+ project . AddProjectFileContent (
261
+ @"<PropertyGroup>
262
+ <StaticWebAssetBasePath>different-path/</StaticWebAssetBasePath>
263
+ </PropertyGroup>" ) ;
264
+ var result = await MSBuildProcessManager . DotnetMSBuild ( project , "Publish" ) ;
265
+
266
+ Assert . BuildPassed ( result ) ;
267
+
268
+ var publishDirectory = project . PublishOutputDirectory ;
269
+
270
+ // Verify nothing is published directly to the wwwroot directory
271
+ Assert . FileCountEquals ( result , 0 , Path . Combine ( publishDirectory , "wwwroot" ) , "*" , SearchOption . TopDirectoryOnly ) ;
272
+
273
+ var blazorPublishDirectory = Path . Combine ( publishDirectory , "wwwroot" , "different-path" ) ;
274
+
275
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazor.boot.json" ) ;
276
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazor.webassembly.js" ) ;
277
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "dotnet.wasm" ) ;
278
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , DotNetJsFileName ) ;
279
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazorwasm.dll" ) ;
280
+
281
+ // Verify static assets are in the publish directory
282
+ Assert . FileExists ( result , blazorPublishDirectory , "index.html" ) ;
283
+
284
+ // Verify web.config
285
+ Assert . FileExists ( result , publishDirectory , "web.config" ) ;
286
+ var webConfigContent = new StreamReader ( GetType ( ) . Assembly . GetManifestResourceStream ( "Microsoft.NET.Sdk.BlazorWebAssembly.IntegrationTests.BlazorWasm.web.config" ) ) . ReadToEnd ( ) ;
287
+ Assert . FileContentEquals ( result , Path . Combine ( publishDirectory , "web.config" ) , webConfigContent ) ;
288
+ Assert . FileCountEquals ( result , 1 , publishDirectory , "*" , SearchOption . TopDirectoryOnly ) ;
289
+
290
+ // Verify static web assets from referenced projects are copied.
291
+ Assert . FileExists ( result , blazorPublishDirectory , "_content" , "RazorClassLibrary" , "wwwroot" , "exampleJsInterop.js" ) ;
292
+ Assert . FileExists ( result , blazorPublishDirectory , "_content" , "RazorClassLibrary" , "styles.css" ) ;
293
+
294
+ VerifyBootManifestHashes ( result , blazorPublishDirectory ) ;
295
+ VerifyServiceWorkerFiles ( result ,
296
+ Path . Combine ( publishDirectory , "wwwroot" ) ,
297
+ serviceWorkerPath : Path . Combine ( "serviceworkers" , "my-service-worker.js" ) ,
298
+ serviceWorkerContent : "// This is the production service worker" ,
299
+ assetsManifestPath : "custom-service-worker-assets.js" ,
300
+ staticWebAssetsBasePath : "different-path" ) ;
301
+ }
302
+
303
+ [ Fact ]
304
+ public async Task Publish_Hosted_WithStaticWebBasePathWorks ( )
305
+ {
306
+ using var project = ProjectDirectory . Create ( "blazorhosted" , additionalProjects : new [ ] { "blazorwasm" , "razorclasslibrary" , } ) ;
307
+ var wasmProject = project . GetSibling ( "blazorwasm" ) ;
308
+ wasmProject . AddProjectFileContent (
309
+ @"<PropertyGroup>
310
+ <StaticWebAssetBasePath>different-path/</StaticWebAssetBasePath>
311
+ </PropertyGroup>" ) ;
312
+ var result = await MSBuildProcessManager . DotnetMSBuild ( project , "Publish" ) ;
313
+
314
+ Assert . BuildPassed ( result ) ;
315
+
316
+ var publishDirectory = project . PublishOutputDirectory ;
317
+ // Make sure the main project exists
318
+ Assert . FileExists ( result , publishDirectory , "blazorhosted.dll" ) ;
319
+
320
+ Assert . FileExists ( result , publishDirectory , "RazorClassLibrary.dll" ) ;
321
+ Assert . FileExists ( result , publishDirectory , "blazorwasm.dll" ) ;
322
+
323
+ var blazorPublishDirectory = Path . Combine ( publishDirectory , "wwwroot" , "different-path" ) ;
324
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazor.boot.json" ) ;
325
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazor.webassembly.js" ) ;
326
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "dotnet.wasm" ) ;
327
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , DotNetJsFileName ) ;
328
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazorwasm.dll" ) ;
329
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "System.Text.Json.dll" ) ; // Verify dependencies are part of the output.
330
+
331
+ // Verify project references appear as static web assets
332
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "RazorClassLibrary.dll" ) ;
333
+ // Also verify project references to the server project appear in the publish output
334
+ Assert . FileExists ( result , publishDirectory , "RazorClassLibrary.dll" ) ;
335
+
336
+ // Verify static assets are in the publish directory
337
+ Assert . FileExists ( result , blazorPublishDirectory , "index.html" ) ;
338
+
339
+ // Verify static web assets from referenced projects are copied.
340
+ Assert . FileExists ( result , publishDirectory , "wwwroot" , "_content" , "RazorClassLibrary" , "wwwroot" , "exampleJsInterop.js" ) ;
341
+ Assert . FileExists ( result , publishDirectory , "wwwroot" , "_content" , "RazorClassLibrary" , "styles.css" ) ;
342
+
343
+ // Verify web.config
344
+ Assert . FileExists ( result , publishDirectory , "web.config" ) ;
345
+
346
+ VerifyBootManifestHashes ( result , blazorPublishDirectory ) ;
347
+
348
+ // Verify compression works
349
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "dotnet.wasm.br" ) ;
350
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazorwasm.dll.br" ) ;
351
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "RazorClassLibrary.dll.br" ) ;
352
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "System.Text.Json.dll.br" ) ;
353
+
354
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "dotnet.wasm.gz" ) ;
355
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazorwasm.dll.gz" ) ;
356
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "RazorClassLibrary.dll.gz" ) ;
357
+ Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "System.Text.Json.dll.gz" ) ;
358
+ }
359
+
255
360
private static void VerifyCompression ( MSBuildResult result , string blazorPublishDirectory )
256
361
{
257
362
var original = Assert . FileExists ( result , blazorPublishDirectory , "_framework" , "blazor.boot.json" ) ;
0 commit comments