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

Hosting in ASP.NET Core #191

Open
bricelam opened this issue Apr 9, 2020 · 5 comments
Open

Hosting in ASP.NET Core #191

bricelam opened this issue Apr 9, 2020 · 5 comments

Comments

@bricelam
Copy link

bricelam commented Apr 9, 2020

I would like to host an Uno WASM project inside an ASP.NET Core project (similar to hosting Blazor WebAssembly). I dug a little into how Blazor does it, and it looks like they generate a StaticWebAssets.xml file based on referenced projects. This allows the ASP.NET Core app to serve static files from the WebAssembly project. Could you add similar targets to the Uno WASM build scripts to piggyback on this functionality?

Also, is there a sample showing how to do this? I'm making progress, but it's a slow going.

@jeromelaban
Copy link
Member

Thanks for the suggestion. At this point, there is no sample on how to do that, but if StaticWebAsset is supported in the default Web SDK, then it should not be a big deal to add.

If you be added in the publish targets:

BeforeTargets="GetCopyToPublishDirectoryItems"

or after the build dist target:

<Target Name="BuildDist" AfterTargets="AfterBuild">

@FrancoisM
Copy link

FrancoisM commented Oct 29, 2021

Hello.
Did you manage to do it? Any sample to share?
Right now I think that in my CI I'll copy the wasm dist folder to the wwwroot of the aspnetcore.

@FrancoisM
Copy link

FrancoisM commented Oct 29, 2021

<Project>
	<Target Name="CopyingDistToAspNetWwwRoot" AfterTargets="BuildDist">
		<ItemGroup>
			<DistFiles Include="$(OutputPath)dist\**\*.*" />
		</ItemGroup>		
		<Copy SourceFiles="@(DistFiles)"
			  DestinationFolder="..\..\MyApp.WebApp\wwwroot\wasm\%(RecursiveDir)" SkipUnchangedFiles="true"/>
	</Target>	
</Project>

@mmarinchenko
Copy link
Contributor

mmarinchenko commented Oct 30, 2021

@FrancoisM

  1. You may just set WasmShellDistPath to ..\..\MyApp.WebApp\wwwroot\wasm to achieve the same effect (unless you need to save a copy inside $(OutputPath)dist).

  2. You probably should change WebRootPath to \wwwroot\wasm in your ASP.NET Core hosting configuration or pass this path to UseStaticFiles()/UseSpaStaticFiles() to correctly serve http[s]:\\host:[port]\wasm\* requests.

@mmarinchenko
Copy link
Contributor

Alternatively, you can put Uno wasm app directly in wwwroot folder. Here's what it might looks like in a Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
ENV ASPNETCORE_URLS=https://+:443;http://+:80
EXPOSE 443 80
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
COPY . /src
RUN dotnet build "/src/Server/Host/Host.csproj" -c Release -o /app/build
RUN dotnet build "/src/Client/Wasm/Wasm.csproj" -c Release -p:WasmShellDistPath=/app/build/wwwroot

FROM build AS publish
RUN dotnet publish "/src/Server/Host/Host.csproj" -c Release -r linux-x64 -o /app/publish --self-contained=false
RUN dotnet publish "/src/Client/Wasm/Wasm.csproj" -c Release -r browser-wasm -p:WasmShellDistPath=/app/publish/wwwroot --self-contained=false
RUN find /app/publish -type f -name '*.pdb' -delete

FROM base AS final
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Server.Host.dll"]

P.S. I'm using .NET 5.0 in my project for now. I haven't tried 6.0 yet, so things might be different there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants