Skip to content

Commit 8239867

Browse files
committed
SNOW-2026116 Remove Mono.Unix from Windows dependencies
1 parent 0b0406d commit 8239867

File tree

5 files changed

+230
-4
lines changed

5 files changed

+230
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#### For the official .NET Release Notes please refer to https://docs.snowflake.com/en/release-notes/clients-drivers/dotnet
22

33
# Changelog
4+
- v5.2.0
5+
- Added multi-targeting support to eliminate prerelease Mono.Unix dependency on Windows .NET 5+.
46
- v5.1.0
57
- Added `APPLICATION_PATH` to `CLIENT_ENVIRONMENT` sent during authentication to identify the application connecting to Snowflake.
68
- Renew idle sessions in the pool if keep alive is enabled.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ The Snowflake .NET connector supports the following .NET framework and libraries
1818

1919
Disclaimer: While the connector targets netstandard2.0 and may work with versions in its [support matrix](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0#select-net-standard-version), only the versions listed above are supported and tested by the connector
2020

21+
## Target Frameworks and Platform-Specific Builds
22+
23+
Starting from version **5.2.0**, the Snowflake .NET connector uses multi-targeting to provide optimized builds for different platforms:
24+
25+
| Target Framework | Platform | Description |
26+
|------------------|----------|-------------|
27+
| `net5.0-windows` | Windows (.NET 5+) | Optimized build for Windows without prerelease dependencies |
28+
| `net5.0` | Linux, macOS (.NET 5+) | Full Unix file system support with Mono.Unix |
29+
| `netstandard2.0` | All platforms | Backward compatibility for .NET Framework 4.6.2+ and .NET Core 3.1 |
30+
31+
**What this means for you:**
32+
33+
- **Windows users** on .NET 5 or higher will automatically receive a build without the prerelease `Mono.Unix` dependency, resulting in a cleaner dependency tree.
34+
- **Linux and macOS users** on .NET 5 or higher will receive a build with full Unix file permissions support through `Mono.Unix`.
35+
- **Older .NET versions** will continue to use the `netstandard2.0` build for maximum compatibility.
36+
37+
The appropriate build is automatically selected by NuGet based on your application's target framework and operating system.
38+
2139
Please refer to the [Notice](#notice) section below for information about safe usage of the .NET Driver
2240

2341
# Coding conventions for the project

Snowflake.Data/Core/Authenticator/ExternalBrowserAuthenticator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public async Task AuthenticateAsync(CancellationToken cancellationToken)
103103
}
104104
else
105105
{
106-
throw e;
106+
throw;
107107
}
108108
}
109109
}
@@ -141,7 +141,7 @@ public void Authenticate()
141141
}
142142
else
143143
{
144-
throw e;
144+
throw;
145145
}
146146
}
147147
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
// This file is compiled ONLY on Windows (when WINDOWS_BUILD is defined)
2+
// It provides stub implementations of Mono.Unix types that throw PlatformNotSupportedException
3+
// since Unix-specific operations should never be called on Windows (protected by runtime guards)
4+
5+
#if WINDOWS_BUILD
6+
7+
using System;
8+
using System.IO;
9+
using Microsoft.Win32.SafeHandles;
10+
11+
namespace Mono.Unix
12+
{
13+
[Flags]
14+
internal enum FileAccessPermissions
15+
{
16+
None = 0,
17+
OtherExecute = 1,
18+
OtherWrite = 2,
19+
OtherRead = 4,
20+
OtherReadWriteExecute = 7,
21+
GroupExecute = 8,
22+
GroupWrite = 16,
23+
GroupRead = 32,
24+
GroupReadWriteExecute = 56,
25+
UserExecute = 64,
26+
UserWrite = 128,
27+
UserRead = 256,
28+
UserReadWrite = 384,
29+
UserReadWriteExecute = 448,
30+
AllPermissions = 511,
31+
DefaultPermissions = 420
32+
}
33+
34+
internal class UnixStream : Stream
35+
{
36+
private const string ErrorMessage = "Unix file operations are not supported on Windows";
37+
38+
public UnixUserInfo OwnerUser => throw new PlatformNotSupportedException(ErrorMessage);
39+
public UnixGroupInfo OwnerGroup => throw new PlatformNotSupportedException(ErrorMessage);
40+
public long OwnerUserId => throw new PlatformNotSupportedException(ErrorMessage);
41+
public long OwnerGroupId => throw new PlatformNotSupportedException(ErrorMessage);
42+
public FileAccessPermissions FileAccessPermissions => throw new PlatformNotSupportedException(ErrorMessage);
43+
44+
public override bool CanRead => throw new PlatformNotSupportedException(ErrorMessage);
45+
public override bool CanSeek => throw new PlatformNotSupportedException(ErrorMessage);
46+
public override bool CanWrite => throw new PlatformNotSupportedException(ErrorMessage);
47+
public override long Length => throw new PlatformNotSupportedException(ErrorMessage);
48+
public override long Position
49+
{
50+
get => throw new PlatformNotSupportedException(ErrorMessage);
51+
set => throw new PlatformNotSupportedException(ErrorMessage);
52+
}
53+
54+
public override void Flush() => throw new PlatformNotSupportedException(ErrorMessage);
55+
public override int Read(byte[] buffer, int offset, int count) => throw new PlatformNotSupportedException(ErrorMessage);
56+
public override long Seek(long offset, SeekOrigin origin) => throw new PlatformNotSupportedException(ErrorMessage);
57+
public override void SetLength(long value) => throw new PlatformNotSupportedException(ErrorMessage);
58+
public override void Write(byte[] buffer, int offset, int count) => throw new PlatformNotSupportedException(ErrorMessage);
59+
}
60+
61+
internal class UnixFileInfo
62+
{
63+
private const string ErrorMessage = "Unix file operations are not supported on Windows";
64+
65+
public UnixFileInfo(string path)
66+
{
67+
throw new PlatformNotSupportedException(ErrorMessage);
68+
}
69+
70+
public string FullName => throw new PlatformNotSupportedException(ErrorMessage);
71+
public bool Exists => throw new PlatformNotSupportedException(ErrorMessage);
72+
public FileAccessPermissions FileAccessPermissions => throw new PlatformNotSupportedException(ErrorMessage);
73+
public long OwnerUserId => throw new PlatformNotSupportedException(ErrorMessage);
74+
public UnixUserInfo OwnerUser => throw new PlatformNotSupportedException(ErrorMessage);
75+
public long Length => throw new PlatformNotSupportedException(ErrorMessage);
76+
77+
public Stream Create(FileAccessPermissions permissions)
78+
=> throw new PlatformNotSupportedException(ErrorMessage);
79+
80+
public UnixStream OpenRead()
81+
=> throw new PlatformNotSupportedException(ErrorMessage);
82+
83+
public UnixStream Open(FileMode mode, FileAccess access, Native.FilePermissions permissions)
84+
=> throw new PlatformNotSupportedException(ErrorMessage);
85+
}
86+
87+
internal class UnixDirectoryInfo
88+
{
89+
private const string ErrorMessage = "Unix directory operations are not supported on Windows";
90+
91+
public UnixDirectoryInfo(string path)
92+
{
93+
throw new PlatformNotSupportedException(ErrorMessage);
94+
}
95+
96+
public string FullName => throw new PlatformNotSupportedException(ErrorMessage);
97+
public bool Exists => throw new PlatformNotSupportedException(ErrorMessage);
98+
public FileAccessPermissions FileAccessPermissions => throw new PlatformNotSupportedException(ErrorMessage);
99+
public long OwnerUserId => throw new PlatformNotSupportedException(ErrorMessage);
100+
public UnixUserInfo OwnerUser => throw new PlatformNotSupportedException(ErrorMessage);
101+
102+
public void Create(FileAccessPermissions permissions)
103+
=> throw new PlatformNotSupportedException(ErrorMessage);
104+
}
105+
106+
internal class UnixUserInfo
107+
{
108+
private const string ErrorMessage = "Unix user operations are not supported on Windows";
109+
110+
public UnixUserInfo(long userId)
111+
{
112+
throw new PlatformNotSupportedException(ErrorMessage);
113+
}
114+
115+
public long UserId => throw new PlatformNotSupportedException(ErrorMessage);
116+
}
117+
118+
internal class UnixGroupInfo
119+
{
120+
private const string ErrorMessage = "Unix group operations are not supported on Windows";
121+
122+
public UnixGroupInfo(long groupId)
123+
{
124+
throw new PlatformNotSupportedException(ErrorMessage);
125+
}
126+
127+
public long GroupId => throw new PlatformNotSupportedException(ErrorMessage);
128+
}
129+
}
130+
131+
namespace Mono.Unix.Native
132+
{
133+
[Flags]
134+
internal enum FilePermissions
135+
{
136+
S_ISUID = 0x0800,
137+
S_ISGID = 0x0400,
138+
S_ISVTX = 0x0200,
139+
S_IRUSR = 0x0100,
140+
S_IWUSR = 0x0080,
141+
S_IXUSR = 0x0040,
142+
S_IRGRP = 0x0020,
143+
S_IWGRP = 0x0010,
144+
S_IXGRP = 0x0008,
145+
S_IROTH = 0x0004,
146+
S_IWOTH = 0x0002,
147+
S_IXOTH = 0x0001,
148+
149+
S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR,
150+
S_IRWXG = S_IRGRP | S_IWGRP | S_IXGRP,
151+
S_IRWXO = S_IROTH | S_IWOTH | S_IXOTH,
152+
153+
ACCESSPERMS = S_IRWXU | S_IRWXG | S_IRWXO,
154+
ALLPERMS = S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO,
155+
DEFFILEMODE = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
156+
}
157+
158+
internal static class Syscall
159+
{
160+
private const string ErrorMessage = "Unix syscalls are not supported on Windows";
161+
162+
public static int mkdir(string path, FilePermissions permissions)
163+
=> throw new PlatformNotSupportedException(ErrorMessage);
164+
165+
public static long chown(string path, int userId, int groupId)
166+
=> throw new PlatformNotSupportedException(ErrorMessage);
167+
168+
public static long chmod(string path, FilePermissions permissions)
169+
=> throw new PlatformNotSupportedException(ErrorMessage);
170+
171+
public static long getuid()
172+
=> throw new PlatformNotSupportedException(ErrorMessage);
173+
174+
public static long getgid()
175+
=> throw new PlatformNotSupportedException(ErrorMessage);
176+
177+
public static long geteuid()
178+
=> throw new PlatformNotSupportedException(ErrorMessage);
179+
180+
public static long getegid()
181+
=> throw new PlatformNotSupportedException(ErrorMessage);
182+
}
183+
}
184+
185+
#endif
186+

Snowflake.Data/Snowflake.Data.csproj

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<!-- net5.0-windows for Windows prerelease Mono.Unix dependency-->
4+
<TargetFrameworks>netstandard2.0;net5.0;net5.0-windows</TargetFrameworks>
45
<Title>Snowflake.Data</Title>
56
<PackageId>Snowflake.Data</PackageId>
67
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
@@ -18,21 +19,40 @@
1819
<LangVersion>8</LangVersion>
1920
</PropertyGroup>
2021

22+
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
23+
<DefineConstants>$(DefineConstants);WINDOWS_BUILD</DefineConstants>
24+
</PropertyGroup>
25+
2126
<ItemGroup>
2227
<PackageReference Include="Apache.Arrow" Version="14.0.2" />
2328
<PackageReference Include="AWSSDK.S3" Version="4.0.4" />
2429
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.10.0" />
2530
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
2631
<PackageReference Include="Azure.Storage.Common" Version="12.12.0" />
2732
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.5" />
28-
<PackageReference Include="Mono.Unix" Version="7.1.0-final.1.21458.1" />
2933
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3034
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
3135
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.34.0" />
3236
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
3337
<PackageReference Include="Tomlyn.Signed" Version="0.17.0" />
3438
</ItemGroup>
3539

40+
<!-- Mono.Unix dependency for Unix platforms (netstandard2.0 and net5.0) -->
41+
<!-- NOT included for net5.0-windows to avoid prerelease dependency on Windows -->
42+
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'net5.0'">
43+
<PackageReference Include="Mono.Unix" Version="7.1.0-final.1.21458.1" />
44+
</ItemGroup>
45+
46+
<!-- Exclude platform shims from all targets by default (SDK auto-includes all .cs files) -->
47+
<ItemGroup>
48+
<Compile Remove="PlatformShims\**\*.cs" />
49+
</ItemGroup>
50+
51+
<!-- Include Mono.Unix Windows shim ONLY for net5.0-windows target -->
52+
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
53+
<Compile Include="PlatformShims\MonoUnixWindowsShim.cs" />
54+
</ItemGroup>
55+
3656
<ItemGroup Condition="'$(Configuration)' != 'Release'">
3757
<InternalsVisibleTo Include="Snowflake.Data.Tests" />
3858
<!--needed by Moq to be able to mock internal interfaces-->

0 commit comments

Comments
 (0)