Skip to content

Commit 1c450c0

Browse files
authored
Merge Project | Build the Common Project (dotnet#3837)
* Add reference to MSS for netcore to fix InvalidUdtException reference issue * SqlDependencyUtils.* are all netcore files, rename as such, and wrap in #if NET * Set build output path * Add OS-specific check for target frameworks Remove runtime identifier/target framework from output path * Builds! Whoohooo! * Common project build targets * Add common project back to the solution build targets * Comments from PR * Rework package references as per comments, add normalized target os variable. * Add message on exec * Add strong name signing and triple check package references * Unconditional assembly originator key file, clarify command
1 parent 07f524c commit 1c450c0

7 files changed

Lines changed: 161 additions & 38 deletions

File tree

build2.proj

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!-- Build Parameters ============================================== -->
4+
<PropertyGroup>
5+
<!-- Configuration: Which build configuration to build -->
6+
<!-- Allowed values: Debug, Release -->
7+
<!-- Default value: Debug -->
8+
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
9+
10+
<!-- DotnetPath: Path to folder containing the `dotnet` binary. Override this if a -->
11+
<!-- specific version (eg, x86) is required. Otherwise, this defaults to using the -->
12+
<!-- dotnet binary in the PATH variable. The provided path should end with a `\` (or -->
13+
<!-- `/`) character. Eg. C:\x86\ -->
14+
<DotnetPath Condition="'$(DotnetPath)' == ''"></DotnetPath>
15+
</PropertyGroup>
16+
17+
<!-- Imports ======================================================= -->
18+
<Import Project="src/Directory.Build.props" />
19+
20+
<!-- Microsoft.Data.SqlClient Build Targets ======================== -->
21+
<PropertyGroup>
22+
<MdsProjectPath>$(RepoRoot)src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj</MdsProjectPath>
23+
</PropertyGroup>
24+
25+
<!-- BuildMds: Builds all binaries for MDS -->
26+
<Target Name="BuildMds" DependsOnTargets="BuildMdsUnix;BuildMdsWindows" />
27+
28+
<!-- BuildMdsUnix: Builds all unix-specific MDS binaries -->
29+
<Target Name="BuildMdsUnix">
30+
<PropertyGroup>
31+
<DotnetCommand>
32+
$(DotnetPath)dotnet build $(MdsProjectPath)
33+
-p:Configuration=$(Configuration)
34+
-p:TargetOs=Unix
35+
</DotnetCommand>
36+
<!-- Convert more than one whitespace character into one space -->
37+
<DotnetCommand>$([System.Text.RegularExpressions.Regex]::Replace($(DotnetCommand), "\s+", " "))</DotnetCommand>
38+
</PropertyGroup>
39+
<Message Text=">>> Building MDS for Unix via command: $(DotnetCommand)"/>
40+
<Exec ConsoleToMsBuild="true" Command="$(DotnetCommand)" />
41+
</Target>
42+
43+
<!-- BuildMdsWindows: Builds all windows-specific MDS binaries -->
44+
<Target Name="BuildMdsWindows">
45+
<PropertyGroup>
46+
<DotnetCommand>
47+
$(DotnetPath)dotnet build $(MdsProjectPath)
48+
-p:Configuration=$(Configuration)
49+
-p:TargetOs=Windows_NT
50+
</DotnetCommand>
51+
<!-- Convert more than one whitespace character into one space -->
52+
<DotnetCommand>$([System.Text.RegularExpressions.Regex]::Replace($(DotnetCommand), "\s+", " "))</DotnetCommand>
53+
</PropertyGroup>
54+
<Message Text=">>> Building MDS for Windows via command: $(DotnetCommand)"/>
55+
<Exec ConsoleToMsBuild="true" Command="$(DotnetCommand)" />
56+
</Target>
57+
</Project>

src/Microsoft.Data.SqlClient.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio Version 17
33
VisualStudioVersion = 17.0.31912.275
44
MinimumVisualStudioVersion = 10.0.40219.1
@@ -561,6 +561,12 @@ Global
561561
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
562562
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Release|x64.ActiveCfg = Release|Any CPU
563563
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Release|x86.ActiveCfg = Release|Any CPU
564+
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
565+
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Debug|x64.Build.0 = Debug|Any CPU
566+
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Debug|x86.Build.0 = Debug|Any CPU
567+
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Release|Any CPU.Build.0 = Release|Any CPU
568+
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Release|x64.Build.0 = Release|Any CPU
569+
{9A8996A8-6484-4AA7-B50F-F861430EDE2F}.Release|x86.Build.0 = Release|Any CPU
564570
{4461063D-2F2B-274C-7E6F-F235119D258E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
565571
{4461063D-2F2B-274C-7E6F-F235119D258E}.Debug|Any CPU.Build.0 = Debug|Any CPU
566572
{4461063D-2F2B-274C-7E6F-F235119D258E}.Debug|x64.ActiveCfg = Debug|x64

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,11 @@
812812
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDependencyUtils.cs">
813813
<Link>Microsoft\Data\SqlClient\SqlDependencyUtils.cs</Link>
814814
</Compile>
815-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDependencyUtils.AppDomain.cs">
816-
<Link>Microsoft\Data\SqlClient\SqlDependencyUtils.AppDomain.cs</Link>
815+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDependencyUtils.AppDomain.netcore.cs">
816+
<Link>Microsoft\Data\SqlClient\SqlDependencyUtils.AppDomain.netcore.cs</Link>
817817
</Compile>
818-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDependencyUtils.AssemblyLoadContext.cs">
819-
<Link>Microsoft\Data\SqlClient\SqlDependencyUtils.AssemblyLoadContext.cs</Link>
818+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlDependencyUtils.AssemblyLoadContext.netcore.cs">
819+
<Link>Microsoft\Data\SqlClient\SqlDependencyUtils.AssemblyLoadContext.netcore.cs</Link>
820820
</Compile>
821821
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlEnclaveAttestationParameters.Crypto.cs">
822822
<Link>Microsoft\Data\SqlClient\SqlEnclaveAttestationParameters.Crypto.cs</Link>
Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,108 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFrameworks>net462;net8.0;net9.0</TargetFrameworks>
2+
<!-- General Properties ============================================== -->
3+
<PropertyGroup>
4+
<Configurations>Debug;Release;</Configurations>
5+
<RootNamespace />
46
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5-
<RootNamespace />
67
</PropertyGroup>
78

9+
<!-- Strong name signing ============================================= -->
10+
<PropertyGroup>
11+
<AssemblyOriginatorKeyFile>$(SigningKeyPath)</AssemblyOriginatorKeyFile>
12+
</PropertyGroup>
13+
<PropertyGroup Condition="'$(CDP_BUILD_TYPE)' == 'Official'">
14+
<SignAssembly>true</SignAssembly>
15+
<KeyFile>$(SigningKeyPath)</KeyFile>
16+
</PropertyGroup>
17+
18+
819
<!-- OS Constants ==================================================== -->
920
<PropertyGroup>
21+
<!-- @TODO: Move to directory.build.props? -->
1022
<!-- If a target OS was not specified, use the current OS as the target OS. -->
1123
<TargetOs Condition="'$(TargetOs)' == ''">$(OS)</TargetOs>
1224

1325
<!-- Uncomment the following line to override the OS you are developing for -->
1426
<!--<TargetOs>Unix</TargetOs>-->
1527
<!--<TargetOs>Windows_NT</TargetOs>-->
1628

29+
<NormalizedTargetOs>$(TargetOs.ToLower())</NormalizedTargetOs>
30+
1731
<!-- NOTE: These constants are prefixed with _ to keep them separate from .NET 5+ precompiler -->
18-
<!-- flags. Those only apply to OS-specific target frameworks, and would interfere here. -->
19-
<DefineConstants Condition="'$(TargetOs.ToUpper())' == 'UNIX'">$(DefineConstants),_UNIX</DefineConstants>
20-
<DefineConstants Condition="'$(TargetOs.ToUpper())' == 'WINDOWS_NT'">$(DefineConstants),_WINDOWS</DefineConstants>
32+
<!-- flags. Those only apply to OS-specific target frameworks, and would interfere here. -->
33+
<DefineConstants Condition="'$(NormalizedTargetOs)' == 'unix'">$(DefineConstants);_UNIX</DefineConstants>
34+
<DefineConstants Condition="'$(NormalizedTargetOs)' == 'windows_nt'">$(DefineConstants);_WINDOWS</DefineConstants>
35+
</PropertyGroup>
36+
37+
<!-- Target Frameworks =============================================== -->
38+
<PropertyGroup>
39+
<!-- net462 is only supported on Windows, so we will only add it if we're building for Windows -->
40+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
41+
<TargetFrameworks Condition="'$(NormalizedTargetOs)' == 'windows_nt'">$(TargetFrameworks);net462</TargetFrameworks>
42+
</PropertyGroup>
43+
44+
<!-- Build Output ==================================================== -->
45+
<PropertyGroup>
46+
<!-- @TODO: Move to directory.build.props? -->
47+
<ArtifactPath>$(RepoRoot)artifacts/</ArtifactPath>
48+
49+
<!-- MSBuild will add the target framework to the end of this path by default. Telling it not -->
50+
<!-- to is possible but requires also specifying the IntermediateOutputPath. So while it -->
51+
<!-- would be nice to have a flat directory structure, it's more hassle than its worth. -->
52+
<OutputPath>$(ArtifactPath)$(AssemblyName)/$(Configuration)/$(NormalizedTargetOs)/</OutputPath>
2153
</PropertyGroup>
2254

2355
<!-- Embedded resources ============================================== -->
2456
<ItemGroup>
57+
<!-- Linker directives to replace UseManagedNetworking with a constant if consumer specifies -->
58+
<!-- the app context switch in their csproj. This file only applies to netcore on windows. -->
59+
<!-- This file does not support pre-processor directives, so it must be conditionally -->
60+
<!-- included into the build. -->
2561
<EmbeddedResource Include="Resources/ILLink.Substitutions.xml"
26-
Condition="'$(TargetOs.ToUpper())' == 'WINDOWS_NT'" />
62+
Condition="'$(NormalizedTargetOs)' == 'windows_nt' AND '$(TargetFramework)' != 'net462'" />
2763
</ItemGroup>
2864

2965
<!-- References ====================================================== -->
30-
<ItemGroup>
31-
<!-- References that apply to all target frameworks -->
66+
<!-- References for netframework -->
67+
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
68+
<Reference Include="System.Configuration" />
69+
<Reference Include="System.EnterpriseServices" />
70+
<Reference Include="System.Transactions" />
71+
3272
<PackageReference Include="Azure.Core" />
3373
<PackageReference Include="Azure.Identity" />
3474
<PackageReference Include="Microsoft.Bcl.Cryptography" />
75+
<PackageReference Include="Microsoft.Data.SqlClient.SNI">
76+
<PrivateAssets>All</PrivateAssets>
77+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
78+
</PackageReference>
3579
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
3680
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" />
3781
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" />
38-
<PackageReference Include="System.Configuration.ConfigurationManager" />
39-
<PackageReference Include="System.Security.Cryptography.Pkcs" />
40-
</ItemGroup>
41-
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
42-
<!-- References that only apply to net462 -->
43-
<Reference Include="System.Configuration" />
44-
<Reference Include="System.Transactions" />
45-
<PackageReference Include="System.ValueTuple" />
46-
<PackageReference Include="System.Threading.Channels" />
47-
</ItemGroup>
48-
49-
<!-- System.Buffers, System.Memory, and System.Runtime.InteropServices.RuntimeInformation are included in .NET 10+ BCL -->
50-
<ItemGroup Condition="$([MSBuild]::VersionLessThan($([MSBuild]::GetTargetFrameworkVersion($(TargetFramework))), '10.0'))">
5182
<PackageReference Include="System.Buffers" />
83+
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
5284
<PackageReference Include="System.Memory" />
5385
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" />
86+
<PackageReference Include="System.Security.Cryptography.Pkcs" />
87+
<PackageReference Include="System.Text.Json" />
88+
<PackageReference Include="System.Threading.Channels" />
89+
<PackageReference Include="System.ValueTuple" />
90+
</ItemGroup>
91+
92+
<!-- References for netcore -->
93+
<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
94+
<PackageReference Include="Azure.Core" />
95+
<PackageReference Include="Azure.Identity" />
96+
<PackageReference Include="Microsoft.Bcl.Cryptography" />
97+
<PackageReference Include="Microsoft.Data.SqlClient.SNI.runtime" />
98+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
99+
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" />
100+
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" />
101+
<PackageReference Include="Microsoft.SqlServer.Server" />
102+
<PackageReference Include="System.Configuration.ConfigurationManager" />
103+
<PackageReference Include="System.Security.Cryptography.Pkcs" />
54104
</ItemGroup>
105+
106+
<!-- CodeGen Targets ================================================= -->
107+
<Import Project="$(ToolsDir)targets\GenerateThisAssemblyCs.targets" />
55108
</Project>

src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,27 @@ internal static partial class ADP
6969
internal const int MaxBufferAccessTokenExpiry = 600;
7070

7171
#region UDT
72-
#if NETFRAMEWORK
73-
private static readonly MethodInfo s_method = typeof(InvalidUdtException).GetMethod("Create", BindingFlags.NonPublic | BindingFlags.Static);
74-
#endif
72+
73+
#if NETFRAMEWORK
74+
private static readonly MethodInfo s_udtFactory =
75+
typeof(InvalidUdtException).GetMethod("Create", BindingFlags.NonPublic | BindingFlags.Static);
76+
#endif
77+
7578
/// <summary>
7679
/// Calls "InvalidUdtException.Create" method when an invalid UDT occurs.
7780
/// </summary>
7881
internal static InvalidUdtException CreateInvalidUdtException(Type udtType, string resourceReasonName)
7982
{
80-
// @TODO: Can we adopt the netcore version?
81-
InvalidUdtException e =
82-
#if NETFRAMEWORK
83-
(InvalidUdtException)s_method.Invoke(null, new object[] { udtType, resourceReasonName });
84-
ADP.TraceExceptionAsReturnValue(e);
85-
#else
86-
InvalidUdtException.Create(udtType, resourceReasonName);
87-
#endif
83+
#if NETFRAMEWORK
84+
InvalidUdtException e = (InvalidUdtException)s_udtFactory.Invoke(null, [udtType, resourceReasonName]);
85+
#else
86+
InvalidUdtException e = InvalidUdtException.Create(udtType, resourceReasonName);
87+
#endif
88+
89+
TraceExceptionAsReturnValue(e);
8890
return e;
8991
}
92+
9093
#endregion
9194

9295
static private void TraceException(string trace, Exception e)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.AppDomain.cs renamed to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.AppDomain.netcore.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#if NET
6+
57
using System;
68

79
namespace Microsoft.Data.SqlClient
@@ -18,3 +20,5 @@ partial void SubscribeToAppDomainUnload()
1820
}
1921
}
2022
}
23+
24+
#endif

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.AssemblyLoadContext.cs renamed to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.AssemblyLoadContext.netcore.cs

File renamed without changes.

0 commit comments

Comments
 (0)