<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
- <IncludePlatformAttributes>true</IncludePlatformAttributes>
- <UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
+ <SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides access to GDI+ graphics functionality.
Commonly Used Types:
System.Drawing.Brush
System.Drawing.Font
System.Drawing.Graphics
-System.Drawing.Icon</PackageDescription>
+System.Drawing.Icon
+
+Unix support is disabled by default. See https://aka.ms/systemdrawingnonwindows for more information.</PackageDescription>
</PropertyGroup>
</Project>
\ No newline at end of file
<data name="PlatformNotSupported_Drawing" xml:space="preserve">
<value>System.Drawing is not supported on this platform.</value>
</data>
+ <data name="PlatformNotSupported_Unix" xml:space="preserve">
+ <value>System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.</value>
+ </data>
<data name="PrintDocumentDesc" xml:space="preserve">
<value>Defines an object that sends output to a printer.</value>
</data>
<data name="SystemDrawingCommon_PlatformNotSupported" xml:space="preserve">
<value>System.Drawing.Common is not supported on this platform.</value>
</data>
-</root>
\ No newline at end of file
+</root>
Link="Common\Interop\Windows\User32\Interop.LOGFONT.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Gdi32\Interop.RasterOp.cs"
Link="Common\Interop\Windows\Gdi32\Interop.RasterOp.cs" />
+ <Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs"
+ Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
Link="Common\System\Text\ValueStringBuilder.cs" />
<Compile Include="$(CommonPath)System\Obsoletions.cs"
<Compile Include="System\Drawing\Internal\GpPathData.cs" />
<Compile Include="System\Drawing\Internal\GPStream.cs" />
<Compile Include="System\Drawing\Internal\SystemColorTracker.cs" />
- <Compile Include="System\Drawing\LocalAppContextSwitches.cs" />
+ <Compile Include="System\Drawing\LocalAppContextSwitches.Windows.cs" />
<Compile Include="System\Drawing\Pen.Windows.cs" />
<Compile Include="System\Drawing\Printing\DefaultPrintController.cs" />
<Compile Include="System\Drawing\Printing\ModeField.cs" />
<Compile Include="Interop\Windows\Interop.Shell32.cs" />
<Compile Include="Interop\Windows\Interop.User32.cs" />
<Compile Include="Interop\Windows\Interop.Winspool.cs" />
- <Compile Include="$(CommonPath)System\LocalAppContextSwitches.Common.cs"
- Link="System\LocalAppContextSwitches.Common.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Gdi32\Interop.CombineRgn.cs"
<Compile Include="System\Drawing\GdiplusNative.Unix.cs" />
<Compile Include="System\Drawing\GdiPlusStreamHelper.Unix.cs" />
<Compile Include="System\Drawing\LibX11Functions.cs" />
+ <Compile Include="System\Drawing\LocalAppContextSwitches.Unix.cs" />
<Compile Include="System\Drawing\MarshallingHelpers.cs" />
<Compile Include="System\Drawing\Image.Unix.cs" />
<Compile Include="System\Drawing\Pen.Unix.cs" />
internal static void EnsureRegistered()
{
- // dummy call to trigger the static constructor
+ if (!LocalAppContextSwitches.EnableUnixSupport)
+ throw new PlatformNotSupportedException(SR.PlatformNotSupported_Unix);
}
}
}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.CompilerServices;
+
+namespace System
+{
+ internal static partial class LocalAppContextSwitches
+ {
+ private static int s_enableUnixSupport;
+ public static bool EnableUnixSupport
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ return GetCachedSwitchValue(@"System.Drawing.EnableUnixSupport", ref s_enableUnixSupport);
+ }
+ }
+ }
+}
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
+using Microsoft.DotNet.RemoteExecutor;
using Microsoft.DotNet.XUnitExtensions;
using Xunit;
yield return new object[] { "16x16_nonindexed_24bit.png", 16, 16, PixelFormat.Format24bppRgb, ImageFormat.Png };
}
+ [PlatformSpecific(TestPlatforms.AnyUnix)]
+ [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
+ public void UnixSupportDisabledThrows()
+ {
+ RemoteExecutor.Invoke(() =>
+ {
+ AppContext.SetSwitch("System.Drawing.EnableUnixSupport", false);
+ TypeInitializationException exception = Assert.Throws<TypeInitializationException>(() => new Bitmap(100, 100));
+ Assert.IsType<PlatformNotSupportedException>(exception.InnerException);
+ }).Dispose();
+ }
+
[ConditionalTheory(Helpers.IsDrawingSupported)]
[MemberData(nameof(Ctor_FilePath_TestData))]
public void Ctor_FilePath(string filename, int width, int height, PixelFormat pixelFormat, ImageFormat rawFormat)
--- /dev/null
+{
+ "configProperties": {
+ "System.Drawing.EnableUnixSupport": true
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "configProperties": {
+ "System.Drawing.EnableUnixSupport": true
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "configProperties": {
+ "System.Drawing.EnableUnixSupport": true
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "configProperties": {
+ "System.Drawing.EnableUnixSupport": true
+ }
+}
\ No newline at end of file