Skip to content

Commit

Permalink
Added net6.0-windows compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
codebude committed Dec 7, 2021
1 parent 58caa70 commit 64012d9
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions QRCoder.Xaml/QRCoder.Xaml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<!-- <UseWindowsForms Condition="'$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0-windows'">true</UseWindowsForms> -->
<UseWPF Condition="'$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0-windows'">true</UseWPF>
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0-windows'">$(DefineConstants);NET5_0_WINDOWS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0-windows'">$(DefineConstants);NET6_0_WINDOWS</DefineConstants>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
Expand Down
9 changes: 8 additions & 1 deletion QRCoder/PostscriptQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS

This comment has been minimized.

Copy link
@andrerom

andrerom Dec 15, 2021

@codebude Is this missing NET6_0?

I'm on .Net6 on Mac and by pulling in 1.4.3 I'm getting error about SvgQRCode could not be found.

This comment has been minimized.

Copy link
@codebude

codebude Dec 15, 2021

Author Owner

Hi Andre, that's wanted. Microsoft dropped System.Drawing in .net 6.0 for non-windows platforms. Since SvgQRCode uses System.Drawing it is only available for .net6.0-windows... I explained it in detail over here: #361 (comment)

This comment has been minimized.

Copy link
@andrerom

andrerom Dec 15, 2021

Ok, unexpected to get such a break in a patch release. But whats done is done.

In the end I assuming SVG is the best choice for responsive QR codes, and it's much easier to work with as you can more easily inline the payload within html when you don't need to generate to static file for later use.

So would be good to have a roadmap for when it will return cross platform. And if that means a ImageSharp based stack (👍) or something else entirely.

This comment has been minimized.

Copy link
@codebude

codebude Dec 15, 2021

Author Owner

Yes, unfortunately until now QRCoder doesn't follow semantic versioning scheme. I just upcounted the last part of the version number. (Back in the days when I started QRCoder I didn't know it better and just kept this versioning scheme. But I plan to do better/in a more semantic way in the future.)
Regards cross compatibility. I already started planning of 2.0.0, backed on ImageSharp. My plan was to wait for ImageSharp 2.0 because there seem to be breaking changes in ImageSharp 2.0 and thus I wanted to avoid a 1.X based QRCoder. But things getting urgent and more users are asking for better cross platform support in QRCoder so I might start soon, backed on ImageSharp 1.X.

This comment has been minimized.

Copy link
@andrerom

andrerom Dec 20, 2021

But things getting urgent and more users are asking for better cross platform support in QRCoder so I might start soon, backed on ImageSharp 1.X.

If ImageSharp is left as internal detail and not exposed, then it "shouldn't be a problem"* semantic version wise

* So, from simplification to reality... in regards to planned package split, easiest if all parts who rely on ImageSharp end up in one package, and hypothetical base classes for this remains private until refactored for ImageSharp 2.X. But your call how you deal with this, Semantic Versioning does not specify if you can bump major versions of sub packages or not, the conservative approach is just to not do it unless forced to (i.e. security issues).

using System;
using System.Drawing;
using static QRCoder.QRCodeGenerator;

namespace QRCoder
{

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public class PostscriptQRCode : AbstractQRCode, IDisposable
{
/// <summary>
Expand Down Expand Up @@ -139,6 +143,9 @@ sc sc scale
";
}

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static class PostscriptQRCodeHelper
{
public static string GetQRCode(string plainText, int pointsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, bool epsFormat = false)
Expand Down
8 changes: 7 additions & 1 deletion QRCoder/QRCode.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using static QRCoder.QRCodeGenerator;

namespace QRCoder
{
#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public class QRCode : AbstractQRCode, IDisposable
{
/// <summary>
Expand Down Expand Up @@ -125,6 +128,9 @@ internal GraphicsPath CreateRoundedRectanglePath(RectangleF rect, int cornerRadi
}
}

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static class QRCodeHelper
{
public static Bitmap GetQRCode(string plainText, int pixelsPerModule, Color darkColor, Color lightColor, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, Bitmap icon = null, int iconSizePercent = 15, int iconBorderWidth = 0, bool drawQuietZones = true)
Expand Down
6 changes: 5 additions & 1 deletion QRCoder/QRCoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>net35;net40;netstandard1.3;netstandard2.0;net5.0;net5.0-windows;net6.0;net6.0-windows</TargetFrameworks>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0-windows'">$(DefineConstants);NET5_0_WINDOWS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0-windows'">$(DefineConstants);NET6_0_WINDOWS</DefineConstants>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
Expand Down Expand Up @@ -45,8 +46,11 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net5.0' or '$(TargetFramework)' == 'net5.0-windows' ">
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows' ">
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>

<PropertyGroup>
<FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
Expand Down
8 changes: 7 additions & 1 deletion QRCoder/SvgQRCode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0
#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS
using QRCoder.Extensions;
using System;
using System.Collections;
Expand All @@ -11,6 +11,9 @@

namespace QRCoder
{
#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public class SvgQRCode : AbstractQRCode, IDisposable
{
/// <summary>
Expand Down Expand Up @@ -376,6 +379,9 @@ public enum MediaType : int
}
}

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public static class SvgQRCodeHelper
{
public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null)
Expand Down
7 changes: 7 additions & 0 deletions QRCoderConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace QRCoderConsole
{
#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
class MainClass
{
public static void Main (string[] args)
Expand All @@ -21,6 +24,7 @@ public static void Main (string[] args)

QRCodeGenerator.ECCLevel eccLevel = QRCodeGenerator.ECCLevel.L;
SupportedImageFormat imageFormat = SupportedImageFormat.Png;

int pixelsPerModule = 20;
string foregroundColor = "#000000";
string backgroundColor = "#FFFFFF";
Expand Down Expand Up @@ -247,6 +251,9 @@ public QRCodeGenerator.ECCLevel GetECCLevel(string value)
return level;
}

#if NET6_0_WINDOWS
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
public ImageFormat GetImageFormat(string value)
{
switch (value.ToLower())
Expand Down
12 changes: 8 additions & 4 deletions QRCoderConsole/QRCoderConsole.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net45;net5.0;net5.0-windows</TargetFrameworks>
<UseWindowsForms Condition="'$(TargetFramework)' == 'net5.0-windows'">true</UseWindowsForms>
<UseWPF Condition="'$(TargetFramework)' == 'net5.0-windows'">true</UseWPF>
<TargetFrameworks>net45;net5.0;net5.0-windows;net6.0-windows</TargetFrameworks>
<!-- <UseWindowsForms Condition="'$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net5.0-windows'">true</UseWindowsForms>-->
<UseWPF Condition="'$(TargetFramework)' == 'net5.0-windows' or '$(TargetFramework)' == 'net6.0-windows'">true</UseWPF>
<DefineConstants Condition="'$(TargetFramework)' == 'net5.0-windows'">$(DefineConstants);NET5_0_WINDOWS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0-windows'">$(DefineConstants);NET6_0_WINDOWS</DefineConstants>
<Externalconsole>true</Externalconsole>
<OutputType>Exe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand All @@ -22,7 +23,10 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows' ">
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NDesk.Options.Core" Version="1.2.5" />
Expand Down

0 comments on commit 64012d9

Please sign in to comment.