-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathSdk.targets
208 lines (176 loc) · 11.8 KB
/
Sdk.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT license.
-->
<Project InitialTargets="CheckPackageReferences" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!--
Disable Microsoft.Build.CentralPackageVersions if NuGet's built in central package management is in use
-->
<EnableCentralPackageVersions Condition="'$(ManagePackageVersionsCentrally)' == 'true'">false</EnableCentralPackageVersions>
</PropertyGroup>
<!--
Import a user extension if specified.
-->
<Import Project="$(CustomBeforeCentralPackageVersionsTargets)"
Condition=" '$(EnableCentralPackageVersions)' != 'false' And '$(CustomBeforeCentralPackageVersionsTargets)' != '' And Exists('$(CustomBeforeCentralPackageVersionsTargets)') " />
<PropertyGroup Condition=" '$(EnableCentralPackageVersions)' != 'false' ">
<!--
Walk up the directory tree looking for a Packages.props, unless a user has already specified a path.
-->
<CentralPackagesFile Condition=" '$(CentralPackagesFile)' == '' ">$([MSBuild]::GetPathOfFileAbove('Packages.props', $(MSBuildProjectDirectory)))</CentralPackagesFile>
<!--
Disable all functionality if:
* The central package management file does not exist.
* The project is using packages.config. Visual Studio project systems will get confused if there are any PackageReference
items and it won't show the packages in the packages.config. NuGet does not support using both and so packages.config has to win.
* The project is a type that doesn't not support PackageReference in Visual Studio (like vcxproj, ccproj, or nuproj).
-->
<EnableCentralPackageVersions
Condition="'$(EnableCentralPackageVersions)' == '' And (!Exists('$(CentralPackagesFile)') Or Exists('$(MSBuildProjectDirectory)\packages.config') Or '$(MSBuildProjectExtension)' == '.vcxproj' Or '$(MSBuildProjectExtension)' == '.ccproj' Or '$(MSBuildProjectExtension)' == '.nuproj')">false</EnableCentralPackageVersions>
<!--
Include this file and the Packages.props file (if necessary) in MSBuildAllProjects so that rebuilds happen if the Packages.props changes.
-->
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current'">$(MSBuildAllProjects);$(MsBuildThisFileFullPath)</MSBuildAllProjects>
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current' And '$(EnableCentralPackageVersions)' != 'false'">$(CentralPackagesFile);$(MSBuildAllProjects)</MSBuildAllProjects>
</PropertyGroup>
<ItemDefinitionGroup Condition=" '$(EnableCentralPackageVersions)' != 'false' ">
<GlobalPackageReference Condition=" $([MSBuild]::ValueOrDefault('$(EnableGlobalPackageReferencePrivateAssetsAll)', 'true')) ">
<!--
Default global package references to only consume the Analyzers and Build logic in a package.
This helps ensure that the package assets are not passed to the compiler or copied to the
output directory. Having a compile-time reference to a package for all projects in a tree
is not recommended. You should only have "global" references to packages that are used for
build.
-->
<IncludeAssets>Analyzers;Build;BuildMultitargeting;BuildTransitive</IncludeAssets>
<!--
Default global package references to have all assets private. This is because global package
references are generally stuff like versioning, signing, etc and should not flow to downstream
dependencies. Also, global package references are already referenced by every project in the
tree so we don't need them to be transitive.
-->
<PrivateAssets>All</PrivateAssets>
</GlobalPackageReference>
</ItemDefinitionGroup>
<ItemGroup Condition=" '$(EnableCentralPackageVersions)' != 'false' ">
<!--
Workaround the issue where FSharp SDK adds implicit PackageReference items but doesn't mark them as such
https://github.com/microsoft/MSBuildSdks/issues/90
-->
<PackageReference Update="FSharp.Core"
Condition="'$(MSBuildProjectExtension)' == '.fsproj' And '$(DisableImplicitFSharpCoreReference)' != 'true' And '$(UpdateImplicitFSharpCoreReference)' != 'false'"
IsImplicitlyDefined="true" />
<PackageReference Update="System.ValueTuple"
Condition="'$(MSBuildProjectExtension)' == '.fsproj' And '$(DisableImplicitSystemValueTupleReference)' != 'true' And '$(UpdateImplicitSystemValueTupleReference)' != 'false' And '$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(_TargetFrameworkVersionWithoutV)' >= '4.0' And '$(_TargetFrameworkVersionWithoutV)' <= '4.7'"
IsImplicitlyDefined="true" />
<!--
Workaround the issue where Microsoft.AspNet.App and Microsoft.AspNet.All are not marked as implicitly defined
-->
<PackageReference Update="Microsoft.AspNetCore.App"
Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true'"
IsImplicitlyDefined="true" />
<PackageReference Update="Microsoft.AspNetCore.All"
Condition="'$(UsingMicrosoftNETSdkWeb)' == 'true'"
IsImplicitlyDefined="true" />
<!--
Store a list of <PackageReference /> items that specified a Version so that an error can be displayed.
-->
<_PackageReferenceWithVersion Include="@(PackageReference->HasMetadata('Version'))" />
<!--
Store a list of the original <PackageReference /> items so later they can be checked for duplicates in
the <GlobalPackageReference /> items. Clear the metadata to save some memory.
-->
<_OriginalPackageReference Include="@(PackageReference->ClearMetadata())" />
</ItemGroup>
<Import Project="$(CentralPackagesFile)"
Condition=" '$(EnableCentralPackageVersions)' != 'false' " />
<ItemGroup Condition=" '$(EnableCentralPackageVersions)' != 'false' ">
<!--
Copy <GlobalPackageReference /> items to the list of <PackageReference /> items.
-->
<PackageReference Include="@(GlobalPackageReference)"
Condition=" '$(EnableGlobalPackageReferences)' != 'false' " />
<!--
Get a list of <PackageReference /> items that specify a VersionOverride but not a Version; that is,
there's no entry for them in the central package management file.
Clear the metadata to save some memory.
-->
<_PackageReferenceWithVersionOverrideButNoCentralVersion Include="@(PackageReference->HasMetadata('VersionOverride')->ClearMetadata())"
Exclude="@(PackageReference->HasMetadata('Version'))"
Condition=" '$(EnablePackageVersionOverride)' != 'false' And '$(EnablePackageVersionOverrideWithoutCentralVersion)' == 'false' " />
<!--
Get a list of <PackageReference /> items that specify the VersionOverride metadata and copy the value
to the Version metadata. All other metadata is also copied.
VersionOverride is important because it forces the user to opt-in to overriding a version at the project
level.
-->
<_PackageReferenceWithVersionOverride Include="@(PackageReference->HasMetadata('VersionOverride'))"
Version="%(VersionOverride)"
Condition=" '$(EnablePackageVersionOverride)' != 'false' "
/>
<!--
Remove items in the original <PackageReference /> list that have a version override so that they can be
added back. The items being added have their Version set to the original VersionOverride.
-->
<PackageReference Remove="@(_PackageReferenceWithVersionOverride)"
Condition=" '$(EnablePackageVersionOverride)' != 'false' "/>
<PackageReference Include="@(_PackageReferenceWithVersionOverride)"
Condition=" '$(EnablePackageVersionOverride)' != 'false' "/>
<!--
Clear the temporary list of package references with VersionOverride to free up some memory.
-->
<_PackageReferenceWithVersionOverride Remove="@(_PackageReferenceWithVersionOverride)" />
</ItemGroup>
<Target Name="CheckPackageReferences"
Condition=" '$(EnableCentralPackageVersions)' != 'false' And '$(DesignTimeBuild)' != 'true' And @(PackageReference->Count()) > 0 ">
<!--
Get a list of duplicate <PackageReference /> and <GlobalPackageReference /> items. Users must be made aware
that this could cause strange behavior and they should not include a PackageReference if there's already a
global PackageReference.
-->
<ItemGroup Condition=" '$(EnableGlobalPackageReferences)' != 'false' ">
<_DuplicateGlobalPackageReference Include="@(_OriginalPackageReference)"
Condition=" '@(GlobalPackageReference)' == '@(_OriginalPackageReference)' and '%(Identity)' != '' " />
</ItemGroup>
<!--
Log an error if there are any duplicate <PackageReference /> items where a <GlobalPackageReference /> is already defined.
-->
<Error
Text="The package reference '%(_DuplicateGlobalPackageReference.Identity)' is already defined as a GlobalPackageReference in '$(CentralPackagesFile)'. Individual projects do not need to include a PackageReference if a GlobalPackageReference is declared."
Condition=" '$(EnableGlobalPackageReferences)' != 'false' And @(_DuplicateGlobalPackageReference->Count()) > 0"
File="$(MSBuildProjectFullPath)" />
<!--
Generate an error if any explicit PackageReference has a version specified in a project. Users must specify a version in
the central pacakge management file or use VersionOverride.
-->
<Error
Text="The package reference '%(_PackageReferenceWithVersion.Identity)' should not specify a version. Please specify the version in '$(CentralPackagesFile)' or set VersionOverride to override the centrally defined version."
Condition=" @(_PackageReferenceWithVersion->Count()) > 0 And '%(_PackageReferenceWithVersion.IsImplicitlyDefined)' != 'true' And '$(EnablePackageVersionOverride)' != 'false' "
File="$(MSBuildProjectFullPath) "/>
<Error
Text="The package reference '%(_PackageReferenceWithVersion.Identity)' should not specify a version. Please specify the version in '$(CentralPackagesFile)'."
Condition=" @(_PackageReferenceWithVersion->Count()) > 0 And '%(_PackageReferenceWithVersion.IsImplicitlyDefined)' != 'true' And '$(EnablePackageVersionOverride)' == 'false'"
File="$(MSBuildProjectFullPath) "/>
<!--
Generate an error if any explicit PackageReference did not have Version specified in the central package management file or a VersionOverride.
-->
<Error
Text="The package reference '%(PackageReference.Identity)' must have a version defined in '$(CentralPackagesFile)'."
Condition=" '%(PackageReference.IsImplicitlyDefined)' != 'true' And '%(PackageReference.Version)' == '' "
File="$(MSBuildProjectFullPath)" />
<!--
Generate an error if any explicit PackageReference had a VersionOverride but did not have Version specified in the central package management file.
-->
<Error
Text="The package reference '%(_PackageReferenceWithVersionOverrideButNoCentralVersion.Identity)' must have a version defined in '$(CentralPackagesFile)'."
Condition=" @(_PackageReferenceWithVersionOverrideButNoCentralVersion->Count()) > 0 "
File="$(MSBuildProjectFullPath)" />
</Target>
<!--
Import a user extension if specified.
-->
<Import Project="$(CustomAfterCentralPackageVersionsTargets)"
Condition=" '$(EnableCentralPackageVersions)' != 'false' And '$(CustomAfterCentralPackageVersionsTargets)' != '' And Exists('$(CustomAfterCentralPackageVersionsTargets)') " />
</Project>