Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElinor Fung <elfung@microsoft.com>2021-05-10 22:48:18 +0300
committerGitHub <noreply@github.com>2021-05-10 22:48:18 +0300
commit757002794ee60402bd8a8ceab8dfbf2ede58aa5f (patch)
treeb80295d33acaf532b8373d355f23862c3b3a4bd3 /eng/generators.targets
parent74cafe71de68fac46cd4956da98387bce9e1043c (diff)
Basic infrastructure to enable DllImportGenerator (#52486)
Diffstat (limited to 'eng/generators.targets')
-rw-r--r--eng/generators.targets35
1 files changed, 35 insertions, 0 deletions
diff --git a/eng/generators.targets b/eng/generators.targets
new file mode 100644
index 00000000000..77d07da6fb1
--- /dev/null
+++ b/eng/generators.targets
@@ -0,0 +1,35 @@
+<Project InitialTargets="ConfigureGenerators">
+
+ <Target Name="ConfigureGenerators"
+ DependsOnTargets="ConfigureDllImportGenerator" />
+
+ <!-- Microsoft.Interop.DllImportGenerator -->
+ <Target Name="ConfigureDllImportGenerator" DependsOnTargets="EnableDllImportGeneratorForNetCoreApp">
+ <PropertyGroup Condition="'$(EnableDllImportGenerator)' == 'true'">
+ <DllImportGenerator_UseMarshalType>true</DllImportGenerator_UseMarshalType>
+ </PropertyGroup>
+ <ItemGroup Condition="'$(EnableDllImportGenerator)' == 'true' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
+ <PackageReference Include="Microsoft.Interop.DllImportGenerator" Version="$(MicrosoftInteropDllImportGeneratorVersion)" PrivateAssets="all" />
+
+ <!-- For testing purposes, compile sources files with attributes directly into the project.
+ This is mimicking the case where the source generator always generates the attributes. -->
+ <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs" />
+ <Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs" />
+ </ItemGroup>
+ </Target>
+
+ <Target Name="EnableDllImportGeneratorForNetCoreApp"
+ Condition="'$(EnableDllImportGenerator)' == ''
+ and ('$(IsNetCoreAppSrc)' == 'true' or '$(MSBuildProjectName)' == 'System.Private.CoreLib')
+ and '$(MSBuildProjectExtension)' == '.csproj'">
+ <PropertyGroup>
+ <!-- Enable DllImportGenerator by default for System.Private.CoreLib -->
+ <EnableDllImportGenerator Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib'">true</EnableDllImportGenerator>
+
+ <!-- Enable DllImportGenerator by default for NETCoreApp libraries that reference either System.Runtime.InteropServices or System.Private.CoreLib -->
+ <EnableDllImportGenerator Condition="'@(Reference)' != '' and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.InteropServices'))">true</EnableDllImportGenerator>
+ <EnableDllImportGenerator Condition="'@(ProjectReference)' != '' and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">true</EnableDllImportGenerator>
+ </PropertyGroup>
+ </Target>
+
+</Project>