dotnet publish -r win-x64 -c Release -o ./publish loses embedded fonts (WPF + .NET.Core 6 App).

Volk Volk 571 Reputation points
2023-01-16T18:11:31.6133333+00:00

Hi!

I recently solved the question here about attaching my fonts to the WPF + .NET.Core 6 application:
Font Family does not change to embedded fonts in XAML components. WPF + .NET.Core 6 App.

Everything works well in Visual Studio and in bin builds. But when I create an independent build for Win x64 (dotnet publish -r win-x64 -c Release -o ./publish) and run the project on another computer where there are no such fonts, then everything turns into a mess of standard Arial fonts.

To be honest, I am so tired of implementing custom fonts in WPF - for some reason they are still not fully implemented in the final build. What should I do so that custom fonts still work in the final assembly on computers where there are no such fonts?

Thanks!

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,667 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,140 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Blog Idlatif 0 Reputation points
    2023-01-17T19:17:50.95+00:00

    I placed my custom font, jura-light.ttf, in the Resources folder in the Windows explorer. I had early on in the project created and named the "Resources" folder where the project.sln file is.

    2> In Visual Studio in the Solution Explorer I double clicked Resources.resx. This brings up the "Resources.resx" tab in the window. I clicked on the tab and selected "Add Resource". This brings up a window where I can navigate. I navigated to jura-light.ttf and added it. The resource is now embedded.

    3> Next I click on the "Resources" folder within Visual Studio. Here I see the name of the file, which I can also get from the Windows folder. I remember the name for the next step.

    4> In the App.xaml folder I added the following code. "jura-light.ttf" is the custom font file name, and #jura is the font name. I stumbled on the name "jura" when I selected the font in the properties window for the label control. It was the first entry. That name has to be right to work. :


  2. Volk Volk 571 Reputation points
    2023-01-17T19:20:58.3766667+00:00

    Here, I have prepared a separate minimal project with this problem. Fonts works everywhere, but not in the publish version on other computers where there are no such fonts. I can't understand where I wrote something wrong and why the fonts are not attached to .exe assembly.

    I look forward to your reply. :)

    In Visual Studio (the computer has these fonts in the system):
    VS

    Build in Visual Studio (the computer has these fonts in the system):
    Build

    Publish (running the finished build on another computer where these fonts are not present) - fonts flew off:
    Publish

    The archive with the project (WPF + Net.Core 6.0) - These files will be available until 2023-01-31 21:05

    After that they will be deleted automatically!:

    GameLauncher.rar


  3. Volk Volk 571 Reputation points
    2023-01-19T16:30:23.2733333+00:00

    I do not understand! Asked to give the source code, I gave it. But no one helped me figure out how to fix the code so that the font was embedded in the project and displayed on any computer. Instead, you ask me to publish the project in different ways - but it doesn't work (you have the source code, try to publish it yourself and build it and check it...). Or take the source code, go to the Hindoo you recently fired, ask him for forgiveness, give him $5,000, let him tell how to attach the font? What is the problem?

    0 comments No comments