forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
referenceFromRuntime.targets
93 lines (75 loc) · 5.19 KB
/
referenceFromRuntime.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
<Project>
<PropertyGroup Condition="$(TargetFramework.StartsWith('netcoreapp')) and '$(TargetFramework)' != '$(NetCoreAppCurrent)'">
<PrepareProjectReferencesDependsOn>
AddRuntimeProjectReference;
$(PrepareProjectReferencesDependsOn);
</PrepareProjectReferencesDependsOn>
<ResolveReferencesDependsOn>
AddRuntimeProjectReference;
$(ResolveReferencesDependsOn);
</ResolveReferencesDependsOn>
<CleanDependsOn>
AddRuntimeProjectReference;
$(CleanDependsOn)
</CleanDependsOn>
</PropertyGroup>
<Target Name="AddRuntimeProjectReference"
Condition="'$(IsTestProject)'!='true' and '@(ReferenceFromRuntime)' != ''">
<Error Condition="'$(IsReferenceAssembly)' == 'true' and '$(AllowReferenceFromRuntime)' != 'true'" Text="ReferenceFromRuntime may not be used from reference assemblies." />
<PropertyGroup>
<RuntimeProjectFile>$([MSBuild]::NormalizePath('$(LibrariesProjectRoot)', 'restore', 'runtime', 'runtime.depproj'))</RuntimeProjectFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(RuntimeProjectFile)">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>_referencePathFromRestoredRuntime</OutputItemType>
</ProjectReference>
</ItemGroup>
</Target>
<Target Name="GetFilesFromCoreCLR" Returns="@(CoreCLRFiles)" DependsOnTargets="ResolveCoreCLRFilesFromLocalBuild" />
<Target Name="FilterReferenceFromRuntime"
AfterTargets="ResolveProjectReferences"
Condition="'@(ReferenceFromRuntime)' != ''">
<Error Condition="'$(IsReferenceAssembly)' == 'true' and '$(AllowReferenceFromRuntime)' != 'true'" Text="ReferenceFromRuntime may not be used from reference assemblies." />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="GetFilesFromCoreCLR" Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<Output TaskParameter="TargetOutputs" ItemName="CoreCLRFiles" />
</MSBuild>
<ItemGroup>
<_referencePathFromRuntime Include="@(CoreCLRFiles)" Private="false" />
<_referencePathFromRuntime Include="@(_referencePathFromRestoredRuntime)" Private="false" />
<!-- If this is a test project, also use the $(RuntimePath) to find a @(ReferenceFromRuntime) assembly. -->
<_referencePathFromRuntime Include="@(ReferenceFromRuntime->'$(RuntimePath)%(Identity).dll')" Condition="'$(IsTestProject)' == 'true'" />
<!-- transform to filename in order to intersect -->
<_referencePathFromRuntimeByFileName Include="@(_referencePathFromRuntime->'%(FileName)')" Condition="'%(_referencePathFromRuntime.Extension)' == '.dll'" >
<ReferencePath>%(Identity)</ReferencePath>
</_referencePathFromRuntimeByFileName>
</ItemGroup>
<RemoveDuplicates Inputs="@(_referencePathFromRuntimeByFileName)">
<Output TaskParameter="Filtered" ItemName="_referencePathFromRuntimeByFileNameFiltered" />
</RemoveDuplicates>
<ItemGroup>
<!-- intersect with ReferenceFromRuntime -->
<_filteredReferencePathFromRuntimeByFileName Include="@(_referencePathFromRuntimeByFileNameFiltered)"
Condition="'@(_referencePathFromRuntimeByFileNameFiltered)' == '@(ReferenceFromRuntime)' and '%(Identity)' != ''">
<Aliases>@(ReferenceFromRuntime->'%(Aliases)')</Aliases>
</_filteredReferencePathFromRuntimeByFileName>
<_remainingReferenceFromRuntime Include="@(ReferenceFromRuntime)" Exclude="@(_filteredReferencePathFromRuntimeByFileName)" />
<!-- Fallback and check for native images for the references as well -->
<_remainingReferenceFromRuntimeWithNI Include="@(_remainingReferenceFromRuntime->'%(Identity).ni')">
<OriginalReferenceFromRuntime>%(Identity)</OriginalReferenceFromRuntime>
</_remainingReferenceFromRuntimeWithNI>
<_filteredReferencePathFromRuntimeByFileName Include="@(_referencePathFromRuntimeByFileNameFiltered)"
Condition="'@(_referencePathFromRuntimeByFileNameFiltered)' == '@(_remainingReferenceFromRuntimeWithNI)' and '%(Identity)' != ''">
<Aliases>@(_remainingReferenceFromRuntimeWithNI->'%(Aliases)')</Aliases>
</_filteredReferencePathFromRuntimeByFileName>
<_missingReferenceFromRuntime Include="@(_remainingReferenceFromRuntimeWithNI)" Exclude="@(_filteredReferencePathFromRuntimeByFileName)" />
<!-- transform back to path -->
<!-- We are adding two items(with and without aliases) for references having Aliases. The major reason behind this to not use the Aliases for all the types in that reference. -->
<!-- We can't use a Reference item for both since only the first one will be kept. Use ReferencePath for the second reference so it will still be passed to the compiler. -->
<Reference Include="@(_filteredReferencePathFromRuntimeByFileName->'%(ReferencePath)')" />
<ReferencePath Include="@(_filteredReferencePathFromRuntimeByFileName->'%(ReferencePath)')" Condition="'%(_filteredReferencePathFromRuntimeByFileName.Aliases)' != ''" Aliases="" />
</ItemGroup>
<Error Condition="'@(_missingReferenceFromRuntime)' != ''"
Text="Could not resolve ReferenceFromRuntime item(s) '%(_missingReferenceFromRuntime.OriginalReferenceFromRuntime)' from '$(RuntimeProjectFile)'." />
</Target>
</Project>