-
Notifications
You must be signed in to change notification settings - Fork 0
/
Directory.Build.targets
69 lines (52 loc) · 3.06 KB
/
Directory.Build.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
<?xml version="1.0" encoding="utf-8"?>
<Project InitialTargets="ApplyPackageVersions" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<!-- Stores the package versions specified in individual projects -->
<ProjectSpecifiedPackageVersion Include="@(PackageVersion)" />
</ItemGroup>
<Import Project="$(PackageVersionsFile)" />
<ItemGroup>
<!-- Clear package versions that are duplicated from a project and the central package versions file -->
<PackageVersion Remove="@(ProjectSpecifiedPackageVersion)" />
<!-- Add back the project specified package versions -->
<PackageVersion Include="@(ProjectSpecifiedPackageVersion)" />
<!-- Stores the original package references used later to determine if there are any problems -->
<OriginalPackageReference Include="@(PackageReference)" />
<!-- Store all PackageVersion items that do not have a PackageReference -->
<_PackagesNotReferenced Include="@(PackageVersion)" Exclude="@(PackageReference)" />
<!-- Clear the PackageReference list -->
<PackageReference Remove="@(OriginalPackageReference)" />
<!-- Add back the PackageReference its from the list that contains versions, excluding the items not referenced -->
<PackageReference Include="@(PackageVersion)" Exclude="@(_PackagesNotReferenced)" />
<!-- Clear the temporary list of items not referenced -->
<_PackagesNotReferenced Remove="@(_PackagesNotReferenced)" />
</ItemGroup>
<Target Name="ApplyPackageVersions"
Condition=" '@(PackageReference)' != '' ">
<!-- Determine all of the original PackageReference items that did not have a PackageVersion -->
<ItemGroup>
<MissingPackageReference Include="@(OriginalPackageReference)" Exclude="@(PackageVersion)" />
</ItemGroup>
<!--
Generate an error if any PackageReference has a version specified and its not an implicit item
-->
<Error
Text="The package reference '%(OriginalPackageReference.Identity)' should not specify a version. Please specify the version in '$(PackageVersionsFile)'."
Condition=" '%(OriginalPackageReference.IsImplicitlyDefined)' != 'true' And '%(OriginalPackageReference.Version)' != '' "
File="$(MSBuildProjectFullPath) "/>
<!--
Generate an error if any explicit PackageReference did not have matching PackageVersion
-->
<Error
Text="The package reference '%(MissingPackageReference.Identity)' must have a version defined in '$(PackageVersionsFile)'."
Condition=" '@(MissingPackageReference)' != '' And '%(MissingPackageReference.IsImplicitlyDefined)' != 'true' "
File="$(MSBuildProjectFullPath)" />
<!--
Generate an error if any implicit PackageReference did not have matching PackageVersion
-->
<Error
Text="The implicit package reference '%(MissingPackageReference.Identity)' must have a version defined in '$(PackageVersionsFile)'."
Condition=" '@(MissingPackageReference)' != '' And '%(MissingPackageReference.IsImplicitlyDefined)' == 'true' "
File="$(MSBuildProjectFullPath)" />
</Target>
</Project>