Skip to content
Closed
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 @@ -5,6 +5,8 @@
<OutputType>Exe</OutputType>
<IsShippingPackage>false</IsShippingPackage>
<SignAssembly>false</SignAssembly>
<_WebViewAssetsBasePath>..\..\..\..\..\Web.JS\dist\Release\</_WebViewAssetsBasePath>
<_BlazorModulesFilePath>..\..\..\..\WebView\src\blazor.modules.json</_BlazorModulesFilePath>
</PropertyGroup>

<Import Project="..\..\..\..\WebView\src\buildTransitive\Microsoft.AspNetCore.Components.WebView.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<Description>Build desktop applications with Blazor and a webview.</Description>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<EmbeddedFilesManifestFileName>Microsoft.Extensions.FileProviders.Embedded.Manifest.xml</EmbeddedFilesManifestFileName>
<IsShippingPackage>true</IsShippingPackage>
<DefineConstants>$(DefineConstants);BLAZOR_WEBVIEW</DefineConstants>
Expand Down Expand Up @@ -73,9 +72,11 @@

<Target Name="_AddEmbeddedBlazorWebView" BeforeTargets="_CalculateEmbeddedFilesManifestInputs" DependsOnTargets="_CheckBlazorWebViewJSPath">
<ItemGroup>
<EmbeddedResource Include="blazor.modules.json" LogicalName="_framework/blazor.modules.json" />
<EmbeddedResource Include="$(BlazorWebViewJSFile)" LogicalName="_framework/$(BlazorWebViewJSFilename)" />
<EmbeddedResource Include="$(BlazorWebViewJSFile).map" LogicalName="_framework/$(BlazorWebViewJSFilename).map" Condition="Exists('$(BlazorWebViewJSFile).map')" />
<!--<EmbeddedResource Include="blazor.modules.json" LogicalName="_framework/blazor.modules.json" />-->
<!--<EmbeddedResource Include="$(BlazorWebViewJSFile)" LogicalName="_framework/$(BlazorWebViewJSFilename)" />
<EmbeddedResource Include="$(BlazorWebViewJSFile).map" LogicalName="_framework/$(BlazorWebViewJSFilename).map" Condition="Exists('$(BlazorWebViewJSFile).map')" />-->
<Content Include="$(BlazorWebViewJSFile)" Pack="true" PackagePath="staticwebassets/$(BlazorWebViewJSFilename)" />
<Content Include="blazor.modules.json" Pack="true" PackagePath="staticwebassets/blazor.modules.json" />
</ItemGroup>
</Target>

Expand Down
38 changes: 19 additions & 19 deletions src/Components/WebView/WebView/src/StaticContentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ internal sealed class StaticContentProvider
private readonly Uri _appBaseUri;
private readonly string _hostPageRelativePath;
private static readonly FileExtensionContentTypeProvider ContentTypeProvider = new();
private static readonly ManifestEmbeddedFileProvider _manifestProvider =
new ManifestEmbeddedFileProvider(typeof(StaticContentProvider).Assembly);
//private static readonly ManifestEmbeddedFileProvider _manifestProvider =
// new ManifestEmbeddedFileProvider(typeof(StaticContentProvider).Assembly);

public StaticContentProvider(IFileProvider fileProvider, Uri appBaseUri, string hostPageRelativePath)
{
Expand All @@ -34,8 +34,8 @@ public bool TryGetResponseContent(string requestUri, bool allowFallbackOnHostPag
// If there's no match, fall back on serving embedded framework content
string contentType;
var found = TryGetFromFileProvider(relativePath, out content, out contentType)
|| (allowFallbackOnHostPage && TryGetFromFileProvider(_hostPageRelativePath, out content, out contentType))
|| TryGetFrameworkFile(relativePath, out content, out contentType);
|| (allowFallbackOnHostPage && TryGetFromFileProvider(_hostPageRelativePath, out content, out contentType));
//|| TryGetFrameworkFile(relativePath, out content, out contentType);

if (found)
{
Expand Down Expand Up @@ -83,22 +83,22 @@ private bool TryGetFromFileProvider(string relativePath, out Stream content, out
return false;
}

private static bool TryGetFrameworkFile(string relativePath, out Stream content, out string contentType)
{
// We're not trying to simulate everything a real webserver does. We don't need to
// support querystring parameters, for example. It's enough to require an exact match.
var file = _manifestProvider.GetFileInfo(relativePath);
if (file.Exists)
{
content = file.CreateReadStream();
contentType = GetResponseContentTypeOrDefault(relativePath);
return true;
}
//private static bool TryGetFrameworkFile(string relativePath, out Stream content, out string contentType)
//{
// // We're not trying to simulate everything a real webserver does. We don't need to
// // support querystring parameters, for example. It's enough to require an exact match.
// var file = _manifestProvider.GetFileInfo(relativePath);
// if (file.Exists)
// {
// content = file.CreateReadStream();
// contentType = GetResponseContentTypeOrDefault(relativePath);
// return true;
// }

content = default;
contentType = default;
return false;
}
// content = default;
// contentType = default;
// return false;
//}

private static string GetResponseContentTypeOrDefault(string path)
=> ContentTypeProvider.TryGetContentType(path, out var matchedContentType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
<Project>
<PropertyGroup>
<JSModuleManifestRelativePath>_framework/blazor.modules.json</JSModuleManifestRelativePath>
<JSModuleManifestRelativePath>_framework/blazor.modules.json</JSModuleManifestRelativePath>
<CompressionEnabled>false</CompressionEnabled>
</PropertyGroup>
<PropertyGroup>
<ResolveStaticWebAssetsInputsDependsOn>
$(ResolveStaticWebAssetsInputsDependsOn);
_AddBlazorWebViewAssets;
</ResolveStaticWebAssetsInputsDependsOn>
</PropertyGroup>

<Target Name="_AddBlazorWebViewAssets" DependsOnTargets="GenerateJSModuleManifestBuildStaticWebAssets">
<PropertyGroup>
<_WebViewAssetsBasePath Condition="'$(_WebViewAssetsBasePath)' == ''">$(MSBuildThisFileDirectory)..\staticwebassets\</_WebViewAssetsBasePath>
<_BlazorModulesFilePath Condition="'$(_WebViewAssetsBasePath)' == ''">$(MSBuildThisFileDirectory)..\staticwebassets\blazor.modules.json</_BlazorModulesFilePath>
</PropertyGroup>
<ItemGroup>
<_WebViewAssetCandidates Include="$(_WebViewAssetsBasePath)blazor.webview.js">
<RelativePath>_framework/blazor.webview.js</RelativePath>
</_WebViewAssetCandidates>
<_WebViewAssetCandidates Include="$(_BlazorModulesFilePath)" Condition="'@(_ExistingBuildJSModules)' == ''">
<RelativePath>_framework/blazor.modules.json</RelativePath>
</_WebViewAssetCandidates>
</ItemGroup>
<DefineStaticWebAssets
CandidateAssets="@(_WebViewAssetCandidates)"
SourceId="$(PackageId)"
ContentRoot="$(_WebViewAssetsBasePath)"
SourceType="Discovered"
AssetKind="All"
AssetMode="All"
AssetRole="Primary"
FingerprintCandidates="true"
BasePath="/">
<Output TaskParameter="Assets" ItemName="_FrameworkStaticWebAsset" />
</DefineStaticWebAssets>

<ItemGroup>
<StaticWebAsset Include="@(_FrameworkStaticWebAsset)" />
</ItemGroup>
</Target>

</Project>

Loading