Fix trimming in WinUI projects

このコミットが含まれているのは:
Sergio Pedri committed 2023-04-20 20:07:19 +02:00
1 親 a291685aff
コミット 1c18b3624f
2ファイル変更
+15 -12

検索条件に一致するファイルはありません

+3 -2
ファイルの表示
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
#if WINDOWS_UWP
using System.Runtime.InteropServices;
#endif
@@ -24,7 +25,7 @@ internal static class RcwMarshaller
/// <typeparam name="T">The interface type to retrieve an instance of.</typeparam>
/// <param name="nativeObject">A pointer to the native object to get a managed wrapper for.</param>
/// <returns>The resulting managed object wrapping <paramref name="nativeObject"/>.</returns>
public static unsafe T GetOrCreateManagedObject<T>(IUnknown* nativeObject)
public static unsafe T GetOrCreateManagedObject<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] T>(IUnknown* nativeObject)
where T : class
{
#if WINDOWS_UWP
@@ -43,7 +44,7 @@ internal static class RcwMarshaller
/// <param name="managedObject">The input RCW instance to unwrap.</param>
/// <param name="nativeObject">A pointer to the resulting native object to retrieve.</param>
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
public static unsafe HRESULT GetNativeObject<TFrom, TTo>(TFrom managedObject, TTo** nativeObject)
public static unsafe HRESULT GetNativeObject<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.Interfaces)] TFrom, TTo>(TFrom managedObject, TTo** nativeObject)
where TFrom : class
where TTo : unmanaged // IUnknown
{
+12 -10
ファイルの表示
@@ -2,14 +2,16 @@
<Project>
<Import Project="..\build\Directory.Build.targets" />
<!-- Enable trimming support on .NET 6 -->
<Target Name="ConfigureAssemblyTrimmingIfNeeded"
BeforeTargets="PrepareForBuild">
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
</Target>
<!--
Enable trimming support on .NET 6 (we need to use StartsWith since it
could be a Windows TFM too). This can't be in a target unlike the other
properties set below, because if that is the case the trimmable attribute
will be set but the analyzers will not run, so warnings will be skipped.
-->
<PropertyGroup Condition="$(TargetFramework.StartsWith('net6.0'))">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
<!-- Emit the [SupportedOSVersion] attribute if needed -->
<Target Name="EmitSupportedOSVersionAttributeForTargetOS"
@@ -21,10 +23,10 @@
</ItemGroup>
</Target>
<!-- Emit the [ComVisible(false)] attribute for UWP targets -->
<!-- Emit the [ComVisible(false)] attribute for UWP and WinUI targets -->
<Target Name="EmitComVisibleAttributeForUwpProjects"
BeforeTargets="PrepareForBuild">
<ItemGroup Condition="$(TargetFramework.StartsWith('uap10.0'))">
<ItemGroup Condition="$(TargetFramework.StartsWith('uap10.0')) OR $(TargetFramework.StartsWith('net6.0-windows'))">
<AssemblyAttribute Include="System.Runtime.InteropServices.ComVisibleAttribute">
<_Parameter1>false</_Parameter1>
</AssemblyAttribute>