Skip to content

Commit 3731069

Browse files
authored
feat: fix github pages build issue (#343)
1 parent c861194 commit 3731069

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

.github/workflows/deploy-demo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: Publish Blazor WASM app
4040
run: |
4141
REPO_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2)
42-
dotnet publish csharp/PhoneNumbers.Demo/PhoneNumbers.Demo.csproj -c Release -o release -p:StaticWebAssetBasePath=/$REPO_NAME
42+
dotnet publish csharp/PhoneNumbers.Demo/PhoneNumbers.Demo.csproj -c Release -o release -p:PathBase=/${REPO_NAME}/
4343
4444
- name: Configure for GitHub Pages
4545
run: |

csharp/PhoneNumbers.Demo/PhoneNumbers.Demo.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<RootNamespace>PhoneNumbers.Demo</RootNamespace>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
8+
<PathBase Condition="'$(PathBase)' == ''">/</PathBase>
89
</PropertyGroup>
910

1011
<ItemGroup>
@@ -16,4 +17,27 @@
1617
<ProjectReference Include="..\PhoneNumbers\PhoneNumbers.csproj" />
1718
</ItemGroup>
1819

20+
<UsingTask TaskName="ReplaceFileText" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
21+
<ParameterGroup>
22+
<InputFile Required="true" ParameterType="System.String" />
23+
<OldText Required="true" ParameterType="System.String" />
24+
<NewText Required="true" ParameterType="System.String" />
25+
</ParameterGroup>
26+
<Task>
27+
<Code Type="Fragment" Language="cs">
28+
var content = System.IO.File.ReadAllText(InputFile);
29+
if (!content.Contains(OldText))
30+
throw new System.InvalidOperationException($"Could not find '{OldText}' in {InputFile}");
31+
content = content.Replace(OldText, NewText);
32+
System.IO.File.WriteAllText(InputFile, content);
33+
</Code>
34+
</Task>
35+
</UsingTask>
36+
37+
<Target Name="UpdateBaseHref" AfterTargets="Publish" Condition="'$(PathBase)' != '/'">
38+
<ReplaceFileText InputFile="$(PublishDir)wwwroot/index.html"
39+
OldText='&lt;base href="/" /&gt;'
40+
NewText='&lt;base href="$(PathBase)" /&gt;' />
41+
</Target>
42+
1943
</Project>

0 commit comments

Comments
 (0)