Skip to content

Commit 81a2bab

Browse files
Fix source build when using --no-build-js (#59118)
Co-authored-by: Javier Calvarro Nelson <jacalvar@microsoft.com>
1 parent 02e5cfb commit 81a2bab

File tree

8 files changed

+71
-33
lines changed

8 files changed

+71
-33
lines changed

.azure/pipelines/ci-public.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ stages:
653653
displayName: Update submodules
654654
- script: ./restore.cmd
655655
displayName: Run restore.cmd
656+
- powershell: ./eng/build.ps1 -all -noBuildJava -noBuildNodeJS "-WarnAsError:false"
657+
displayName: Build (No NodeJS)
656658
- script: npm run build
657659
displayName: Build JS
658660
- script: ./eng/build.cmd -all -noBuildJava -pack -c Debug

.azure/pipelines/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ extends:
719719
displayName: Update submodules
720720
- script: ./restore.cmd
721721
displayName: Run restore.cmd
722+
- script: ./eng/build.cmd -all -noBuildJava -noBuildNodeJS
723+
displayName: Build (No NodeJS)
722724
- script: npm run build
723725
displayName: Build JS
724726
- script: ./eng/build.cmd -all -noBuildJava -pack -c Debug

src/Assets/Microsoft.AspNetCore.App.Internal.Assets.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<_BlazorJSContentRoot Condition="'$(Configuration)' == 'Release'">$(RepoRoot)src\Components\Web.JS\dist\Release</_BlazorJSContentRoot>
2222
</PropertyGroup>
2323

24-
<ItemGroup>
24+
<ItemGroup Condition="'$(BuildNodeJS)' == 'true'">
2525
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.web.js" />
2626
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.server.js" />
2727
<_BlazorJSFile Include="$(_BlazorJSContentRoot)\blazor.webassembly.js" />

src/Assets/build/Microsoft.AspNetCore.App.Internal.Assets.targets

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,22 @@
3333
<_FrameworkStaticWebAssetCandidate Include="$(BlazorFrameworkStaticWebAssetRoot)\blazor.webassembly.js.map" />
3434
</ItemGroup>
3535

36+
<ItemGroup>
37+
<_MissingFrameworkStaticWebAssetCandidate
38+
Include="@(_FrameworkStaticWebAssetCandidate)"
39+
Condition="!EXISTS('%(Identity)')" />
40+
<_FrameworkStaticWebAssetCandidate Remove="@(_MissingFrameworkStaticWebAssetCandidate)" />
41+
</ItemGroup>
42+
43+
<Message Importance="High" Text="Framework asset '%(_MissingFrameworkStaticWebAssetCandidate.Identity)' could not be found and won't be included in the project." />
44+
3645
<PropertyGroup>
3746
<_FrameworkAssetsPath>$(IntermediateOutputPath)frameworkassets</_FrameworkAssetsPath>
3847
</PropertyGroup>
3948

4049
<MakeDir
4150
Directories="$(_FrameworkAssetsPath)"
42-
Condition="!Exists('$(_FrameworkAssetsPath)')" />
51+
Condition="!EXISTS('$(_FrameworkAssetsPath)')" />
4352

4453
<Copy
4554
SourceFiles="@(_FrameworkStaticWebAssetCandidate)"

src/Components/WebView/Samples/PhotinoPlatform/testassets/PhotinoTestApp/PhotinoTestApp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<OutputType>Exe</OutputType>
66
<IsShippingPackage>false</IsShippingPackage>
77
<SignAssembly>false</SignAssembly>
8+
<_WebViewAssetsBasePath>..\..\..\..\..\Web.JS\dist\Release\</_WebViewAssetsBasePath>
9+
<_BlazorModulesFilePath>..\..\..\..\WebView\src\blazor.modules.json</_BlazorModulesFilePath>
810
</PropertyGroup>
911

1012
<Import Project="..\..\..\..\WebView\src\buildTransitive\Microsoft.AspNetCore.Components.WebView.props" />

src/Components/WebView/WebView/src/Microsoft.AspNetCore.Components.WebView.csproj

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
55
<Description>Build desktop applications with Blazor and a webview.</Description>
6-
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
76
<EmbeddedFilesManifestFileName>Microsoft.Extensions.FileProviders.Embedded.Manifest.xml</EmbeddedFilesManifestFileName>
87
<IsShippingPackage>true</IsShippingPackage>
98
<DefineConstants>$(DefineConstants);BLAZOR_WEBVIEW</DefineConstants>
@@ -63,19 +62,15 @@
6362
<BlazorWebViewJSFile Condition=" '$(Configuration)' != 'Debug' ">..\..\..\Web.JS\dist\Release\$(BlazorWebViewJSFilename)</BlazorWebViewJSFile>
6463
</PropertyGroup>
6564

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

7470
<Target Name="_AddEmbeddedBlazorWebView" BeforeTargets="_CalculateEmbeddedFilesManifestInputs" DependsOnTargets="_CheckBlazorWebViewJSPath">
7571
<ItemGroup>
76-
<EmbeddedResource Include="blazor.modules.json" LogicalName="_framework/blazor.modules.json" />
77-
<EmbeddedResource Include="$(BlazorWebViewJSFile)" LogicalName="_framework/$(BlazorWebViewJSFilename)" />
78-
<EmbeddedResource Include="$(BlazorWebViewJSFile).map" LogicalName="_framework/$(BlazorWebViewJSFilename).map" Condition="Exists('$(BlazorWebViewJSFile).map')" />
72+
<Content Include="$(BlazorWebViewJSFile)" Condition="EXISTS('$(BlazorWebViewJSFile)')" Pack="true" PackagePath="staticwebassets/$(BlazorWebViewJSFilename)" />
73+
<Content Include="blazor.modules.json" Pack="true" PackagePath="staticwebassets/blazor.modules.json" />
7974
</ItemGroup>
8075
</Target>
8176

src/Components/WebView/WebView/src/StaticContentProvider.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ internal sealed class StaticContentProvider
1212
private readonly Uri _appBaseUri;
1313
private readonly string _hostPageRelativePath;
1414
private static readonly FileExtensionContentTypeProvider ContentTypeProvider = new();
15-
private static readonly ManifestEmbeddedFileProvider _manifestProvider =
16-
new ManifestEmbeddedFileProvider(typeof(StaticContentProvider).Assembly);
1715

1816
public StaticContentProvider(IFileProvider fileProvider, Uri appBaseUri, string hostPageRelativePath)
1917
{
@@ -34,8 +32,7 @@ public bool TryGetResponseContent(string requestUri, bool allowFallbackOnHostPag
3432
// If there's no match, fall back on serving embedded framework content
3533
string contentType;
3634
var found = TryGetFromFileProvider(relativePath, out content, out contentType)
37-
|| (allowFallbackOnHostPage && TryGetFromFileProvider(_hostPageRelativePath, out content, out contentType))
38-
|| TryGetFrameworkFile(relativePath, out content, out contentType);
35+
|| (allowFallbackOnHostPage && TryGetFromFileProvider(_hostPageRelativePath, out content, out contentType));
3936

4037
if (found)
4138
{
@@ -83,23 +80,6 @@ private bool TryGetFromFileProvider(string relativePath, out Stream content, out
8380
return false;
8481
}
8582

86-
private static bool TryGetFrameworkFile(string relativePath, out Stream content, out string contentType)
87-
{
88-
// We're not trying to simulate everything a real webserver does. We don't need to
89-
// support querystring parameters, for example. It's enough to require an exact match.
90-
var file = _manifestProvider.GetFileInfo(relativePath);
91-
if (file.Exists)
92-
{
93-
content = file.CreateReadStream();
94-
contentType = GetResponseContentTypeOrDefault(relativePath);
95-
return true;
96-
}
97-
98-
content = default;
99-
contentType = default;
100-
return false;
101-
}
102-
10383
private static string GetResponseContentTypeOrDefault(string path)
10484
=> ContentTypeProvider.TryGetContentType(path, out var matchedContentType)
10585
? matchedContentType
Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
<Project>
22
<PropertyGroup>
3-
<JSModuleManifestRelativePath>_framework/blazor.modules.json</JSModuleManifestRelativePath>
3+
<JSModuleManifestRelativePath>_framework/blazor.modules.json</JSModuleManifestRelativePath>
4+
<CompressionEnabled>false</CompressionEnabled>
45
</PropertyGroup>
6+
<PropertyGroup>
7+
<ResolveStaticWebAssetsInputsDependsOn>
8+
$(ResolveStaticWebAssetsInputsDependsOn);
9+
_AddBlazorWebViewAssets;
10+
</ResolveStaticWebAssetsInputsDependsOn>
11+
</PropertyGroup>
12+
13+
<Target Name="_AddBlazorWebViewAssets" DependsOnTargets="GenerateJSModuleManifestBuildStaticWebAssets">
14+
<PropertyGroup>
15+
<_WebViewAssetsBasePath Condition="'$(_WebViewAssetsBasePath)' == ''">$(MSBuildThisFileDirectory)..\staticwebassets\</_WebViewAssetsBasePath>
16+
<_BlazorModulesFilePath Condition="'$(_WebViewAssetsBasePath)' == ''">$(MSBuildThisFileDirectory)..\staticwebassets\blazor.modules.json</_BlazorModulesFilePath>
17+
</PropertyGroup>
18+
<ItemGroup>
19+
<_WebViewAssetCandidates Include="$(_WebViewAssetsBasePath)blazor.webview.js">
20+
<RelativePath>_framework/blazor.webview.js</RelativePath>
21+
</_WebViewAssetCandidates>
22+
<_WebViewAssetCandidates Include="$(_BlazorModulesFilePath)" Condition="'@(_ExistingBuildJSModules)' == ''">
23+
<RelativePath>_framework/blazor.modules.json</RelativePath>
24+
</_WebViewAssetCandidates>
25+
26+
<_MissingWebViewAssetCandidates
27+
Include="@(_WebViewAssetCandidates)"
28+
Condition="!EXISTS('%(Identity)')" />
29+
<_WebViewAssetCandidates Remove="@(_MissingWebViewAssetCandidates)" />
30+
</ItemGroup>
31+
32+
<Message Importance="High" Text="WebView asset '%(_MissingWebViewAssetCandidates.Identity)' could not be found and won't be included in the project." />
33+
34+
<DefineStaticWebAssets
35+
CandidateAssets="@(_WebViewAssetCandidates)"
36+
SourceId="$(PackageId)"
37+
ContentRoot="$(_WebViewAssetsBasePath)"
38+
SourceType="Discovered"
39+
AssetKind="All"
40+
AssetMode="All"
41+
AssetRole="Primary"
42+
FingerprintCandidates="true"
43+
BasePath="/">
44+
<Output TaskParameter="Assets" ItemName="_FrameworkStaticWebAsset" />
45+
</DefineStaticWebAssets>
46+
47+
<ItemGroup>
48+
<StaticWebAsset Include="@(_FrameworkStaticWebAsset)" />
49+
</ItemGroup>
50+
</Target>
51+
552
</Project>
53+

0 commit comments

Comments
 (0)