Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
Purpose: WebView apps fetch _framework/blazor.modules.json at runtime. When the app
contributes its own JS library modules, the SDK generates that manifest. When it does
not, nothing would be served, so this package ships an empty ([]) fallback and
materializes it as the consumer's own static web asset ONLY in that case. The decision is
materializes it as the consumer's own current-project-only static web asset ONLY in that
case. The fallback does not flow from libraries to referencing projects. The decision is
made here, during ResolveStaticWebAssetsInputs (before the build manifest is generated and
its conflict check runs), so exactly one asset ever lands on the route and no group /
conflict-resolution machinery is required. -->
Expand Down Expand Up @@ -53,7 +54,7 @@
ContentRoot="$(_BlazorWebViewModulesFallbackRoot)"
BasePath="/"
AssetKind="All"
AssetMode="All"
AssetMode="CurrentProject"
AssetRole="Primary"
FingerprintCandidates="true">
<Output TaskParameter="Assets" ItemName="_BlazorWebViewModulesFallbackAsset" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public ConsumerBuild(ITestOutputHelper output, bool isolateNuGetFeeds = true, [C
// fallback so the exact transitive package versions the repo restored (which may not be
// published to public feeds yet) can still be resolved.
var repoCache = StaticWebAssetsTestData.NuGetPackageRoot.TrimEnd('\\', '/');
var nonShippingSource = Directory.Exists(StaticWebAssetsTestData.NonShippingPackagesDir)
? $"""<add key="local-nonshipping" value="{StaticWebAssetsTestData.NonShippingPackagesDir.TrimEnd('\\', '/')}" />"""
: "";
File.WriteAllText(Path.Combine(_root, "NuGet.config"), $"""
<configuration>
<config>
Expand All @@ -62,7 +65,7 @@ public ConsumerBuild(ITestOutputHelper output, bool isolateNuGetFeeds = true, [C
<packageSources>
<clear />
<add key="local-shipping" value="{StaticWebAssetsTestData.ShippingPackagesDir.TrimEnd('\\', '/')}" />
<add key="local-nonshipping" value="{StaticWebAssetsTestData.NonShippingPackagesDir.TrimEnd('\\', '/')}" />
{nonShippingSource}
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Expand Down Expand Up @@ -201,9 +204,9 @@ internal sealed record ProcessResult(int ExitCode, string Output, string BinlogP
/// </summary>
public bool LooksLikeNetworkFailure
=> !Succeeded &&
!Output.Contains("The local source", StringComparison.OrdinalIgnoreCase) &&
(Output.Contains("Unable to load the service index", StringComparison.OrdinalIgnoreCase) ||
Output.Contains("NU1301", StringComparison.OrdinalIgnoreCase) ||
Output.Contains("Unable to resolve", StringComparison.OrdinalIgnoreCase) && Output.Contains("nuget", StringComparison.OrdinalIgnoreCase) ||
Output.Contains("The remote name could not be resolved", StringComparison.OrdinalIgnoreCase) ||
Output.Contains("No such host is known", StringComparison.OrdinalIgnoreCase));
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,103 @@ public void PublishAndBuild_AppWithoutJsModules_ServesEmptyFallbackModulesManife
Assert.Equal("[]", File.ReadAllText(publishedManifest!).Trim());
}

[ConditionalFact]
public void Publish_AppAndRclWithoutJsModulesBothReferencingWebView_ProducesSingleFallbackManifest()
{
using var build = new ConsumerBuild(_output);

build.CreateProject("rcl", "rcl.csproj", $"""
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>{StaticWebAssetsTestData.DefaultTargetFramework}</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView" Version="{StaticWebAssetsTestData.PackageVersion}" />
</ItemGroup>
</Project>
""");

build.CreateProject("app", "app.csproj", $"""
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>{StaticWebAssetsTestData.DefaultTargetFramework}</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView" Version="{StaticWebAssetsTestData.PackageVersion}" />
<ProjectReference Include="..\rcl\rcl.csproj" />
</ItemGroup>
</Project>
""");
build.CreateFile("app/Program.cs", "class Program { static void Main() { } }");

var result = build.Run("publish -c Release -v:m", "app/app.csproj");
if (result.LooksLikeNetworkFailure)
{
return;
}

Assert.True(result.Succeeded, $"Publish should succeed.\n{result.Output}");
Assert.DoesNotContain("Conflicting assets with the same target path", result.Output);

var routes = GetModulesManifestRoutes(build.Root);
Assert.Equal("_framework/blazor.modules.json", Assert.Single(routes));

var publishedManifest = FindPublishedFile(build.Root, "blazor.modules.json");
Assert.NotNull(publishedManifest);
Assert.Equal("[]", File.ReadAllText(publishedManifest!).Trim());
}

[ConditionalFact]
public void Publish_AppAndRclWithJsModulesBothReferencingWebView_ProducesSingleModulesManifest()
{
using var build = new ConsumerBuild(_output);

build.CreateProject("rcl", "rcl.csproj", $"""
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>{StaticWebAssetsTestData.DefaultTargetFramework}</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView" Version="{StaticWebAssetsTestData.PackageVersion}" />
</ItemGroup>
</Project>
""");
build.CreateFile("rcl/wwwroot/rcl.lib.module.js", "export function afterStarted() {}");

build.CreateProject("app", "app.csproj", $"""
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>{StaticWebAssetsTestData.DefaultTargetFramework}</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView" Version="{StaticWebAssetsTestData.PackageVersion}" />
<ProjectReference Include="..\rcl\rcl.csproj" />
</ItemGroup>
</Project>
""");
build.CreateFile("app/Program.cs", "class Program { static void Main() { } }");

var result = build.Run("publish -c Release -v:m", "app/app.csproj");
if (result.LooksLikeNetworkFailure)
{
return;
}

Assert.True(result.Succeeded, $"Publish should succeed.\n{result.Output}");
Assert.DoesNotContain("Conflicting assets with the same target path", result.Output);

var routes = GetModulesManifestRoutes(build.Root);
Assert.Equal("_framework/blazor.modules.json", Assert.Single(routes));

var publishedManifest = FindPublishedFile(build.Root, "blazor.modules.json");
Assert.NotNull(publishedManifest);
var publishedContent = File.ReadAllText(publishedManifest!);
Assert.Contains("_content/rcl/", publishedContent);
Assert.Contains(".lib.module.js", publishedContent);
}

[ConditionalFact]
public void Publish_ProjectReferenceToWebViewWithJsModuleRcl_SucceedsWithSingleModulesManifest()
{
Expand Down
Loading