diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/DebuggerSupportFalse.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/DebuggerSupportFalse.cs new file mode 100644 index 00000000000000..4c8c23c3ea6132 --- /dev/null +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/DebuggerSupportFalse.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Reflection; + +/// +/// Ensures setting DebuggerSupport = false causes parameter names to be removed +/// +class Program +{ + static int Main(string[] args) + { + // Ensure the method is kept + MethodWithParameter (""); + + // Get parameter name via trim-incompatible reflection + var parameterName = reflectedType.GetMethod("MethodWithParameter")!.GetParameters()[0].Name; + + // Parameter name should be removed + if (!string.IsNullOrEmpty(parameterName)) + return -1; + + return 100; + } + + static Type reflectedType = typeof(Program); + + public static void MethodWithParameter(string parameter) {} +} diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/DebuggerSupportTrue.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/DebuggerSupportTrue.cs new file mode 100644 index 00000000000000..cf7ee75c313f5b --- /dev/null +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/DebuggerSupportTrue.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Reflection; + +/// +/// Ensures setting DebuggerSupport = true causes parameter names to be kept +/// +class Program +{ + static int Main(string[] args) + { + // Ensure the method is kept + MethodWithParameter (""); + + // Get parameter name via trim-incompatible reflection + var parameterName = reflectedType.GetMethod("MethodWithParameter")!.GetParameters()[0].Name; + + // Parameter name should be kept + if (parameterName != "parameter") + return -1; + + return 100; + } + + static Type reflectedType = typeof(Program); + + public static void MethodWithParameter(string parameter) {} +} diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj index 7b39f85f522a95..a5c28926b272f6 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/TrimmingTests/System.Runtime.TrimmingTests.proj @@ -10,6 +10,14 @@ osx-x64;linux-x64;browser-wasm + + DebuggerSupport + true + + + DebuggerSupport + true + DebuggerSupport diff --git a/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets b/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets index 2d1526dc69ac5a..ab36c6795a4b0c 100644 --- a/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets +++ b/src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets @@ -156,6 +156,7 @@ Copyright (c) .NET Foundation. All rights reserved. UnusedInterfaces="$(_TrimmerUnusedInterfaces)" IPConstProp="$(_TrimmerIPConstProp)" Sealer="$(_TrimmerSealer)" + KeepMetadata="@(_TrimmerKeepMetadata)" Warn="$(ILLinkWarningLevel)" NoWarn="$(NoWarn)" @@ -240,6 +241,11 @@ Copyright (c) .NET Foundation. All rights reserved. false + + + <_TrimmerKeepMetadata Include="all" Condition=" '$(DebuggerSupport)' != 'false' " /> + + <_TrimmerPreserveSymbolPaths Condition=" '$(_TrimmerPreserveSymbolPaths)' == '' and '$(DeterministicSourcePaths)' == 'true' ">true <_TrimmerPreserveSymbolPaths Condition=" '$(_TrimmerPreserveSymbolPaths)' == '' ">false