Skip to content

Commit b486b74

Browse files
authored
Don't bind against non-shipping contract assemblies (#78730)
Manual backport of c8503d3 Fixes #77988 Unblocks #78532 Introduce the AnnotateTargetPathWithContract switch to make it configure-able when a source project should return the reference project's assembly instead of the source assembly, when other projects compile against it. Set it so that reference assemblies are only returned for NetCoreAppCurrent tfms or when the project isn't packable. - Fix System.DirectoryServices.AccountManagement build System.DirectoryServices.AccountManagement now builds against src/System.DirectoryServices instead of ref/System.DirectoryServices (because the package doesn't contain the ref assembly). Because of that, the compiler now gets confused because of the System.DirectoryServices.Interop namespace and the global Interop class. This happens even though the DirectoryServices.Interop namespace doesn't include any public types. That results in the following errors: src\libraries\System.DirectoryServices.AccountManagement\src\System\DirectoryServices\AccountManagement\AD\SidList.cs(50,26): error CS0246: The type or namespace name 'SID_AND_ATTRIBUTES' could not be found (are you missing a using directive or an assembly reference?) src\libraries\System.DirectoryServices.AccountManagement\src\System\DirectoryServices\AccountManagement\interopt.cs(439,20): error CS0246: The type or namespace name 'UNICODE_INTPTR_STRING' could not be found (are you missing a using directive or an assembly reference?) This commit fixes that by removing the System.DirectoryServices.Interop namespace and moving the types into the parent namespace. - Suppress nullable warnings in Serialization.Schema Now that Schema compiles against the source assembly of System.CodeDom, it receives nullability errors. I'm suppressing them manually for now but am filing an issue to correctly fix those. Related: #78036
1 parent 5223f01 commit b486b74

26 files changed

+34
-34
lines changed

eng/resolveContract.targets

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
<HasMatchingContract Condition="'$(HasMatchingContract)' == '' and Exists('$(ContractProject)')">true</HasMatchingContract>
2121
<!-- Disable API compat if the project doesn't have reference assembly -->
2222
<RunApiCompat Condition="'$(HasMatchingContract)' != 'true'">false</RunApiCompat>
23+
<!-- Don't build against reference assemblies when projects are packable and the tfm is not the latest .NETCoreApp as
24+
such reference assemblies don't ship to customers and only exist for tooling scenarios. -->
25+
<AnnotateTargetPathWithContract Condition="'$(AnnotateTargetPathWithContract)' == '' and
26+
'$(HasMatchingContract)' == 'true' and
27+
(
28+
'$(IsPackable)' != 'true' or
29+
(
30+
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
31+
'$(TargetFrameworkVersion)' == 'v$(NetCoreAppCurrentVersion)'
32+
)
33+
)">true</AnnotateTargetPathWithContract>
2334
</PropertyGroup>
2435

2536
<ItemGroup Condition="'$(IsSourceProject)' == 'true' or '$(IsReferenceAssemblyProject)' == 'true' or '$(IsPartialFacadeAssembly)' == 'true'">
@@ -36,7 +47,7 @@
3647

3748
<!-- Allow P2Ps that target a source project to build against the corresponding ref project. -->
3849
<Target Name="AnnotateTargetPathWithTargetPlatformMonikerWithReferenceAssembly"
39-
Condition="'$(HasMatchingContract)' == 'true'"
50+
Condition="'$(AnnotateTargetPathWithContract)' == 'true'"
4051
DependsOnTargets="ResolveProjectReferences"
4152
AfterTargets="GetTargetPathWithTargetPlatformMoniker">
4253
<ItemGroup>

src/libraries/System.DirectoryServices/src/ILLink/ILLink.Suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<argument>ILLink</argument>
66
<argument>IL2050</argument>
77
<property name="Scope">member</property>
8-
<property name="Target">M:System.DirectoryServices.Interop.UnsafeNativeMethods.ADsOpenObject(System.String,System.String,System.String,System.Int32,System.Guid@,System.Object@)</property>
8+
<property name="Target">M:System.DirectoryServices.UnsafeNativeMethods.ADsOpenObject(System.String,System.String,System.String,System.Int32,System.Guid@,System.Object@)</property>
99
</attribute>
1010
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
1111
<argument>ILLink</argument>

src/libraries/System.DirectoryServices/src/Interop/AdsOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace System.DirectoryServices.Interop
4+
namespace System.DirectoryServices
55
{
66
internal enum AdsOptions
77
{

src/libraries/System.DirectoryServices/src/Interop/AdsPropertyOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace System.DirectoryServices.Interop
4+
namespace System.DirectoryServices
55
{
66
internal enum AdsPropertyOperation
77
{

src/libraries/System.DirectoryServices/src/Interop/AdsSearchColumn.cs

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

44
using System.Runtime.InteropServices;
55

6-
namespace System.DirectoryServices.Interop
6+
namespace System.DirectoryServices
77
{
88
[StructLayout(LayoutKind.Sequential)]
99
internal unsafe struct AdsSearchColumn

src/libraries/System.DirectoryServices/src/Interop/AdsSearchPreferenceInfo.cs

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

44
using System.Runtime.InteropServices;
55

6-
namespace System.DirectoryServices.Interop
6+
namespace System.DirectoryServices
77
{
88
[StructLayout(LayoutKind.Sequential)]
99
internal struct AdsSearchPreferenceInfo

src/libraries/System.DirectoryServices/src/Interop/AdsSearchPreferences.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace System.DirectoryServices.Interop
4+
namespace System.DirectoryServices
55
{
66
internal enum AdsSearchPreferences
77
{

src/libraries/System.DirectoryServices/src/Interop/AdsSortKey.cs

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

44
using System.Runtime.InteropServices;
55

6-
namespace System.DirectoryServices.Interop
6+
namespace System.DirectoryServices
77
{
88
[StructLayout(LayoutKind.Sequential)]
99
internal struct AdsSortKey

src/libraries/System.DirectoryServices/src/Interop/AdsType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace System.DirectoryServices.Interop
4+
namespace System.DirectoryServices
55
{
66
internal enum AdsType
77
{

src/libraries/System.DirectoryServices/src/Interop/AdsValue2.cs

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

44
using System.Runtime.InteropServices;
55

6-
namespace System.DirectoryServices.Interop
6+
namespace System.DirectoryServices
77
{
88
[StructLayout(LayoutKind.Sequential)]
99
internal struct Ads_Pointer

0 commit comments

Comments
 (0)