forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
referenceFromRuntime.targets
59 lines (49 loc) · 3.47 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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AddReferenceFromRuntimeForTests"
AfterTargets="ResolveAssemblyReferences"
Condition="'$(IsTestProject)'=='true' AND '@(ReferenceFromRuntime)' != ''">
<ItemGroup>
<!-- tests can use anything from the RuntimePath -->
<ReferencePath Include="@(ReferenceFromRuntime->'$(RuntimePath)%(Identity).dll')" />
<ReferenceCopyLocalPaths Condition="'%(ReferenceFromRuntime.Private)' == 'true'" Include="@(ReferenceFromRuntime->'$(RuntimePath)%(Identity).dll')" />
</ItemGroup>
</Target>
<Target Name="AddRuntimeProjectReference"
BeforeTargets="AddProjectReferencesDynamically"
Condition="'$(IsTestProject)'!='true' AND '@(ReferenceFromRuntime)' != ''">
<Error Condition="('$(IsReferenceAssembly)' != 'true' OR '$(AllowReferenceFromRuntime)' == 'true') AND '$(RuntimeProjectFile)' == ''" Text="RuntimeProjectFile must be specified when using ReferenceFromRuntime from source projects." />
<Error Condition="'$(IsReferenceAssembly)' == 'true' AND '$(AllowReferenceFromRuntime)' != 'true'" Text="ReferenceFromRuntime may not be used from reference assemblies." />
<ItemGroup>
<ProjectReference Include="$(RuntimeProjectFile)">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>_referencePathFromRuntime</OutputItemType>
</ProjectReference>
</ItemGroup>
</Target>
<Target Name="FilterReferenceFromRuntime"
AfterTargets="ResolveProjectReferences"
Condition="'$(IsTestProject)'!='true' AND '@(ReferenceFromRuntime)' != ''">
<ItemGroup>
<!-- transform to filename in order to intersect -->
<_referencePathFromRuntimeByFileName Include="@(_referencePathFromRuntime->'%(FileName)')" Condition="'%(_referencePathFromRuntime.Extension)' == '.dll'" >
<ReferencePath>%(Identity)</ReferencePath>
</_referencePathFromRuntimeByFileName>
<!-- intersect with ReferenceFromRuntime -->
<_filteredReferencePathFromRuntimeByFileName Include="@(_referencePathFromRuntimeByFileName)"
Condition="'@(_referencePathFromRuntimeByFileName)' == '@(ReferenceFromRuntime)' AND '%(Identity)' != ''" />
<_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="@(_referencePathFromRuntimeByFileName)"
Condition="'@(_referencePathFromRuntimeByFileName)' == '@(_remainingReferenceFromRuntimeWithNI)' AND '%(Identity)' != ''" />
<_missingReferenceFromRuntime Include="@(_remainingReferenceFromRuntimeWithNI)" Exclude="@(_filteredReferencePathFromRuntimeByFileName)" />
<!-- transform back to path -->
<ReferencePath Include="@(_filteredReferencePathFromRuntimeByFileName->'%(ReferencePath)')" />
</ItemGroup>
<Error Condition="'@(_missingReferenceFromRuntime)' != ''"
Text="Could not resolve ReferenceFromRuntime item(s) '%(_missingReferenceFromRuntime.OriginalReferenceFromRuntime)' from '$(RuntimeProjectFile)'." />
</Target>
</Project>