-
Notifications
You must be signed in to change notification settings - Fork 353
/
Microsoft.DotNet.GenAPI.targets
95 lines (77 loc) · 4.97 KB
/
Microsoft.DotNet.GenAPI.targets
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- If ToolHostCmd is undefined, we default to assuming 'dotnet' is on the path -->
<ToolHostCmd Condition="'$(ToolHostCmd)' == ''">dotnet</ToolHostCmd>
<GenAPITargetPath Condition="'$(GenAPITargetPath)' == ''">$(TargetDir)$(TargetName).cs</GenAPITargetPath>
<_GenAPIPath Condition="'$(MSBuildRuntimeType)' == 'core'">$(MSBuildThisFileDirectory)\..\tools\netcoreapp2.1\Microsoft.DotNet.GenAPI.dll</_GenAPIPath>
<_GenAPIPath Condition="'$(MSBuildRuntimeType)' != 'core'">$(MSBuildThisFileDirectory)\..\tools\net472\Microsoft.DotNet.GenAPI.exe</_GenAPIPath>
<_GenAPICommand Condition="'$(MSBuildRuntimeType)' == 'core'">$(ToolHostCmd) "$(_GenAPIPath)"</_GenAPICommand>
<_GenAPICommand Condition="'$(MSBuildRuntimeType)' != 'core' AND '$(OS)' == 'Windows_NT'">"$(_GenAPIPath)"</_GenAPICommand>
<_GenAPICommand Condition="'$(MSBuildRuntimeType)' != 'core' AND '$(OS)' != 'Windows_NT'">mono --runtime=v4.0.30319 "$(_GenAPIPath)"</_GenAPICommand>
<!-- Sequence ourselves last in PrepareForRun
This ensures the output has been copied to TargetPath, but still permits
us to participate in FileWrites. -->
<PrepareForRunDependsOn Condition="'$(GenerateReferenceAssemblySource)' == 'true'">
$(PrepareForRunDependsOn);
GenerateReferenceAssemblySource;
</PrepareForRunDependsOn>
</PropertyGroup>
<ItemGroup Condition="'$(GeneratePlatformNotSupportedAssembly)' == 'true' OR '$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">
<AssemblyMetadata Include="NotSupported">
<Value>True</Value>
</AssemblyMetadata>
</ItemGroup>
<Target Name="GenerateReferenceAssemblySource"
Inputs="$(TargetPath)"
Outputs="$(GenAPITargetPath)">
<ItemGroup>
<!-- build out a list of directories where dependencies are located -->
<_referencePathDirectoriesWithDuplicates Include="@(ReferencePath->'%(RootDir)%(Directory)'->TrimEnd('\'))" />
<!-- strip metadata, removing duplicates -->
<_referencePathDirectories Include="%(_referencePathDirectoriesWithDuplicates.Identity)" />
</ItemGroup>
<Exec Command="$(_GenAPICommand) -assembly:"$(TargetPath)" -libPath:"@(_referencePathDirectories)" -out:"$(GenAPITargetPath)" $(GenAPIAdditionalParameters)" />
<ItemGroup>
<FileWrites Include="$(GenAPITargetPath)"/>
</ItemGroup>
</Target>
<PropertyGroup Condition="'$(GeneratePlatformNotSupportedAssembly)' == 'true' OR '$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">
<!-- Tell ResolveMatchingContract to run and resolve contract to project reference -->
<ResolveMatchingContract>true</ResolveMatchingContract>
<NotSupportedSourceFile>$(IntermediateOutputPath)$(TargetName).notsupported.cs</NotSupportedSourceFile>
<CoreCompileDependsOn>$(CoreCompileDependsOn);GenerateNotSupportedSource</CoreCompileDependsOn>
<!-- Not supported sources are created from the ref assembly, we currently don't produce finalizers in dummmy assemblies, so we disable ApiCompat to not fail. -->
<RunApiCompat>false</RunApiCompat>
</PropertyGroup>
<!-- GenerateNotSupportedSource
Inputs:
* A contract assembly
* Reference assemblies
Generates source for the contract that throws PlatformNotSupportedException
-->
<Target Name="GenerateNotSupportedSource"
DependsOnTargets="ResolveMatchingContract"
Inputs="@(ReferencePath);@(ResolvedMatchingContract)"
Outputs="$(NotSupportedSourceFile)">
<ItemGroup>
<!-- build out a list of directories where dependencies are located -->
<_referencePathDirectoriesWithDuplicates Include="@(ReferencePath->'%(RootDir)%(Directory)'->TrimEnd('\'))" />
<!-- strip metadata, removing duplicates -->
<_referencePathDirectories Include="%(_referencePathDirectoriesWithDuplicates.Identity)" />
</ItemGroup>
<Error Text="No single matching contract found." Condition="'@(ResolvedMatchingContract->Count())' != '1'" />
<PropertyGroup>
<GenAPIArgs>-assembly:"%(ResolvedMatchingContract.Identity)"</GenAPIArgs>
<GenAPIArgs>$(GenAPIArgs) -libPath:"@(_referencePathDirectories)"</GenAPIArgs>
<GenAPIArgs>$(GenAPIArgs) -out:"$(NotSupportedSourceFile)"</GenAPIArgs>
<GenAPIArgs Condition="'$(GeneratePlatformNotSupportedAssembly)' == 'true' OR '$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">$(GenAPIArgs) -throw:"$(GeneratePlatformNotSupportedAssemblyMessage)"</GenAPIArgs>
<GenAPIArgs Condition="'$(GeneratePlatformNotSupportedAssemblyWithGlobalPrefix)' == 'true'">$(GenAPIArgs) -global</GenAPIArgs>
</PropertyGroup>
<Exec Command="$(_GenAPICommand) $(GenAPIArgs)" WorkingDirectory="$(ToolRuntimePath)" />
<ItemGroup>
<FileWrites Include="$(NotSupportedSourceFile)" />
<Compile Include="$(NotSupportedSourceFile)" />
</ItemGroup>
</Target>
</Project>