WPF features are not available in MGCB Pipeline
Thank you for your support, my name is Onodera.
I’m trying to create a SpriteFont creation function using the WPF function in MGCB Pipeline.
I get an MGCB build error, so please let me know if there is a solution.
【環境】
- Windows 10 Pro 1909
- Visual Studio 2019 16.7.5
- MonoGame 3.8.0.1641
First, it worked fine with MonoGame 3.7. An error has occurred since the version was upgraded to 3.8.
I tried to create the following projects in 3.8, but all of them gave an error.
a. Create Pipeline in .NET Core
b. Create Pipeline with .NET Framework
c. Create a Pipeline in .NET Standard (however, Standard doesn’t use WPF, so it internally refers to the .NET Framework)
Since a, b, and c are all doing the same thing, let’s take a as an example.
The project file sets “Use WPF” and “Microsoft .NET.Sdk.WindowsDesktop” to enable the use of WPF functions.
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MonoGame.Framework.Content.Pipeline" Version="3.8.0.1641" />
<PackageReference Include="MonoGame.Framework.WindowsDX" Version="3.8.0.1641" />
</ItemGroup>
</Project>
The Pipeline code looks like this:
It’s a test code, so it just references the WPF code. No special processing is done for SpriteFont.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using TInput = Microsoft.Xna.Framework.Content.Pipeline.Graphics.FontDescription;
using TOutput = WpfFontPipelineNetFramework.WpfSpriteFontContent;
namespace WpfFontPipelineNetFramework
{
[ContentProcessor(DisplayName = "WpfCore")]
public class Processor1 : ContentProcessor<TInput, TOutput>
{
public override TOutput Process(TInput input, ContentProcessorContext context)
{
var fontContnet = new WpfSpriteFontContent();
var fontWeight = ((input.Style & FontDescriptionStyle.Bold) == FontDescriptionStyle.Bold) ? FontWeights.Bold : FontWeights.Regular;
var fontStyle = ((input.Style & FontDescriptionStyle.Italic) == FontDescriptionStyle.Italic) ? FontStyles.Italic : FontStyles.Normal;
var typeface = new Typeface(new System.Windows.Media.FontFamily(input.FontName), fontStyle, fontWeight, FontStretches.Normal);
typeface.TryGetGlyphTypeface(out GlyphTypeface glyphTypeface);
return fontContnet;
}
}
public class WpfSpriteFontContent
{
public Texture2DContent Texture { get; set; }
public List<Rectangle> Glyphs { get; set; }
public List<Rectangle> Cropping { get; set; }
public List<char> CharacterMap { get; set; }
public int LineSpacing { get; set; }
public float Spacing { get; set; }
public List<Microsoft.Xna.Framework.Vector3> Kerning { get; set; }
[ContentSerializer(AllowNull = true)]
public char? DefaultCharacter { get; set; }
public WpfSpriteFontContent()
{
Texture = new Texture2DContent();
Glyphs = new List<Rectangle>();
Cropping = new List<Rectangle>();
CharacterMap = new List<char>();
Kerning = new List<Vector3>();
}
}
}
When you refer to the DLL created by MGCB and set “WpfCore” in the Processor of Font.spritefont and build it, the following error is output.
C:/xxxx/MonoGamePipelineWpfTest/Font.spritefont: error: Processor ‘Processor1’ had unexpected failure!
System.IO.FileNotFoundException: Could not load file or assembly ‘PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’. The specified file could not be found.
File name: ‘PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’
at WpfFontPipelineNetCore.Processor1.Process(FontDescription input, ContentProcessorContext context)
at Microsoft.Xna.Framework.Content.Pipeline.ContentProcessor`2.Microsoft.Xna.Framework.Content.Pipeline.IContentProcessor.Process(Object input, ContentProcessorContext context) in C:\BuildAgents\MonoGameWin1\work\f7381a85a626990\MonoGame.Framework.Content.Pipeline\ContentProcessor.cs:line 60
at MonoGame.Framework.Content.Pipeline.Builder.PipelineManager.ProcessContent(PipelineBuildEvent pipelineEvent) in C:\BuildAgents\MonoGameWin1\work\f7381a85a626990\MonoGame.Framework.Content.Pipeline\Builder\PipelineManager.cs:line 717
The following error is output in the .NET Framework version.
Failed to load assembly ‘C:/xxxx/MonoGamePipelineWpfTest/dll/Framework/WpfFontPipelineNetFramework.dll’: Unable to load one or more of the requested types.
Could not load file or assembly ‘System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The specified file could not be found.
C:/xxxx/MonoGamePipelineWpfTest/Font.spritefont
Warning: Unable to load one or more of the requested types.
Could not load file or assembly ‘System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51’. The specified file could not be found.
C:/xxxx/MonoGamePipelineWpfTest/Font.spritefont: error: Failed to create processor ‘Processor1’
For the .NET Standard version, the same error will be output because the above project will be referenced.
Is there any solution?
By the way, all of the following dlls exist.
- C:\Windows\Microsoft_NET\assembly\GAC_32\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll
- C:\Windows\Microsoft_NET\assembly\GAC_64\PresentationCore\v4.0_4.0.0.0__31bf3856ad364e35\PresentationCore.dll
The sample project is on OneDrive.
https://1drv.ms/u/s!Ap-DYzVqMCtRsuNG6hgsR3L_vjDrAA?e=BXku96
Thank you.