admin管理员组

文章数量:1277346

After publishing a console app (using dotnet publish), the console app does not display the emojis properly in Windows Terminal.

Interestingly, if I just use dotnet run, the emojis appear properly in Windows Terminal.

I published the console app using --no-self-contained and without it. Both result with the emojis not showing properly.

This is happening on both Windows 10 version 22H2 and Windows 11 version 23H2.

I'm using .NET 9.0.200.

Sample code:

const string CHECKMARK1 = "✅";
const string CHECKMARK2 = "\u2705";

Console.WriteLine(CHECKMARK1);
Console.WriteLine(CHECKMARK2);
Console.WriteLine("✅");
Console.WriteLine("\u2705");

Output using dotnet run in Windows Terminal:

✅
✅
✅
✅

EXE output after using dotnet publish in Windows Terminal:

?
?
?
?

Also, for thoroughness, here are the commands I used for publishing:

dotnet.exe publish "c:\path\to\emoji.csproj" --runtime "win-x64" --no-self-contained /p:PublishSingleFile=true

dotnet.exe publish "c:\path\to\emoji.csproj" --runtime "win-x64" /p:PublishSingleFile=true

I would appreciate any insight into why this is happening.

After publishing a console app (using dotnet publish), the console app does not display the emojis properly in Windows Terminal.

Interestingly, if I just use dotnet run, the emojis appear properly in Windows Terminal.

I published the console app using --no-self-contained and without it. Both result with the emojis not showing properly.

This is happening on both Windows 10 version 22H2 and Windows 11 version 23H2.

I'm using .NET 9.0.200.

Sample code:

const string CHECKMARK1 = "✅";
const string CHECKMARK2 = "\u2705";

Console.WriteLine(CHECKMARK1);
Console.WriteLine(CHECKMARK2);
Console.WriteLine("✅");
Console.WriteLine("\u2705");

Output using dotnet run in Windows Terminal:

✅
✅
✅
✅

EXE output after using dotnet publish in Windows Terminal:

?
?
?
?

Also, for thoroughness, here are the commands I used for publishing:

dotnet.exe publish "c:\path\to\emoji.csproj" --runtime "win-x64" --no-self-contained /p:PublishSingleFile=true

dotnet.exe publish "c:\path\to\emoji.csproj" --runtime "win-x64" /p:PublishSingleFile=true

I would appreciate any insight into why this is happening.

Share Improve this question edited Feb 24 at 16:12 marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked Feb 24 at 14:40 howdoicodehowdoicode 99311 silver badges20 bronze badges 2
  • It will also show question marks when ran in Visual Studio. i.sstatic/fzNKN3Y6.png – gunr2171 Commented Feb 24 at 14:50
  • @gunr2171 — Sure. Did you see my answer? It works the same way when executed in Visual Studio. – Sergey A Kryukov Commented Feb 25 at 0:22
Add a comment  | 

1 Answer 1

Reset to default 5

Before the first System.Console output call, you have to execute:

System.Console.OutputEncoding = System.Text.Encoding.UTF8;

In contrast to some other Console calls, this property assignment can throw an exception if the entry assembly has a wrong OutputType. It should be <OutputType>Exe</OutputType>.

本文标签: cEmojis not displaying properly after publishing exe in NET 9Stack Overflow