Skip to content

Commit 2cf3c1a

Browse files
In BlazorWebView WinForms/WPF, don't require wwwroot to exist in bin directory in development
Fixes #4537
1 parent fa8d8fa commit 2cf3c1a

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/BlazorWebView/samples/BlazorWinFormsApp/BlazorWinFormsApp.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
<ProjectReference Include="..\WebViewAppShared\WebViewAppShared.csproj" />
1616
</ItemGroup>
1717

18-
<ItemGroup>
19-
<Content Update="wwwroot\**">
20-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21-
</Content>
22-
</ItemGroup>
23-
2418
<Import Project="..\..\src\WindowsForms\build\Microsoft.AspNetCore.Components.WebView.WindowsForms.targets" />
2519

2620
</Project>

src/BlazorWebView/samples/BlazorWpfApp/BlazorWpfApp.csproj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
<ProjectReference Include="..\WebViewAppShared\WebViewAppShared.csproj" />
1616
</ItemGroup>
1717

18-
<ItemGroup>
19-
<Content Update="wwwroot\**">
20-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21-
</Content>
22-
</ItemGroup>
23-
2418
<Import Project="..\..\src\Wpf\build\Microsoft.AspNetCore.Components.WebView.Wpf.targets" />
2519

2620
</Project>

src/BlazorWebView/src/WindowsForms/BlazorWebView.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,17 @@ private void HandleRootComponentsCollectionChanged(object sender, NotifyCollecti
198198
/// <returns>Returns a <see cref="IFileProvider"/> for static assets.</returns>
199199
public virtual IFileProvider CreateFileProvider(string contentRootDir)
200200
{
201-
return new PhysicalFileProvider(contentRootDir);
201+
if (Directory.Exists(contentRootDir))
202+
{
203+
// Typical case after publishing, or if you're copying content to the bin dir in development for some nonstandard reason
204+
return new PhysicalFileProvider(contentRootDir);
205+
}
206+
else
207+
{
208+
// Typical case in development, as the files come from Microsoft.AspNetCore.Components.WebView.StaticContentProvider
209+
// instead and aren't copied to the bin dir
210+
return new NullFileProvider();
211+
}
202212
}
203213

204214
/// <inheritdoc />

src/BlazorWebView/src/Wpf/BlazorWebView.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,17 @@ private void HandleRootComponentsCollectionChanged(object sender, NotifyCollecti
218218
/// <returns>Returns a <see cref="IFileProvider"/> for static assets.</returns>
219219
public virtual IFileProvider CreateFileProvider(string contentRootDir)
220220
{
221-
return new PhysicalFileProvider(contentRootDir);
221+
if (Directory.Exists(contentRootDir))
222+
{
223+
// Typical case after publishing, or if you're copying content to the bin dir in development for some nonstandard reason
224+
return new PhysicalFileProvider(contentRootDir);
225+
}
226+
else
227+
{
228+
// Typical case in development, as the files come from Microsoft.AspNetCore.Components.WebView.StaticContentProvider
229+
// instead and aren't copied to the bin dir
230+
return new NullFileProvider();
231+
}
222232
}
223233

224234
private void CheckDisposed()

0 commit comments

Comments
 (0)