Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source build when using --no-build-js #59118

Merged
merged 8 commits into from
Nov 27, 2024
Merged
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
2 changes: 2 additions & 0 deletions .azure/pipelines/ci-public.yml
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ stages:
displayName: Update submodules
- script: ./restore.cmd
displayName: Run restore.cmd
- powershell: ./eng/build.ps1 -all -noBuildJava -noBuildNodeJS "-WarnAsError:false"
displayName: Build (No NodeJS)
- script: npm run build
displayName: Build JS
- script: ./eng/build.cmd -all -noBuildJava -pack -c Debug
Expand Down
2 changes: 2 additions & 0 deletions .azure/pipelines/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ extends:
displayName: Update submodules
- script: ./restore.cmd
displayName: Run restore.cmd
- script: ./eng/build.cmd -all -noBuildJava -noBuildNodeJS
displayName: Build (No NodeJS)
- script: npm run build
displayName: Build JS
- script: ./eng/build.cmd -all -noBuildJava -pack -c Debug
Expand Down
2 changes: 1 addition & 1 deletion src/Assets/Microsoft.AspNetCore.App.Internal.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<_BlazorJSContentRoot Condition="'$(Configuration)' == 'Release'">$(RepoRoot)src\Components\Web.JS\dist\Release</_BlazorJSContentRoot>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(BuildNodeJS)' == 'true'">
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.web.js" />
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.server.js" />
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.webassembly.js" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\blazor.webassembly.js.map" />
</ItemGroup>

<ItemGroup>
<_MissingFrameworkStaticWebAssetCandidate
Include="@(_FrameworkStaticWebAssetCandidate)"
Condition="!EXISTS('%(Identity)')" />
<_FrameworkStaticWebAssetCandidate Remove="@(_MissingFrameworkStaticWebAssetCandidate)" />
</ItemGroup>

<Message Importance="High" Text="Framework asset '%(_MissingFrameworkStaticWebAssetCandidate.Identity)' could not be found and won't be included in the project." />

<PropertyGroup>
<_FrameworkAssetsPath>$(IntermediateOutputPath)frameworkassets</_FrameworkAssetsPath>
</PropertyGroup>

<MakeDir
Directories="$(_FrameworkAssetsPath)"
Condition="!Exists('$(_FrameworkAssetsPath)')" />
Condition="!EXISTS('$(_FrameworkAssetsPath)')" />

<Copy
SourceFiles="@(_FrameworkStaticWebAssetCandidate)"
Expand Down
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 @@ -63,19 +62,15 @@
<BlazorWebViewJSFile Condition=" '$(Configuration)' != 'Debug' ">..\..\..\Web.JS\dist\Release\$(BlazorWebViewJSFilename)</BlazorWebViewJSFile>
</PropertyGroup>

<!-- blazor.webview.js should exist after eng/Npm.Workspace.nodeproj builds. Fall back if not. -->
<!-- blazor.webview.js should exist after eng/Npm.Workspace.nodeproj builds. Warn if not. -->
<Target Name="_CheckBlazorWebViewJSPath" AfterTargets="ResolveProjectReferences" Condition=" !EXISTS('$(BlazorWebViewJSFile)') ">
<Warning Text="'$(BlazorWebViewJSFile)' does not exist. Falling back to checked-in copy." />
<PropertyGroup>
<BlazorWebViewJSFile>..\..\..\Web.JS\dist\Release\$(BlazorWebViewJSFilename)</BlazorWebViewJSFile>
</PropertyGroup>
<Warning Text="'$(BlazorWebViewJSFile)' does not exist and won't be included in the build." />
</Target>

<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')" />
<Content Include="$(BlazorWebViewJSFile)" Condition="EXISTS('$(BlazorWebViewJSFile)')" Pack="true" PackagePath="staticwebassets/$(BlazorWebViewJSFilename)" />
<Content Include="blazor.modules.json" Pack="true" PackagePath="staticwebassets/blazor.modules.json" />
</ItemGroup>
</Target>

Expand Down
22 changes: 1 addition & 21 deletions src/Components/WebView/WebView/src/StaticContentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ 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);

public StaticContentProvider(IFileProvider fileProvider, Uri appBaseUri, string hostPageRelativePath)
{
Expand All @@ -34,8 +32,7 @@ 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));

if (found)
{
Expand Down Expand Up @@ -83,23 +80,6 @@ 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;
}

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

private static string GetResponseContentTypeOrDefault(string path)
=> ContentTypeProvider.TryGetContentType(path, out var matchedContentType)
? matchedContentType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
<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>

<_MissingWebViewAssetCandidates
Include="@(_WebViewAssetCandidates)"
Condition="!EXISTS('%(Identity)')" />
<_WebViewAssetCandidates Remove="@(_MissingWebViewAssetCandidates)" />
</ItemGroup>

<Message Importance="High" Text="WebView asset '%(_MissingWebViewAssetCandidates.Identity)' could not be found and won't be included in the project." />

<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