Is there a way to get access to the System.Printing namespace from a .net core console application. I see it is available for a .net core WPF application. There is nothing in the documentation that specifies it is only available for WPF.
I have looked for System.Printing NuGet package with no luck
I am using C# .NET Core 3.1 on Windows 10
The System.Printing namespace also includes many enumerations that describe printer capabilities, such as whether a printer can produce collated output, and that specify instructions to printers, such as the paper size to use for a print job. This namespace is part of the enhanced printing services provided with Windows Presentation Foundation.
One option is to split monolithic service (s) into multiple microservices and run your .NET Core app under i.e. Linux and let your print service on windows and have the .NET Core service call into the print service when it needs to print something Show activity on this post.
Managed code developers using Windows Forms must use the APIs in the System.Drawing.Printing namespace. Classes within the System.Printing namespace are not supported for use within a Windows service or ASP.NET application or service.
Classes within the System.Printing namespace are not supported for use within a Windows service or ASP.NET application or service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.
Add the following framework reference to your .csproj file to be able to reference the System.Printing
namespace:
<ItemGroup>
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" />
</ItemGroup>
Sources: https://github.com/dotnet/wpf/issues/871#issuecomment-501498045 https://docs.microsoft.com/en-us/dotnet/core/porting/cpp-cli
Sample:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" />
</ItemGroup>
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With