Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Microsoft.NuGet.targets « Microsoft.NuGet.Build.Tasks « src - github.com/mono/NuGet.BuildTasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 666a298dec8a270221a1efdb7d0cf7f79e6d9122 (plain)
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!--
***********************************************************************************************
Microsoft.NuGet.targets

WARNING:  DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
          created a backup copy.  Incorrect changes to this file will make it
          impossible to load or build your projects from the command-line or the IDE.

Copyright (c) .NET Foundation. All rights reserved. 
***********************************************************************************************
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask TaskName="Microsoft.NuGet.Build.Tasks.ResolveNuGetPackageAssets" AssemblyFile="Microsoft.NuGet.Build.Tasks.dll" />

  <!--
  Identify the project asset/lock file in following order:
  1. If ProjectAssetsFile exists, then simply use it since it means project uses PackageReference
  2. If ProjectLockFile already defined, then use it instead of constructing our own
  3. Construct our own project lock file for that first check for <ProjectName>.project.json file
  4. And lastly check for project.json file existence, and use project.lock.json file

  If none of these conditions satisfy then these NuGet build targets will not be executed.
  -->
  <Choose>
    <When Condition="'$(ProjectAssetsFile)' != ''">
      <!-- The ProjectAssetsFile has been specified which means it uses PackageReference, so use that. -->
      <PropertyGroup>
        <ProjectLockFile>$(ProjectAssetsFile)</ProjectLockFile>
      </PropertyGroup>
    </When>

    <When Condition="'$(RestoreProjectStyle)' == 'PackageReference'">
      <!-- The RestoreProjectStyle property has been specified to PackageReference, so use that. -->
      <PropertyGroup>
        <ProjectLockFile>$(BaseIntermediateOutputPath)project.assets.json</ProjectLockFile>
      </PropertyGroup>
    </When>

    <When Condition="'$(ProjectLockFile)' != ''">
      <!-- The ProjectLockFile has been specified; don't compute it. -->
    </When>

    <When Condition="Exists('$(MSBuildProjectName).project.json')">
      <!-- There's a MyProj.project.json file, so use MyProj.project.lock.json. -->
      <PropertyGroup>
        <ProjectLockFile>$(MSBuildProjectName).project.lock.json</ProjectLockFile>
      </PropertyGroup>
    </When>

    <When Condition="Exists('project.json')">
      <!-- There's a project.json file, so use project.lock.json. -->
      <PropertyGroup>
        <ProjectLockFile>project.lock.json</ProjectLockFile>
      </PropertyGroup>
    </When>

    <Otherwise>
      <!-- No assets or lock file provided at all, so fallback to project.assets.json file.-->
      <PropertyGroup>
        <ProjectLockFile>$(BaseIntermediateOutputPath)project.assets.json</ProjectLockFile>
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <!-- Add to MSBuildAllProjects in order to better support incremental builds. -->
  <PropertyGroup>
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
  </PropertyGroup>

  <PropertyGroup>
    <ResolveNuGetPackages Condition="'$(ResolveNuGetPackages)' == '' and '$(MSBuildProjectExtension)' != '.xproj'">true</ResolveNuGetPackages>

    <!-- 
    if BaseNuGetRuntimeIdentifier is defined then simply use it as RuntimeIdentifier, otherwise
    we'll set RuntimeIdentifiers to default value later on.
    -->
    <RuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' != ''">$(BaseNuGetRuntimeIdentifier)</RuntimeIdentifier>

    <BaseNuGetRuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' == '' and '$(TargetPlatformIdentifier)' == 'UAP'">win10</BaseNuGetRuntimeIdentifier>
    <BaseNuGetRuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' == ''">win</BaseNuGetRuntimeIdentifier>

    <UseTargetPlatformAsNuGetTargetMoniker Condition="'$(UseTargetPlatformAsNuGetTargetMoniker)' == '' AND '$(TargetFrameworkMoniker)' == '.NETCore,Version=v5.0'">true</UseTargetPlatformAsNuGetTargetMoniker>
    <NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == '' AND '$(UseTargetPlatformAsNuGetTargetMoniker)' == 'true'">$(TargetPlatformIdentifier),Version=v$([System.Version]::Parse('$(TargetPlatformMinVersion)').ToString(3))</NuGetTargetMoniker>
    <NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == '' AND '$(UseTargetPlatformAsNuGetTargetMoniker)' != 'true'">$(TargetFrameworkMoniker)</NuGetTargetMoniker>

    <CopyNuGetImplementations Condition="'$(CopyNuGetImplementations)' == '' and (('$(OutputType)' != 'library' and '$(OutputType)' != 'winmdobj') or ('$(AppxPackage)' == 'true') or '$(TargetFrameworkIdentifier)' == '.NETFramework')">true</CopyNuGetImplementations>
    <IncludeFrameworkReferencesFromNuGet Condition="'$(IncludeFrameworkReferencesFromNuGet)' == ''">true</IncludeFrameworkReferencesFromNuGet>

    <_NuGetRuntimeIdentifierPlatformTargetSuffix Condition="'$(PlatformTarget)' != '' and '$(PlatformTarget)' != 'AnyCPU'">-$(PlatformTarget.ToLower())</_NuGetRuntimeIdentifierPlatformTargetSuffix>
    <_NuGetRuntimeIdentifierWithoutAot>$(BaseNuGetRuntimeIdentifier)$(_NuGetRuntimeIdentifierPlatformTargetSuffix)</_NuGetRuntimeIdentifierWithoutAot>
  </PropertyGroup>

  <!-- If a NuGetRuntimeIdentifier wasn't already specified, let's go generate it -->
  <PropertyGroup Condition="'$(NuGetRuntimeIdentifier)' == '' and '$(CopyNuGetImplementations)' == 'true'">
    <NuGetRuntimeIdentifier>$(_NuGetRuntimeIdentifierWithoutAot)</NuGetRuntimeIdentifier>
    <NuGetRuntimeIdentifier Condition="'$(UseDotNetNativeToolchain)' == 'true'">$(_NuGetRuntimeIdentifierWithoutAot)-aot</NuGetRuntimeIdentifier>
  </PropertyGroup>

  <!-- If RuntimeIdentifiers weren't already specified for non-UAP projects, then generate it -->
  <PropertyGroup Condition="'$(BaseNuGetRuntimeIdentifier)' == 'win' and '$(NuGetRuntimeIdentifier)' != '' and '$(RuntimeIdentifiers)' == '' and '$(RuntimeIdentifier)' == ''">
    <RuntimeIdentifiers>win;win-x86;win-x64</RuntimeIdentifiers>
  </PropertyGroup>

  <ItemGroup>
    <!-- If we are resolving from project.lock.json, we need to consider any edit to it as something that forces a rebuild -->
    <CustomAdditionalCompileInputs Include="$(ProjectLockFile)" Condition="'$(ResolveNuGetPackages)' == 'true' and Exists('$(ProjectLockFile)')" />
  </ItemGroup>

  <PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'UAP'">
    <_NuGetTargetFallbackMoniker>UAP,Version=v10.0</_NuGetTargetFallbackMoniker>
    <ImplicitlyExpandTargetFramework>false</ImplicitlyExpandTargetFramework>
    <EnableAppLocalFXWorkaround>false</EnableAppLocalFXWorkaround>
    <UseNetNativeCustomFramework>true</UseNetNativeCustomFramework>
  </PropertyGroup>

  <!--
    ============================================================
                                        GetProjectsReferencingProjectJsonFiles
    ============================================================
  -->
  <Target Name="GetProjectsReferencingProjectJson" DependsOnTargets="_SplitProjectReferencesByFileExistence" Returns="@(_ProjectReferencingProjectJsonFile)">
    <ItemGroup Condition="'$(ResolveNuGetPackages)' == 'true'">
      <_ProjectReferencingProjectJsonFile Include="$(MSBuildProjectFullPath)">
        <ProjectReferences>@(ProjectReference)</ProjectReferences>
        <ProjectJson>$(MSBuildProjectDirectory)\project.json</ProjectJson>
      </_ProjectReferencingProjectJsonFile>
    </ItemGroup>

    <MSBuild
      Projects="@(_MSBuildProjectReferenceExistent)"
      Targets="GetProjectsReferencingProjectJson"
      BuildInParallel="$(BuildInParallel)"
      Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
      RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">

      <Output TaskParameter="TargetOutputs" ItemName="_ProjectReferencingProjectJsonFile" />
    </MSBuild>
  </Target>

  <ItemGroup>
    <NuGetPreprocessorValue Include="rootnamespace">
      <Value>$(RootNamespace)</Value>
    </NuGetPreprocessorValue>
    <NuGetPreprocessorValue Include="assemblyname">
      <Value>$(AssemblyName)</Value>
    </NuGetPreprocessorValue>
    <NuGetPreprocessorValue Include="fullpath">
      <Value>$(MSBuildProjectDirectory)</Value>
    </NuGetPreprocessorValue>
    <NuGetPreprocessorValue Include="outputfilename">
      <Value>$(TargetFileName)</Value>
    </NuGetPreprocessorValue>
    <NuGetPreprocessorValue Include="filename">
      <Value>$(MSBuildProjectFile)</Value>
    </NuGetPreprocessorValue>
  </ItemGroup>

  <!--
    ============================================================
                                        ResolveNuGetPackageAssets

    Resolve assets from consumed NuGet packages listed in the project.lock.json

        [OUT]
        @(Analyzer) - Paths to build-time diagnostic analyzers
        @(Reference) - Paths to build-time NuGet dependencies
        @(ReferenceCopyLocalPaths) - Paths to run-time dependencies to copy
    ============================================================
  -->
  <PropertyGroup>
    <ResolveAssemblyReferencesDependsOn>$(ResolveAssemblyReferencesDependsOn);ResolveNuGetPackageAssets</ResolveAssemblyReferencesDependsOn>
    <PrepareResourcesDependsOn>ResolveNuGetPackageAssets;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
  </PropertyGroup>

  <PropertyGroup>
    <ResolveNuGetPackageAssetsDependsOn>ResolveProjectReferences</ResolveNuGetPackageAssetsDependsOn>
    <ResolveNuGetPackageAssetsDependsOn Condition="'$(ImplicitlyExpandTargetFramework)' == 'true'">$(ResolveNuGetPackageAssetsDependsOn);ImplicitlyExpandTargetFramework</ResolveNuGetPackageAssetsDependsOn>
  </PropertyGroup>

  <Target Name="ResolveNuGetPackageAssets"
          DependsOnTargets="$(ResolveNuGetPackageAssetsDependsOn)"
          Condition="'$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')">

    <ResolveNuGetPackageAssets AllowFallbackOnTargetSelection="$(DesignTimeBuild)"
                               ContinueOnError="$(ContinueOnError)"
                               IncludeFrameworkReferences="$(IncludeFrameworkReferencesFromNuGet)"
                               NuGetPackagesDirectory="$(NuGetPackagesDirectory)"
                               RuntimeIdentifier="$(NuGetRuntimeIdentifier)"
                               ProjectLanguage="$(Language)"
                               ProjectLockFile="$(ProjectLockFile)"
                               ContentPreprocessorValues="@(NuGetPreprocessorValue)"
                               ContentPreprocessorOutputDirectory="$(IntermediateOutputPath)\NuGet"
                               TargetMonikers="$(NuGetTargetMoniker);$(_NuGetTargetFallbackMoniker)">

      <Output TaskParameter="ResolvedAnalyzers" ItemName="Analyzer" />
      <Output TaskParameter="ResolvedCopyLocalItems" ItemName="ReferenceCopyLocalPaths" />
      <Output TaskParameter="ResolvedReferences" ItemName="_ReferencesFromNuGetPackages" />
      <Output TaskParameter="ReferencedPackages" ItemName="ReferencedNuGetPackages" />
      <Output TaskParameter="ContentItems" ItemName="_NuGetContentItems" />
      <Output TaskParameter="FileWrites" ItemName="FileWrites" />
    </ResolveNuGetPackageAssets>

    <ItemGroup>
      <!-- Remove exact references, such as if a package had a framework reference to 'System' that we already have -->
      <Reference Remove="@(_ReferencesFromNuGetPackages)" />

      <!-- Remove simple name references that are already implicitly added -->
      <_ReferencesFromNuGetPackages Remove="%(ReferencePath.FileName)" Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'" />

      <!-- Include NuGet references in the proper groups. Project-to-project references must go in the
           _ResolvedProjectReferencePaths group which matches the behavior of the ResolveProjectReferences
           target. This ensures that even if the assembly is missing on disk, it still makes it to the compiler. -->
      <Reference Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' != 'Project'" />
      <_ResolvedProjectReferencePaths Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' == 'Project'" />

      <!-- Remove simple name references if we're directly providing a reference assembly to the compiler. For example,
           consider a project with an Reference Include="System", and some NuGet package is providing System.dll -->
      <Reference Remove="%(_ReferencesFromNuGetPackages.FileName)" Condition="'%(_ReferencesFromNuGetPackages.NuGetIsFrameworkReference)' == 'false'"/>
    </ItemGroup>

    <PropertyGroup Condition=" '$(AutoUnifyAssemblyReferences)' == 'true' ">
      <!-- Normally Design Time Assembly Resolution (DTAR) won't consider these references.
           Put DTAR in a mode where it will prefer the output of RAR and unify. -->
      <DTARUseReferencesFromProject>true</DTARUseReferencesFromProject>
    </PropertyGroup>

    <!-- The items in _NuGetContentItems need to go into the appropriately-named item group, but the names depend upon the items
         themselves. Split it apart. -->
    <CreateItem Include="@(_NuGetContentItems)" Condition="'@(_NuGetContentItems)' != ''">
      <Output TaskParameter="Include" ItemName="%(_NuGetContentItems.NuGetItemType)" />
    </CreateItem>
  </Target>

  <Target Name="RuntimeImplementationProjectOutputGroup"
          Returns="@(RuntimeImplementationProjectOutputGroupOutput)"
          Condition="'$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')">

    <!-- This output group must contain the implementation assemblies for the host (i.e. design time) environment, not the
         target environment. Thus, we explicitly pass the RuntimeIdentifier that doesn't have the -aot suffix -->
    <ResolveNuGetPackageAssets AllowFallbackOnTargetSelection="$(DesignTimeBuild)"
                               NuGetPackagesDirectory="$(NuGetPackagesDirectory)"
                               RuntimeIdentifier="$(_NuGetRuntimeIdentifierWithoutAot)"
                               ProjectLanguage="$(Language)"
                               ProjectLockFile="$(ProjectLockFile)"
                               TargetMonikers="$(NuGetTargetMoniker);$(_NuGetTargetFallbackMoniker)">

      <Output TaskParameter="ResolvedCopyLocalItems" ItemName="NonAheadOfTimeRuntimeImplementations" />
    </ResolveNuGetPackageAssets>

    <ItemGroup>
      <RuntimeImplementationProjectOutputGroupOutput Include="%(NonAheadOfTimeRuntimeImplementations.Identity)">
        <FinalOutputPath>%(NonAheadOfTimeRuntimeImplementations.FullPath)</FinalOutputPath>
        <TargetPath>%(NonAheadOfTimeRuntimeImplementations.FullPath)</TargetPath>
      </RuntimeImplementationProjectOutputGroupOutput>
    </ItemGroup>
  </Target>

  <!--
    ============================================================
            Framework injection into mixed-target applications
    ============================================================
  -->
  <PropertyGroup>
    <NuGetTargetFrameworkMonikerToInject Condition="'$(NuGetTargetFrameworkMonikerToInject)' == ''">.NETCore,Version=v5.0</NuGetTargetFrameworkMonikerToInject>
    <NuGetTargetMonikerToInject Condition="'$(NuGetTargetMonikerToInject)' == ''">.NETCore,Version=v5.0</NuGetTargetMonikerToInject>
    <_ComputeNetCoreFrameworkInjectionParametersBeforeTargets Condition="'$(AppxPackage)' == 'true' and '$(TargetPlatformIdentifier)' == 'UAP'">BeforeGenerateProjectPriFile</_ComputeNetCoreFrameworkInjectionParametersBeforeTargets>
  </PropertyGroup>

  <Target Name="ComputeNetCoreFrameworkInjectionParameters" BeforeTargets="$(_ComputeNetCoreFrameworkInjectionParametersBeforeTargets)" DependsOnTargets="_AddUnionWinmd" Condition="'$(_ComputeNetCoreFrameworkInjectionParametersBeforeTargets)' != ''">
    <PropertyGroup>
      <_PackagingOutputsIncludesFramework Condition="'%(PackagingOutputs.FileName)%(PackagingOutputs.Extension)' == 'System.Runtime.dll'">true</_PackagingOutputsIncludesFramework>
      <_AppContainsManagedCodeForInjection Condition="'%(PackagingOutputs.Identity)' == '$(_TargetPlatformSdkDir)UnionMetadata\Windows.winmd'">true</_AppContainsManagedCodeForInjection>
      <_AppContainsManagedCodeForInjection Condition="'%(PackagingOutputs.Identity)' == '$(WindowsSDK_UnionMetadataPath)\Windows.winmd'">true</_AppContainsManagedCodeForInjection>
    </PropertyGroup>

    <PropertyGroup>
      <_NetCoreFrameworkInjectionNeeded Condition="'$(_PackagingOutputsIncludesFramework)' != 'true' and '$(_AppContainsManagedCodeForInjection)' == 'true'">true</_NetCoreFrameworkInjectionNeeded>
    </PropertyGroup>
  </Target>

  <Target Name="InjectNetCoreFrameworkBlockIfLockFileExists"
          AfterTargets="ComputeNetCoreFrameworkInjectionParameters"
          Condition="'$(_NetCoreFrameworkInjectionNeeded)' == 'true' and '$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')">
    <Error Text="One of your dependencies requires the .NET Framework, but the .NET Framework could not be found in the NuGet packages installed in this project.  Please install the appropriate .NET Framework packages required by your dependency." />
  </Target>

  <Target Name="InjectNetCoreFramework"
          AfterTargets="ComputeNetCoreFrameworkInjectionParameters"
          Condition="'$(_NetCoreFrameworkInjectionNeeded)' == 'true' and ('$(ResolveNuGetPackages)' != 'true' or !Exists('$(ProjectLockFile)'))">
    <GetReferenceAssemblyPaths TargetFrameworkMoniker="$(NuGetTargetFrameworkMonikerToInject)" Condition="'$(FrameworkInjectionLockFile)' == ''">
      <Output TaskParameter="ReferenceAssemblyPaths" ItemName="_NuGetInjectionSourceDirectories" />
    </GetReferenceAssemblyPaths>

    <PropertyGroup>
      <FrameworkInjectionLockFile Condition="'$(FrameworkInjectionLockFile)' == ''">@(_NuGetInjectionSourceDirectories->'%(Identity)\project.lock.json')</FrameworkInjectionLockFile>
      <FrameworkInjectionPackagesDirectory Condition="'$(FrameworkInjectionPackagesDirectory)' == ''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\NuGet\Repository', 'NETCoreSDK', null, RegistryView.Registry32, RegistryView.Default))</FrameworkInjectionPackagesDirectory>
    </PropertyGroup>

    <ResolveNuGetPackageAssets Condition="Exists('$(FrameworkInjectionLockFile)')"
                               NuGetPackagesDirectory="$(FrameworkInjectionPackagesDirectory)"
                               RuntimeIdentifier="$(NuGetRuntimeIdentifier)"
                               TargetMonikers="$(NuGetTargetMonikerToInject)"
                               ProjectLockFile="$(FrameworkInjectionLockFile)">

      <Output TaskParameter="ResolvedCopyLocalItems" ItemName="_InjectNetCoreFrameworkPayload" />
    </ResolveNuGetPackageAssets>

    <PropertyGroup>
      <_CoreRuntimePackageId Condition="'%(_InjectNetCoreFrameworkPayload.FileName)%(_InjectNetCoreFrameworkPayload.Extension)' == 'mscorlib.dll' OR '%(_InjectNetCoreFrameworkPayload.FileName)%(_InjectNetCoreFrameworkPayload.Extension)' == 'mscorlib.ni.dll'">%(_InjectNetCoreFrameworkPayload.NuGetPackageId)</_CoreRuntimePackageId>
    </PropertyGroup>

    <ItemGroup>
      <PackagingOutputs Include="@(_InjectNetCoreFrameworkPayload)" Condition="'%(_InjectNetCoreFrameworkPayload.NuGetPackageId)' != '$(_CoreRuntimePackageId)' or '$(UseDotNetNativeToolchain)' == 'true'">
        <TargetPath>%(Filename)%(Extension)</TargetPath>
        <ProjectName>$(ProjectName)</ProjectName>
        <OutputGroup>CopyLocalFilesOutputGroup</OutputGroup>
      </PackagingOutputs>
    </ItemGroup>
  </Target>

  <Import Project="$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuget.targets" Condition="Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuget.targets') AND '$(IncludeNuGetImports)' != 'false'" />
</Project>