|
| 1 | +<Project InitialTargets="ConfigureGenerators"> |
| 2 | + |
| 3 | + <Target Name="ConfigureGenerators" |
| 4 | + DependsOnTargets="ConfigureDllImportGenerator" /> |
| 5 | + |
| 6 | + <!-- Microsoft.Interop.DllImportGenerator --> |
| 7 | + <Target Name="ConfigureDllImportGenerator" DependsOnTargets="EnableDllImportGeneratorForNetCoreApp"> |
| 8 | + <PropertyGroup Condition="'$(EnableDllImportGenerator)' == 'true'"> |
| 9 | + <DllImportGenerator_UseMarshalType>true</DllImportGenerator_UseMarshalType> |
| 10 | + </PropertyGroup> |
| 11 | + <ItemGroup Condition="'$(EnableDllImportGenerator)' == 'true' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))"> |
| 12 | + <PackageReference Include="Microsoft.Interop.DllImportGenerator" Version="$(MicrosoftInteropDllImportGeneratorVersion)" PrivateAssets="all" /> |
| 13 | + |
| 14 | + <!-- For testing purposes, compile sources files with attributes directly into the project. |
| 15 | + This is mimicking the case where the source generator always generates the attributes. --> |
| 16 | + <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs" /> |
| 17 | + <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs" /> |
| 18 | + </ItemGroup> |
| 19 | + </Target> |
| 20 | + |
| 21 | + <Target Name="EnableDllImportGeneratorForNetCoreApp" |
| 22 | + Condition="'$(EnableDllImportGenerator)' == '' |
| 23 | + and ('$(IsNetCoreAppSrc)' == 'true' or '$(MSBuildProjectName)' == 'System.Private.CoreLib') |
| 24 | + and '$(MSBuildProjectExtension)' == '.csproj'"> |
| 25 | + <PropertyGroup> |
| 26 | + <!-- Enable DllImportGenerator by default for System.Private.CoreLib --> |
| 27 | + <EnableDllImportGenerator Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib'">true</EnableDllImportGenerator> |
| 28 | + |
| 29 | + <!-- Enable DllImportGenerator by default for NETCoreApp libraries that reference either System.Runtime.InteropServices or System.Private.CoreLib --> |
| 30 | + <EnableDllImportGenerator Condition="'@(Reference)' != '' and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.InteropServices'))">true</EnableDllImportGenerator> |
| 31 | + <EnableDllImportGenerator Condition="'@(ProjectReference)' != '' and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">true</EnableDllImportGenerator> |
| 32 | + </PropertyGroup> |
| 33 | + </Target> |
| 34 | + |
| 35 | +</Project> |
0 commit comments