Skip to content

Commit

Permalink
Merge pull request dotnet#17357 from LakshanF/ComWarnings
Browse files Browse the repository at this point in the history
Disable COM for trimming
  • Loading branch information
LakshanF committed May 3, 2021
2 parents 548da35 + e6f8525 commit 7cf847c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ Copyright (c) .NET Foundation. All rights reserved.
<EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization>false</EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization>
</PropertyGroup>

<!-- We disable in-built COM support for trimmed apps here so that the feature
switch can flow to the runtimeconfig.json. Built-in COM support is disabled
by default since they may require assemblies, types or members that
could be removed by the linker, causing a trimmed app to crash. -->
<PropertyGroup Condition="'$(BuiltInComSupport)' == '' And
'$(PublishTrimmed)' == 'true' And
$([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '6.0'))">
<BuiltInComSupport>false</BuiltInComSupport>
</PropertyGroup>

<PropertyGroup Condition="'$(SuppressTrimAnalysisWarnings)' == '' And ('$(EnableTrimAnalyzer)' == 'true' Or '$(PublishTrimmed)' == 'true')">
<!-- Trim analysis warnings are suppressed for .NET < 6. -->
<SuppressTrimAnalysisWarnings Condition="$([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0'))">true</SuppressTrimAnalysisWarnings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ Copyright (c) .NET Foundation. All rights reserved.
-->

<ItemGroup>
<RuntimeHostConfigurationOption Include=" System.Runtime.InteropServices.Marshal.IsBuiltInComSupported"
Condition="'$(BuiltInComSupport)' != ''"
Value="$(BuiltInComSupport)"
Trim="true" />

<RuntimeHostConfigurationOption Include="System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization"
Condition="'$(EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization)' != ''"
Value="$(EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization)"
Expand Down Expand Up @@ -1039,4 +1044,4 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<Import Project="$(AfterMicrosoftNETSdkTargets)" Condition="'$(AfterMicrosoftNETSdkTargets)' != ''"/>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ public void TrimmingOptions_are_defaulted_correctly_on_trimmed_apps(string targe
parsedVersion.Major >= 6)
{
JObject runtimeConfig = JObject.Parse(runtimeConfigContents);
runtimeConfig["runtimeOptions"]["configProperties"]
["System.Runtime.InteropServices.Marshal.IsBuiltInComSupported"].Value<bool>()
.Should().Be(false);
runtimeConfig["runtimeOptions"]["configProperties"]
["System.StartupHookProvider.IsSupported"].Value<bool>()
.Should().Be(false);
Expand All @@ -693,6 +696,7 @@ public void TrimmingOptions_are_defaulted_correctly_on_trimmed_apps(string targe
}
else
{
runtimeConfigContents.Should().NotContain("System.Runtime.InteropServices.Marshal.IsBuiltInComSupported");
runtimeConfigContents.Should().NotContain("System.StartupHookProvider.IsSupported");
runtimeConfigContents.Should().NotContain("System.Resources.ResourceManager.AllowCustomResourceTypes");
runtimeConfigContents.Should().NotContain("System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization");
Expand Down

0 comments on commit 7cf847c

Please sign in to comment.