Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the access to the System.Printing namespace in .NET Core Console Application

Tags:

c#

.net-core

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

like image 582
webwake Avatar asked Feb 25 '20 15:02

webwake


People also ask

What is the printing namespace in Windows?

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.

How can I run a print service on Linux?

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.

Which namespace should I use for Windows Forms APIs?

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.

Can I use a printing class in a Windows 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.


1 Answers

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>
like image 179
Jaws Avatar answered Oct 20 '22 20:10

Jaws