Skip to content

Commit 87e8aa5

Browse files
authored
9.2 Deployment (#84)
2 parents d49d1db + 0672f48 commit 87e8aa5

11 files changed

Lines changed: 229 additions & 38 deletions

File tree

.ci/BHoMBot/Nuget/BHoM.Interop.SQL.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<title></title>
1717
<dependencies>
1818
<group targetFramework="netstandard2.0">
19-
<dependency id="Microsoft.Data.SqlClient" version="5.1.1" />
19+
<dependency id="Microsoft.Data.SqlClient" version="7.0.0" />
2020
<dependency id="Microsoft.EntityFrameworkCore" version = "3.1.32" />
2121
<dependency id="NETStandard.Library" version="2.0.3" />
2222
<dependency id="Microsoft.CSharp" version="4.7.0" />

SQL_Adapter/AdapterActions/Execute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
using System.Data;
3535

36-
#if ZCTDEPLOY
36+
#if ZCTDEPLOY || NET7_0_OR_GREATER
3737
using Microsoft.Data.SqlClient;
3838
#else
3939
using System.Data.SqlClient;

SQL_Adapter/AdapterActions/Pull.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
using BH.oM.Adapters.SQL;
2929
using BH.Engine.SQL;
3030

31-
#if ZCTDEPLOY
31+
#if ZCTDEPLOY || NET7_0_OR_GREATER
3232
using Microsoft.Data.SqlClient;
3333
#else
3434
using System.Data.SqlClient;

SQL_Adapter/AdapterActions/Push.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
using System.Data;
3232
using System.Reflection;
3333

34-
#if ZCTDEPLOY
34+
#if ZCTDEPLOY || NET7_0_OR_GREATER
3535
using Microsoft.Data.SqlClient;
3636
#else
3737
using System.Data.SqlClient;

SQL_Adapter/SQL_Adapter.csproj

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
<Authors>BHoM</Authors>
88
<Copyright>Copyright © https://github.com/BHoM</Copyright>
99
<RootNamespace>BH.Adapter.SQL</RootNamespace>
10-
<FileVersion>9.1.0.0</FileVersion>
10+
<FileVersion>9.2.0.0</FileVersion>
1111
<Configurations>Debug;Release;ZeroCodeTool</Configurations>
1212
<OutputPath>..\Build\</OutputPath>
1313
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1414
</PropertyGroup>
1515

1616
<PropertyGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
17-
<TargetFramework>net472</TargetFramework>
17+
<TargetFrameworks>net472;net7.0</TargetFrameworks>
1818
<DefineConstants>INSTALLERDEPLOY</DefineConstants>
1919
</PropertyGroup>
2020
<PropertyGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
@@ -25,11 +25,35 @@
2525
<ItemGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
2626
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
2727
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.32" />
28-
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
28+
<PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.0" />
29+
</ItemGroup>
30+
31+
<ItemGroup Condition="'$(TargetFramework)'=='net7.0'">
32+
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
2933
</ItemGroup>
3034

3135
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
32-
<Exec Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
36+
<!-- net472: netfx subdirectory -->
37+
<Exec Condition="'$(TargetFramework)'=='net472'"
38+
Command="if not exist &quot;$(ProgramData)\BHoM\Assemblies\netfx\&quot; mkdir &quot;$(ProgramData)\BHoM\Assemblies\netfx&quot;" />
39+
<Exec Condition="'$(TargetFramework)'=='net472'"
40+
Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;$(ProgramData)\BHoM\Assemblies\netfx\&quot; /Y" />
41+
<!-- backward compatibility: root Assemblies subdirectory -->
42+
<Exec Condition="'$(TargetFramework)'=='net472'"
43+
Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;$(ProgramData)\BHoM\Assemblies&quot; /Y" />
44+
<!-- net7.0: SQL_Adapter.dll + Microsoft.Data.SqlClient.dll → net7.0 subdirectory -->
45+
<Exec Condition="'$(TargetFramework)'=='net7.0'"
46+
Command="if not exist &quot;$(ProgramData)\BHoM\Assemblies\net7.0\&quot; mkdir &quot;$(ProgramData)\BHoM\Assemblies\net7.0&quot;" />
47+
<Exec Condition="'$(TargetFramework)'=='net7.0'"
48+
Command="xcopy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;$(ProgramData)\BHoM\Assemblies\net7.0\&quot; /Y" />
49+
<Exec Condition="'$(TargetFramework)'=='net7.0'"
50+
Command="xcopy &quot;$(TargetDir)runtimes\win\lib\net6.0\Microsoft.Data.SqlClient.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies\net7.0\&quot; /Y" />
51+
<Exec Condition="'$(TargetFramework)'=='net7.0'"
52+
Command="xcopy &quot;$(TargetDir)runtimes\win-x64\native\Microsoft.Data.SqlClient.SNI.dll&quot; &quot;$(ProgramData)\BHoM\Assemblies\net7.0\&quot; /Y" />
53+
<Exec Condition="'$(TargetFramework)'=='net7.0'"
54+
Command="if not exist &quot;$(ProgramData)\BHoM\Settings\&quot; mkdir &quot;$(ProgramData)\BHoM\Settings\&quot; /Y" />
55+
<Exec Condition="'$(TargetFramework)'=='net7.0'"
56+
Command="xcopy &quot;$(ProjectDir)Settings\SqlClientAssemblyFix.json&quot; &quot;$(ProgramData)\BHoM\Settings\&quot; /Y" />
3357
</Target>
3458

3559
<ItemGroup>
@@ -65,7 +89,7 @@
6589
</Reference>
6690
</ItemGroup>
6791

68-
<ItemGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
92+
<ItemGroup Condition="('$(Configuration)'=='Debug' Or '$(Configuration)'=='Release') And '$(TargetFramework)'=='net472'">
6993
<Reference Include="System" />
7094
<Reference Include="System.Core" />
7195
<Reference Include="System.Xml.Linq" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"_t": "BH.oM.Adapters.SQL.SqlClientAssemblyFixSettings",
3+
"BHoM_Guid": "a3f2c1d0-b4e5-4f60-8a9b-c1d2e3f40001",
4+
"Name": "",
5+
"Tags": [],
6+
"Fragments": [],
7+
"CustomData": {},
8+
"InitialisationMethod": "BH.Engine.SQL.Compute.PreloadSqlClient",
9+
"InitialisationAssembly": "SQL_Engine"
10+
}

SQL_Adapter/SqlAdapter.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
using System.Threading.Tasks;
2828
using BH.Engine.Base;
2929

30-
#if ZCTDEPLOY
30+
#if ZCTDEPLOY || NET7_0_OR_GREATER
3131
using Microsoft.Data.SqlClient;
3232
#else
3333
using System.Data.SqlClient;
@@ -37,13 +37,29 @@ namespace BH.Adapter.SQL
3737
{
3838
public partial class SqlAdapter : BHoMAdapter
3939
{
40+
/***************************************************/
41+
/**** Static Constructor ****/
42+
/***************************************************/
43+
44+
#if NET7_0_OR_GREATER
45+
static SqlAdapter()
46+
{
47+
// Use managed TCP sockets instead of the native SNI DLL.
48+
// Required on CoreCLR hosts (Rhino 8) where the native SNI library is not on
49+
// the DLL search path. Effective only on actual .NET 7+ processes — ignored
50+
// when a net472 build runs under CoreCLR compat mode, which is why this
51+
// switch must live in the net7.0-targeted build, not the net472 build.
52+
AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true);
53+
}
54+
#endif
55+
4056
/***************************************************/
4157
/**** Constructors ****/
4258
/***************************************************/
4359

4460
public SqlAdapter(string server, string database)
4561
{
46-
#if ZCTDEPLOY
62+
#if ZCTDEPLOY || NET7_0_OR_GREATER
4763
m_ConnectionString = $"Server = {server}; Database = {database}; Trusted_Connection = True; TrustServerCertificate=True";
4864
#else
4965
m_ConnectionString = $"Server = {server}; Database = {database}; Trusted_Connection = True;";
@@ -112,9 +128,9 @@ private void Initialise()
112128
connection.Close();
113129
}
114130
}
115-
catch (PlatformNotSupportedException ex)
131+
catch (Exception ex)
116132
{
117-
BH.Engine.Base.Compute.RecordError("SQL is not supported in this UI. Please use Grasshopper in Rhino 7 or Excel.");
133+
BH.Engine.Base.Compute.RecordError($"Failed to connect to SQL Server: {ex.Message}");
118134
}
119135
}
120136

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* This file is part of the Buildings and Habitats object Model (BHoM)
3+
* Copyright (c) 2015 - 2026, the respective contributors. All rights reserved.
4+
*
5+
* Each contributor holds copyright over their respective contributions.
6+
* The project versioning (Git) records all such contribution source information.
7+
*
8+
*
9+
* The BHoM is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3.0 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* The BHoM is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public License
20+
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
21+
*/
22+
23+
using BH.Engine.Base;
24+
using BH.oM.Base;
25+
using BH.oM.Base.Attributes;
26+
using System;
27+
using System.Collections.Generic;
28+
using System.ComponentModel;
29+
using System.IO;
30+
using System.Linq;
31+
using System.Reflection;
32+
using System.Text;
33+
using System.Threading.Tasks;
34+
35+
namespace BH.Engine.SQL
36+
{
37+
public static partial class Compute
38+
{
39+
/***************************************************/
40+
/**** Public Methods ****/
41+
/***************************************************/
42+
43+
[Description("Make sure the correct version of Microsoft.Data.SqlClient before Rhino 8 has a chance to load its stub dll. Temporary solution while wating for a fix from McNeel.")]
44+
[Output("success", "return true if the code was executed without error.")]
45+
public static bool PreloadSqlClient()
46+
{
47+
// Only relevant on .NET 5+ (CoreCLR / Rhino 8).
48+
// On .NET Framework 4.7.2 (Rhino 7) the System.Data.SqlClient inbox provider is used
49+
// and Microsoft.Data.SqlClient is not involved.
50+
if (Environment.Version.Major < 5)
51+
return true;
52+
53+
// Assembly path for the version of the SqlCleint we want to load
54+
string assemblyPath = Path.Combine(
55+
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
56+
"BHoM", "Assemblies", "net7.0", "Microsoft.Data.SqlClient.dll");
57+
58+
// Guard: if SqlClient is already in the Default ALC we are too late.
59+
// Check whether what is loaded is the real implementation or Rhino's stub.
60+
Assembly already = AppDomain.CurrentDomain.GetAssemblies()
61+
.FirstOrDefault(a => a.GetName().Name == "Microsoft.Data.SqlClient");
62+
63+
if (already != null)
64+
{
65+
if (!already.Location.Contains("BHoM"))
66+
{
67+
BH.Engine.Base.Compute.RecordWarning(
68+
"Microsoft.Data.SqlClient was already loaded from Rhino's directory before the SQL Toolkit " +
69+
$"pre-load could run: {already.Location}. The SQL Adapter will not work correctly in Rhino 8. " +
70+
"This indicates that a Rhino plugin loaded the stub at Rhino startup. " +
71+
"Consider switching to the ALC-isolation approach described in 14_OptionA_ALC_Implementation.md.");
72+
return false;
73+
}
74+
75+
// Already loaded from BHoM's own directory — nothing to do.
76+
return true;
77+
}
78+
79+
if (!File.Exists(assemblyPath))
80+
{
81+
BH.Engine.Base.Compute.RecordWarning(
82+
$"Microsoft.Data.SqlClient.dll was not found at the expected path: {assemblyPath}. " +
83+
"The SQL Adapter may not work correctly in Rhino 8. " +
84+
"Ensure SQL_Adapter has been built with the net7.0 target framework.");
85+
return false;
86+
}
87+
88+
try
89+
{
90+
Assembly.LoadFrom(assemblyPath);
91+
return true;
92+
}
93+
catch (Exception ex)
94+
{
95+
BH.Engine.Base.Compute.RecordError(ex, "Failed to pre-load Microsoft.Data.SqlClient from the BHoM Assemblies folder.");
96+
return false;
97+
}
98+
}
99+
100+
/***************************************************/
101+
}
102+
}
103+
104+
105+
106+
107+

SQL_Engine/SQL_Engine.csproj

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
<Authors>BHoM</Authors>
88
<Copyright>Copyright © https://github.com/BHoM</Copyright>
99
<RootNamespace>BH.Engine.SQL</RootNamespace>
10-
<FileVersion>9.1.0.0</FileVersion>
10+
<FileVersion>9.2.0.0</FileVersion>
1111
<Configurations>Debug;Release;ZeroCodeTool</Configurations>
1212
<OutputPath>..\Build\</OutputPath>
1313
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1414
</PropertyGroup>
1515

1616
<PropertyGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
17-
<TargetFramework>net472</TargetFramework>
17+
<TargetFramework>netstandard2.0</TargetFramework>
1818
<DefineConstants>INSTALLERDEPLOY</DefineConstants>
1919
</PropertyGroup>
2020
<PropertyGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
2121
<TargetFramework>netstandard2.0</TargetFramework>
2222
<DefineConstants>ZCTDEPLOY</DefineConstants>
2323
</PropertyGroup>
2424

25-
<ItemGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
25+
<ItemGroup>
2626
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
2727
</ItemGroup>
2828

@@ -57,15 +57,5 @@
5757
</Reference>
5858
</ItemGroup>
5959

60-
<ItemGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
61-
<Reference Include="System" />
62-
<Reference Include="System.Core" />
63-
<Reference Include="System.Xml.Linq" />
64-
<Reference Include="System.Data.DataSetExtensions" />
65-
<Reference Include="Microsoft.CSharp" />
66-
<Reference Include="System.Data" />
67-
<Reference Include="System.Net.Http" />
68-
<Reference Include="System.Xml" />
69-
</ItemGroup>
7060

7161
</Project>

SQL_oM/SQL_oM.csproj

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
<Authors>BHoM</Authors>
88
<Copyright>Copyright © https://github.com/BHoM</Copyright>
99
<RootNamespace>BH.oM.SQL</RootNamespace>
10-
<FileVersion>9.1.0.0</FileVersion>
10+
<FileVersion>9.2.0.0</FileVersion>
1111
<Configurations>Debug;Release;ZeroCodeTool</Configurations>
1212
<OutputPath>..\Build\</OutputPath>
1313
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1414
</PropertyGroup>
1515

1616
<PropertyGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
17-
<TargetFramework>net472</TargetFramework>
17+
<TargetFramework>netstandard2.0</TargetFramework>
1818
<DefineConstants>INSTALLERDEPLOY</DefineConstants>
1919
</PropertyGroup>
2020
<PropertyGroup Condition="'$(Configuration)'=='ZeroCodeTool'">
@@ -44,15 +44,5 @@
4444
</Reference>
4545
</ItemGroup>
4646

47-
<ItemGroup Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'">
48-
<Reference Include="System" />
49-
<Reference Include="System.Core" />
50-
<Reference Include="System.Xml.Linq" />
51-
<Reference Include="System.Data.DataSetExtensions" />
52-
<Reference Include="Microsoft.CSharp" />
53-
<Reference Include="System.Data" />
54-
<Reference Include="System.Net.Http" />
55-
<Reference Include="System.Xml" />
56-
</ItemGroup>
5747

5848
</Project>

0 commit comments

Comments
 (0)