Skip to content

Commit 660b69e

Browse files
authored
Merge pull request #17657 from LakshanF/ComHostWarn
SDK support for runtime native host and COM changes
2 parents 0655534 + 376cfcd commit 660b69e

File tree

3 files changed

+41
-43
lines changed

3 files changed

+41
-43
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.ILLink.targets

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,21 @@ Copyright (c) .NET Foundation. All rights reserved.
2727
</AssemblyAttribute>
2828
</ItemGroup>
2929

30-
<!-- We disable startup hooks for trimmed apps here so that the feature
31-
switch can flow to the runtimeconfig.json. Startup hooks are disabled
32-
by default since they may require assemblies, types or members that
33-
could be removed by the linker, causing a trimmed app to crash. -->
34-
<PropertyGroup Condition="'$(StartupHookSupport)' == '' And
35-
'$(PublishTrimmed)' == 'true' And
36-
$([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '6.0'))">
37-
<StartupHookSupport>false</StartupHookSupport>
38-
</PropertyGroup>
3930

40-
<!-- We disable custom resource types for trimmed apps here so that the feature
41-
switch can flow to the runtimeconfig.json. Custom resource types are disabled
42-
by default since they may require assemblies, types or members that
43-
could be removed by the linker, causing a trimmed app to crash. -->
44-
<PropertyGroup Condition="'$(CustomResourceTypesSupport)' == '' And
45-
'$(PublishTrimmed)' == 'true' And
46-
$([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '6.0'))">
47-
<CustomResourceTypesSupport>false</CustomResourceTypesSupport>
48-
</PropertyGroup>
49-
<PropertyGroup Condition="'$(EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization)' == '' And
50-
'$(PublishTrimmed)' == 'true' And
31+
<!-- We disable features for trimmed apps here so that the feature
32+
switches can flow to the runtimeconfig.json. Features are disabled
33+
by default since they may require assemblies, types or members that
34+
could be removed by the linker, causing a trimmed app to crash. -->
35+
<PropertyGroup Condition="'$(PublishTrimmed)' == 'true' And
5136
$([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '6.0'))">
52-
<EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization>false</EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization>
37+
<StartupHookSupport Condition="'$(StartupHookSupport)' == ''">false</StartupHookSupport>
38+
<CustomResourceTypesSupport Condition="'$(CustomResourceTypesSupport)' == ''">false</CustomResourceTypesSupport>
39+
<EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization Condition="'$(EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization)' == ''">false</EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization>
40+
<BuiltInComInteropSupport Condition="'$(BuiltInComInteropSupport)' == ''">false</BuiltInComInteropSupport>
41+
<EnableCppCLIHostActivation Condition="'$(EnableCppCLIHostActivation)' == ''">false</EnableCppCLIHostActivation>
42+
<_EnableConsumingManagedCodeFromNativeHosting Condition="'$(_EnableConsumingManagedCodeFromNativeHosting)' == ''">false</_EnableConsumingManagedCodeFromNativeHosting>
5343
</PropertyGroup>
5444

55-
<!-- We disable in-built COM support for trimmed apps here so that the feature
56-
switch can flow to the runtimeconfig.json. Built-in COM support is disabled
57-
by default since they may require assemblies, types or members that
58-
could be removed by the linker, causing a trimmed app to crash. -->
59-
<PropertyGroup Condition="'$(BuiltInComSupport)' == '' And
60-
'$(PublishTrimmed)' == 'true' And
61-
$([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '6.0'))">
62-
<BuiltInComSupport>false</BuiltInComSupport>
63-
</PropertyGroup>
64-
6545
<PropertyGroup Condition="'$(SuppressTrimAnalysisWarnings)' == '' And ('$(EnableTrimAnalyzer)' == 'true' Or '$(PublishTrimmed)' == 'true')">
6646
<!-- Trim analysis warnings are suppressed for .NET < 6. -->
6747
<SuppressTrimAnalysisWarnings Condition="$([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0'))">true</SuppressTrimAnalysisWarnings>

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,6 @@ Copyright (c) .NET Foundation. All rights reserved.
359359
-->
360360

361361
<ItemGroup>
362-
<RuntimeHostConfigurationOption Include=" System.Runtime.InteropServices.Marshal.IsBuiltInComSupported"
363-
Condition="'$(BuiltInComSupport)' != ''"
364-
Value="$(BuiltInComSupport)"
365-
Trim="true" />
366-
367362
<RuntimeHostConfigurationOption Include="System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization"
368363
Condition="'$(EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization)' != ''"
369364
Value="$(EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization)"
@@ -416,6 +411,21 @@ Copyright (c) .NET Foundation. All rights reserved.
416411
Value="$(UseSystemResourceKeys)"
417412
Trim="true" />
418413

414+
<RuntimeHostConfigurationOption Include="System.Runtime.InteropServices.BuiltInComInterop.IsSupported"
415+
Condition="'$(BuiltInComInteropSupport)' != ''"
416+
Value="$(BuiltInComInteropSupport)"
417+
Trim="true" />
418+
419+
<RuntimeHostConfigurationOption Include="System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting"
420+
Condition="'$(_EnableConsumingManagedCodeFromNativeHosting)' != ''"
421+
Value="$(_EnableConsumingManagedCodeFromNativeHosting)"
422+
Trim="true" />
423+
424+
<RuntimeHostConfigurationOption Include="System.Runtime.InteropServices.EnableCppCLIHostActivation"
425+
Condition="'$(EnableCppCLIHostActivation)' != ''"
426+
Value="$(EnableCppCLIHostActivation)"
427+
Trim="true" />
428+
419429
<RuntimeHostConfigurationOption Include="System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization"
420430
Condition="'$(EnableUnsafeBinaryFormatterSerialization)' != ''"
421431
Value="$(EnableUnsafeBinaryFormatterSerialization)"

src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -682,24 +682,32 @@ public void TrimmingOptions_are_defaulted_correctly_on_trimmed_apps(string targe
682682
{
683683
JObject runtimeConfig = JObject.Parse(runtimeConfigContents);
684684
runtimeConfig["runtimeOptions"]["configProperties"]
685-
["System.Runtime.InteropServices.Marshal.IsBuiltInComSupported"].Value<bool>()
685+
["System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization"].Value<bool>()
686686
.Should().BeFalse();
687687
runtimeConfig["runtimeOptions"]["configProperties"]
688-
["System.StartupHookProvider.IsSupported"].Value<bool>()
688+
["System.Resources.ResourceManager.AllowCustomResourceTypes"].Value<bool>()
689689
.Should().BeFalse();
690690
runtimeConfig["runtimeOptions"]["configProperties"]
691-
["System.Resources.ResourceManager.AllowCustomResourceTypes"].Value<bool>()
691+
["System.Runtime.InteropServices.BuiltInComInterop.IsSupported"].Value<bool>()
692692
.Should().BeFalse();
693693
runtimeConfig["runtimeOptions"]["configProperties"]
694-
["System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization"].Value<bool>()
694+
["System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting"].Value<bool>()
695+
.Should().BeFalse();
696+
runtimeConfig["runtimeOptions"]["configProperties"]
697+
["System.Runtime.InteropServices.EnableCppCLIHostActivation"].Value<bool>()
698+
.Should().BeFalse();
699+
runtimeConfig["runtimeOptions"]["configProperties"]
700+
["System.StartupHookProvider.IsSupported"].Value<bool>()
695701
.Should().BeFalse();
696702
}
697703
else
698704
{
699-
runtimeConfigContents.Should().NotContain("System.Runtime.InteropServices.Marshal.IsBuiltInComSupported");
700-
runtimeConfigContents.Should().NotContain("System.StartupHookProvider.IsSupported");
701-
runtimeConfigContents.Should().NotContain("System.Resources.ResourceManager.AllowCustomResourceTypes");
702705
runtimeConfigContents.Should().NotContain("System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization");
706+
runtimeConfigContents.Should().NotContain("System.Resources.ResourceManager.AllowCustomResourceTypes");
707+
runtimeConfigContents.Should().NotContain("System.Runtime.InteropServices.BuiltInComInterop.IsSupported");
708+
runtimeConfigContents.Should().NotContain("System.Runtime.InteropServices.EnableConsumingManagedCodeFromNativeHosting");
709+
runtimeConfigContents.Should().NotContain("System.Runtime.InteropServices.EnableCppCLIHostActivation");
710+
runtimeConfigContents.Should().NotContain("System.StartupHookProvider.IsSupported");
703711
}
704712
}
705713

0 commit comments

Comments
 (0)