In this tutorial we will be deploying our JSViewer_MVC_Core sample on Google Cloud platform using Google App Engine flexible environment. App Engine flexible environment is based on Linux, it is useful for .NET Core applications.
gcloud app create –JSViewer-MVC-Core
CustomFontResolver.cs |
Copy Code
|
---|---|
using GrapeCity.Documents.Text.Windows; public sealed class CustomFontResolver : GrapeCity.ActiveReports.IFontResolver { static readonly GrapeCity.Documents.Text.FontCollection _fonts = new GrapeCity.Documents.Text.FontCollection(); static CustomFontResolver() { _fonts.Clear(); var assembly = Assembly.GetExecutingAssembly(); var fontnames = assembly.GetManifestResourceNames().Where(str => str.EndsWith(".ttf")); foreach (var fontname in fontnames) { Stream stream = assembly.GetManifestResourceStream(fontname); _fonts.Add(GrapeCity.Documents.Text.Font.FromStream(stream)); } _fonts.DefaultFont = _fonts.FindFamilyName("Arial"); } public static GrapeCity.ActiveReports.IFontResolver Instance = new CustomFontResolver(); private CustomFontResolver() { } GrapeCity.Documents.Text.FontCollection GrapeCity.ActiveReports.IFontResolver.GetFonts(string familyName, bool isBold, bool isItalic) { var fonts = new GrapeCity.Documents.Text.FontCollection(); var font = _fonts.FindFamilyName(familyName, isBold, isItalic); if (font != null) fonts.Add(font); fonts.Add(_fonts.DefaultFont); return fonts; } } |
Startup.cs |
Copy Code
|
---|---|
app.UseReportViewer(settings =>
{
settings.UseFontResolver = CustomFontResolver.Instance;
settings.UseEmbeddedTemplates(EmbeddedReportsPrefix, Assembly.GetAssembly(app.GetType()));
settings.UseCompression = true;
});
|
app.yaml |
Copy Code
|
---|---|
runtime: custom env: flex |
Since we have installed the Google Cloud Tool for Visual studio extension in Visual studio 2019. This can be easily done by:
a. Right Clicking on the project and then on Generate app.yaml and dockerfile.
b. In the generated app.yaml change the runtime environment from aspnetcore to custom and add the following container configuration.
app.yaml |
Copy Code
|
---|---|
runtime: custom env: flex manual_scaling: instances: 1 resources: cpu: 1 memory_gb: 0.5 disk_size_gb: 10 |
c. Clear the dockerfile and add the following text in the docker file:
Example Title |
Copy Code
|
---|---|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env WORKDIR /app # Copy csproj and restore as distinct layers COPY *.csproj ./ RUN dotnet restore # Copy everything else and build COPY . ./ RUN dotnet publish -c Release -o out # Build runtime image FROM mcr.microsoft.com/dotnet/aspnet:6.0 WORKDIR /app COPY --from=build-env /app/out . EXPOSE 8080 ENV ASPNETCORE_URLS=http://*:8080 ENTRYPOINT ["dotnet", "JSViewer_MVC_Core.dll"] |
On Window’s command prompt, you can create a new app.yaml in one line:
app.yaml |
Copy Code
|
---|---|
(echo runtime: aspnetcore & echo env: flex) > app.yaml |
The app.yaml file will have to be copied over to the destination folder when you start the publishing process.
You can include the file to the output through Visual Studio or editing the JsViewer_MVC_Core.csproj file:
JsViewer_MVC_Core.csproj |
Copy Code
|
---|---|
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> </PropertyGroup> <ItemGroup> <None Include="app.yaml" CopyToOutputDirectory="Always" /> </ItemGroup> </Project> |
Now we can publish the release version our application either using Visual Studio or CLI. You can use the following command to publish the application using command prompt.
dotnet publish -c Release
To publish using Visual Studio:
Now that we have set up everything it is time to deploy the application.
gcloud app deploy
gcloud app browse
To avoid incurring charges, you can delete your Cloud project to stop billing for all the resources used within that project.