Skip to content

Commit d3ee883

Browse files
committed
add windows .NET Core support
1 parent d35d3db commit d3ee883

3 files changed

Lines changed: 81 additions & 4 deletions

File tree

.github/workflows/dotnet-core.yml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ name: FSharp.Data.SqlClient 'Actions' CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, fb ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ master, fb ]
88

99
jobs:
10-
build:
11-
10+
build-linux:
1211
runs-on: ubuntu-latest
1312

1413
services:
@@ -60,3 +59,45 @@ jobs:
6059
6160
- name: Build
6261
run: ./build.sh
62+
63+
build-windows:
64+
runs-on: windows-latest
65+
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- name: Setup .NET
70+
uses: actions/setup-dotnet@v4
71+
with:
72+
dotnet-version: 9.0.x
73+
74+
- name: Install SQL Server
75+
uses: potatoqualitee/mssqlsuite@v1.7
76+
with:
77+
install: sqlengine
78+
sa-password: YourStrong@Passw0rd
79+
80+
- name: Restore AdventureWorks2012 from backup
81+
shell: pwsh
82+
run: |
83+
$BAK = "$env:TEMP\AdventureWorks2012.bak"
84+
Write-Host "Downloading AdventureWorks2012.bak..."
85+
Invoke-WebRequest -Uri "https://github.com/Microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorks2012.bak" -OutFile $BAK
86+
87+
# Get the default data path from SQL Server
88+
$dataPath = Invoke-Sqlcmd -ServerInstance "localhost" -Username "SA" -Password "YourStrong@Passw0rd" -TrustServerCertificate -Query "SELECT SERVERPROPERTY('InstanceDefaultDataPath') AS DataPath" | Select-Object -ExpandProperty DataPath
89+
90+
Write-Host "Restoring AdventureWorks2012 to $dataPath ..."
91+
$restoreQuery = @"
92+
RESTORE DATABASE [AdventureWorks2012]
93+
FROM DISK = N'$BAK'
94+
WITH MOVE 'AdventureWorks2012' TO '${dataPath}AdventureWorks2012_Data.mdf',
95+
MOVE 'AdventureWorks2012_log' TO '${dataPath}AdventureWorks2012_Log.ldf',
96+
REPLACE, NOUNLOAD, STATS = 5
97+
"@
98+
Invoke-Sqlcmd -ServerInstance "localhost" -Username "SA" -Password "YourStrong@Passw0rd" -TrustServerCertificate -Query $restoreQuery -QueryTimeout 120
99+
100+
echo "GITHUB_ACTION_SQL_SERVER_CONNECTION_STRING=Data Source=localhost,1433;Initial Catalog=AdventureWorks2012;User ID=SA;Password=YourStrong@Passw0rd;TrustServerCertificate=True;" >> $env:GITHUB_ENV
101+
102+
- name: Build
103+
run: .\build.cmd

src/SqlClient.DesignTime/SingleRootTypeProvider.fs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
open FSharp.Data.SqlClient
44
open Microsoft.FSharp.Core.CompilerServices
55
open System.Reflection
6+
open System.Runtime.InteropServices
67
open System
78

89
[<AbstractClass>]
@@ -17,6 +18,31 @@ type SingleRootTypeProvider(config: TypeProviderConfig, providerName, parameters
1718
addDefaultProbingLocation = true
1819
)
1920

21+
// On Windows, Microsoft.Data.SqlClient loads the native SNI library via P/Invoke.
22+
// When the type provider runs inside the F# compiler, the native DLL search path
23+
// may not include the TP output directory. Register a resolver so the runtime can
24+
// find Microsoft.Data.SqlClient.SNI.dll next to the TP assembly.
25+
#if USE_SYSTEM_DATA_COMMON_DBPROVIDERFACTORIES
26+
static do
27+
if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then
28+
let tpDir =
29+
System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
30+
31+
let handler =
32+
System.Runtime.InteropServices.DllImportResolver(fun libraryName assembly searchPath ->
33+
if libraryName = "Microsoft.Data.SqlClient.SNI.dll" then
34+
let candidate = System.IO.Path.Combine(tpDir, "Microsoft.Data.SqlClient.SNI.dll")
35+
36+
if System.IO.File.Exists(candidate) then
37+
NativeLibrary.Load(candidate)
38+
else
39+
System.IntPtr.Zero
40+
else
41+
System.IntPtr.Zero)
42+
43+
NativeLibrary.SetDllImportResolver(typeof<Microsoft.Data.SqlClient.SqlConnection>.Assembly, handler)
44+
#endif
45+
2046
let cache = new Cache<ProvidedTypeDefinition>()
2147

2248
do

src/SqlClient.DesignTime/SqlClient.DesignTime.fsproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,31 @@
8888
<_TPRid Condition="$([MSBuild]::IsOSPlatform('Linux'))">unix</_TPRid>
8989
<_TPRid Condition="$([MSBuild]::IsOSPlatform('OSX'))">unix</_TPRid>
9090
<_TPRid Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</_TPRid>
91+
<_TPNativeRid Condition="$([MSBuild]::IsOSPlatform('Windows'))">win-x64</_TPNativeRid>
92+
<_TPNativeRid Condition="'$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier)</_TPNativeRid>
9193
<_TPOutputDir>$(TargetDir)</_TPOutputDir>
9294
<_TPRuntimeDir>$(_TPOutputDir)runtimes/$(_TPRid)/lib/$(TargetFramework)</_TPRuntimeDir>
9395
<!-- For netstandard2.0, NuGet does not copy RID-specific assemblies.
9496
Fall back to the net9.0 sibling output (built first). -->
9597
<_TPRuntimeDir Condition="!Exists('$(_TPRuntimeDir)')">$(_TPOutputDir)../net9.0/runtimes/$(_TPRid)/lib/net9.0</_TPRuntimeDir>
98+
<_TPNativeDir>$(_TPOutputDir)runtimes/$(_TPNativeRid)/native</_TPNativeDir>
9699
</PropertyGroup>
97100
<ItemGroup>
98101
<_RidSpecificAssemblies Include="$(_TPRuntimeDir)/*.dll" />
102+
<_NativeAssemblies Include="$(_TPNativeDir)/*.dll" Condition="'$(_TPNativeRid)' != ''" />
99103
</ItemGroup>
100104
<Message Importance="high" Text="TP RID copy: $(_TPRuntimeDir) -> $(_TPOutputDir)" />
101105
<Copy SourceFiles="@(_RidSpecificAssemblies)"
102106
DestinationFolder="$(_TPOutputDir)"
103107
OverwriteReadOnlyFiles="true"
104108
SkipUnchangedFiles="false"
105109
Condition="Exists('$(_TPRuntimeDir)')" />
110+
<Message Importance="high" Text="TP native copy: $(_TPNativeDir) -> $(_TPOutputDir)" Condition="'$(_TPNativeRid)' != ''" />
111+
<Copy SourceFiles="@(_NativeAssemblies)"
112+
DestinationFolder="$(_TPOutputDir)"
113+
OverwriteReadOnlyFiles="true"
114+
SkipUnchangedFiles="false"
115+
Condition="'$(_TPNativeRid)' != '' and Exists('$(_TPNativeDir)')" />
106116
</Target>
107117
<Import Project="..\..\.paket\Paket.Restore.targets" />
108118
</Project>

0 commit comments

Comments
 (0)