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

generators.targets « eng - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7835650b04eca3ffdf9b4f75164b903f0cfb006 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<Project>

  <PropertyGroup>
    <EnableDllImportGenerator Condition="'$(EnableDllImportGenerator)' == ''
                        and '$(MSBuildProjectName)' == 'System.Private.CoreLib'">true</EnableDllImportGenerator>
    <IncludeDllImportGeneratorSources Condition="'$(IncludeDllImportGeneratorSources)' == ''">true</IncludeDllImportGeneratorSources>
  </PropertyGroup>
  <ItemGroup>
    <EnabledGenerators Include="DllImportGenerator" Condition="'$(EnableDllImportGenerator)' == 'true'" />
    <!-- If the current project is not System.Private.CoreLib, we enable the DllImportGenerator source generator
         when the project is a C# source project that either:
         - references System.Private.CoreLib, or
         - references System.Runtime.InteropServices -->
    <EnabledGenerators Include="DllImportGenerator"
                       Condition="'$(EnableDllImportGenerator)' == ''
                        and '$(IsRuntimeAssembly)' == 'true'
                        and '$(MSBuildProjectExtension)' == '.csproj'
                        and (
                          ('@(Reference)' != ''
                            and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.InteropServices')))
                          or ('@(ProjectReference)' != ''
                            and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)')))
                          or ('$(NetCoreAppCurrentTargetFrameworkMoniker)' == '$(TargetFrameworkMoniker)'
                            and '$(DisableImplicitAssemblyReferences)' == 'false'))" />
    <EnabledGenerators Include="DllImportGenerator"
                       Condition="'$(EnableDllImportGenerator)' == ''
                        and '$(IsRuntimeAssembly)' == 'true'
                        and '$(MSBuildProjectExtension)' == '.csproj'
                        and ('$(TargetFrameworkIdentifier)' == '.NETStandard' or '$(TargetFrameworkIdentifier)' == '.NETFramework' or ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '$(NetCoreAppCurrentVersion)'))))" />
  </ItemGroup>

  <!-- Use this complex ItemGroup-based filtering to add the ProjectReference to make sure dotnet/runtime stays compatible with NuGet Static Graph Restore. -->
  <ItemGroup Condition="'@(EnabledGenerators)' != ''
                        and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator'))">
    <ProjectReference
      Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\DllImportGenerator\DllImportGenerator.csproj"
      OutputItemType="Analyzer"
      ReferenceOutputAssembly="false" />
    <ProjectReference
      Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\Microsoft.Interop.SourceGeneration\Microsoft.Interop.SourceGeneration.csproj"
      OutputItemType="Analyzer"
      ReferenceOutputAssembly="false" />
  </ItemGroup>
  <ItemGroup Condition="'@(EnabledGenerators)' != ''
                        and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator'))
                        and '$(IncludeDllImportGeneratorSources)' == 'true'">
    <Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\GeneratedDllImportAttribute.cs" />
    <Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\StringMarshalling.cs" />

    <!-- Only add the following files if we are on the latest TFM (that is, net7). -->
    <Compile Condition="'$(NetCoreAppCurrentTargetFrameworkMoniker)' == '$(TargetFrameworkMoniker)'" Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\GeneratedMarshallingAttribute.cs" />

    <!-- Only add the following files if we are on the latest TFM (that is, net7) and the project is SPCL or has references to System.Runtime.CompilerServices.Unsafe and System.Memory -->
    <Compile Condition="'$(NetCoreAppCurrentTargetFrameworkMoniker)' == '$(TargetFrameworkMoniker)'
                        and (
                          '$(MSBuildProjectName)' == 'System.Private.CoreLib'
                          or '$(EnableDllImportGenerator)' == 'true'
                          or ('@(Reference)' != ''
                            and @(Reference->AnyHaveMetadataValue('Identity', 'System.Memory')))
                          or ('@(ProjectReference)' != ''
                            and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))))" Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\ArrayMarshaller.cs" />
  </ItemGroup>

  <Target Name="ConfigureGenerators"
          DependsOnTargets="ConfigureDllImportGenerator"
          BeforeTargets="CoreCompile" />

  <!-- Microsoft.Interop.DllImportGenerator -->
  <Target Name="ConfigureDllImportGenerator"
          Condition="'@(EnabledGenerators)' != '' and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator'))"
          DependsOnTargets="ResolveProjectReferences"
          BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun">
    <PropertyGroup>
        <DllImportGenerator_UseMarshalType>true</DllImportGenerator_UseMarshalType>
    </PropertyGroup>
  </Target>

  <Import Project="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props" />
</Project>