2 ***********************************************************************************************
3 Microsoft.NuGet.targets
5 WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
6 created a backup copy. Incorrect changes to this file will make it
7 impossible to load or build your projects from the command-line or the IDE.
9 Copyright (c) .NET Foundation. All rights reserved.
10 ***********************************************************************************************
12 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
13 <UsingTask TaskName="Microsoft.NuGet.Build.Tasks.ResolveNuGetPackageAssets" AssemblyFile="Microsoft.NuGet.Build.Tasks.dll" />
15 <PropertyGroup Condition="'$(ProjectLockFile)' == ''">
16 <_ProjectSpecificProjectJsonFile>$(MSBuildProjectName).project.json</_ProjectSpecificProjectJsonFile>
17 <ProjectLockFile Condition="Exists('$(_ProjectSpecificProjectJsonFile)')">$(MSBuildProjectName).project.lock.json</ProjectLockFile>
18 <ProjectLockFile Condition="!Exists('$(_ProjectSpecificProjectJsonFile)')">project.lock.json</ProjectLockFile>
22 <ResolveNuGetPackages Condition="'$(ResolveNuGetPackages)' == '' and '$(MSBuildProjectExtension)' != '.xproj'">true</ResolveNuGetPackages>
24 <BaseNuGetRuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' == '' and '$(TargetPlatformIdentifier)' == 'UAP'">win10</BaseNuGetRuntimeIdentifier>
25 <BaseNuGetRuntimeIdentifier Condition="'$(BaseNuGetRuntimeIdentifier)' == ''">win</BaseNuGetRuntimeIdentifier>
27 <UseTargetPlatformAsNuGetTargetMoniker Condition="'$(UseTargetPlatformAsNuGetTargetMoniker)' == '' AND '$(TargetFrameworkMoniker)' == '.NETCore,Version=v5.0'">true</UseTargetPlatformAsNuGetTargetMoniker>
28 <NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == '' AND '$(UseTargetPlatformAsNuGetTargetMoniker)' == 'true'">$(TargetPlatformIdentifier),Version=v$([System.Version]::Parse('$(TargetPlatformMinVersion)').ToString(3))</NuGetTargetMoniker>
29 <NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == '' AND '$(UseTargetPlatformAsNuGetTargetMoniker)' != 'true'">$(TargetFrameworkMoniker)</NuGetTargetMoniker>
31 <CopyNuGetImplementations Condition="'$(CopyNuGetImplementations)' == '' and (('$(OutputType)' != 'library' and ('$(OutputType)' != 'winmdobj' or '$(AppxPackage)' == 'true')) or '$(TargetFrameworkIdentifier)' == '.NETFramework')">true</CopyNuGetImplementations>
32 <IncludeFrameworkReferencesFromNuGet Condition="'$(IncludeFrameworkReferencesFromNuGet)' == ''">true</IncludeFrameworkReferencesFromNuGet>
34 <_NuGetRuntimeIdentifierPlatformTargetSuffix Condition="'$(PlatformTarget)' != '' and '$(PlatformTarget)' != 'AnyCPU'">-$(PlatformTarget.ToLower())</_NuGetRuntimeIdentifierPlatformTargetSuffix>
35 <_NuGetRuntimeIdentifierWithoutAot>$(BaseNuGetRuntimeIdentifier)$(_NuGetRuntimeIdentifierPlatformTargetSuffix)</_NuGetRuntimeIdentifierWithoutAot>
38 <!-- If a NuGetRuntimeIdentifier wasn't already specified, let's go generate it -->
39 <PropertyGroup Condition="'$(NuGetRuntimeIdentifier)' == '' and '$(CopyNuGetImplementations)' == 'true'">
40 <NuGetRuntimeIdentifier>$(_NuGetRuntimeIdentifierWithoutAot)</NuGetRuntimeIdentifier>
41 <NuGetRuntimeIdentifier Condition="'$(UseDotNetNativeToolchain)' == 'true'">$(_NuGetRuntimeIdentifierWithoutAot)-aot</NuGetRuntimeIdentifier>
45 <!-- If we are resolving from project.lock.json, we need to consider any edit to it as something that forces a rebuild -->
46 <CustomAdditionalCompileInputs Include="$(ProjectLockFile)" Condition="'$(ResolveNuGetPackages)' == 'true' and Exists('$(ProjectLockFile)')" />
49 <PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'UAP'">
50 <_NuGetTargetFallbackMoniker>UAP,Version=v10.0</_NuGetTargetFallbackMoniker>
51 <ImplicitlyExpandTargetFramework>false</ImplicitlyExpandTargetFramework>
52 <EnableAppLocalFXWorkaround>false</EnableAppLocalFXWorkaround>
53 <UseNetNativeCustomFramework>true</UseNetNativeCustomFramework>
57 ============================================================
58 GetProjectsReferencingProjectJsonFiles
59 ============================================================
61 <Target Name="GetProjectsReferencingProjectJson" DependsOnTargets="_SplitProjectReferencesByFileExistence" Returns="@(_ProjectReferencingProjectJsonFile)">
62 <ItemGroup Condition="'$(ResolveNuGetPackages)' == 'true'">
63 <_ProjectReferencingProjectJsonFile Include="$(MSBuildProjectFullPath)">
64 <ProjectReferences>@(ProjectReference)</ProjectReferences>
65 <ProjectJson>$(MSBuildProjectDirectory)\project.json</ProjectJson>
66 </_ProjectReferencingProjectJsonFile>
70 Projects="@(_MSBuildProjectReferenceExistent)"
71 Targets="GetProjectsReferencingProjectJson"
72 BuildInParallel="$(BuildInParallel)"
73 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
74 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
76 <Output TaskParameter="TargetOutputs" ItemName="_ProjectReferencingProjectJsonFile" />
81 <NuGetPreprocessorValue Include="rootnamespace">
82 <Value>$(RootNamespace)</Value>
83 </NuGetPreprocessorValue>
84 <NuGetPreprocessorValue Include="assemblyname">
85 <Value>$(AssemblyName)</Value>
86 </NuGetPreprocessorValue>
87 <NuGetPreprocessorValue Include="fullpath">
88 <Value>$(MSBuildProjectDirectory)</Value>
89 </NuGetPreprocessorValue>
90 <NuGetPreprocessorValue Include="outputfilename">
91 <Value>$(TargetFileName)</Value>
92 </NuGetPreprocessorValue>
93 <NuGetPreprocessorValue Include="filename">
94 <Value>$(MSBuildProjectFile)</Value>
95 </NuGetPreprocessorValue>
99 ============================================================
100 ResolveNuGetPackageAssets
102 Resolve assets from consumed NuGet packages listed in the project.lock.json
105 @(Analyzer) - Paths to build-time diagnostic analyzers
106 @(Reference) - Paths to build-time NuGet dependencies
107 @(ReferenceCopyLocalPaths) - Paths to run-time dependencies to copy
108 ============================================================
111 <ResolveAssemblyReferencesDependsOn>$(ResolveAssemblyReferencesDependsOn);ResolveNuGetPackageAssets</ResolveAssemblyReferencesDependsOn>
112 <PrepareResourcesDependsOn>ResolveNuGetPackageAssets;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
116 <ResolveNuGetPackageAssetsDependsOn>ResolveProjectReferences</ResolveNuGetPackageAssetsDependsOn>
117 <ResolveNuGetPackageAssetsDependsOn Condition="'$(ImplicitlyExpandTargetFramework)' == 'true'">$(ResolveNuGetPackageAssetsDependsOn);ImplicitlyExpandTargetFramework</ResolveNuGetPackageAssetsDependsOn>
120 <Target Name="ResolveNuGetPackageAssets" DependsOnTargets="$(ResolveNuGetPackageAssetsDependsOn)" Condition="'$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')">
121 <!-- We need to figure out the output path of any dependent xproj projects -->
123 Projects="@(_MSBuildProjectReferenceExistent)"
124 Targets="GetTargetDir"
125 BuildInParallel="$(BuildInParallel)"
126 Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
127 RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)"
128 Condition="'%(_MSBuildProjectReferenceExistent.Extension)' == '.xproj'">
130 <Output TaskParameter="TargetOutputs" ItemName="_XProjTargetDirs" />
133 <!-- The items in _XProjTargetDirs have the target directories as the main itemspecs and the originating project as metadata; reverse them -->
135 <ProjectReferenceCreatingPackage Include="%(_XProjTargetDirs.OriginalItemSpec)">
136 <OutputBasePath>%(_XProjTargetDirs.Identity)</OutputBasePath>
137 </ProjectReferenceCreatingPackage>
140 <ResolveNuGetPackageAssets AllowFallbackOnTargetSelection="$(DesignTimeBuild)"
141 ContinueOnError="$(ContinueOnError)"
142 IncludeFrameworkReferences="$(IncludeFrameworkReferencesFromNuGet)"
143 NuGetPackagesDirectory="$(NuGetPackagesDirectory)"
144 RuntimeIdentifier="$(NuGetRuntimeIdentifier)"
145 ProjectLanguage="$(Language)"
146 ProjectLockFile="$(ProjectLockFile)"
147 ProjectReferencesCreatingPackages="@(ProjectReferenceCreatingPackage)"
148 ContentPreprocessorValues="@(NuGetPreprocessorValue)"
149 ContentPreprocessorOutputDirectory="$(IntermediateOutputPath)\NuGet"
150 TargetMonikers="$(NuGetTargetMoniker);$(_NuGetTargetFallbackMoniker)">
152 <Output TaskParameter="ResolvedAnalyzers" ItemName="Analyzer" />
153 <Output TaskParameter="ResolvedCopyLocalItems" ItemName="ReferenceCopyLocalPaths" />
154 <Output TaskParameter="ResolvedReferences" ItemName="_ReferencesFromNuGetPackages" />
155 <Output TaskParameter="ReferencedPackages" ItemName="ReferencedNuGetPackages" />
156 <Output TaskParameter="ContentItems" ItemName="_NuGetContentItems" />
157 <Output TaskParameter="FileWrites" ItemName="FileWrites" />
158 </ResolveNuGetPackageAssets>
161 <!-- Remove exact references, such as if a package had a framework reference to 'System' that we already have -->
162 <Reference Remove="@(_ReferencesFromNuGetPackages)" />
164 <!-- Remove simple name references that are already implicitly added -->
165 <_ReferencesFromNuGetPackages Remove="%(ReferencePath.FileName)" Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'" />
167 <!-- Include NuGet references in the proper groups. Project-to-project references must go in the
168 _ResolvedProjectReferencePaths group which matches the behavior of the ResolveProjectReferences
169 target. This ensures that even if the assembly is missing on disk, it still makes it to the compiler. -->
170 <Reference Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' != 'Project'" />
171 <_ResolvedProjectReferencePaths Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' == 'Project'" />
173 <!-- Remove simple name references if we're directly providing a reference assembly to the compiler. For example,
174 consider a project with an Reference Include="System", and some NuGet package is providing System.dll -->
175 <Reference Remove="%(_ReferencesFromNuGetPackages.FileName)" Condition="'%(_ReferencesFromNuGetPackages.NuGetIsFrameworkReference)' == 'false'"/>
178 <PropertyGroup Condition=" '$(AutoUnifyAssemblyReferences)' == 'true' ">
179 <!-- Normally Design Time Assembly Resolution (DTAR) won't consider these references.
180 Put DTAR in a mode where it will prefer the output of RAR and unify. -->
181 <DTARUseReferencesFromProject>true</DTARUseReferencesFromProject>
184 <!-- The items in _NuGetContentItems need to go into the appropriately-named item group, but the names depend upon the items
185 themselves. Split it apart. -->
186 <CreateItem Include="@(_NuGetContentItems)" Condition="'@(_NuGetContentItems)' != ''">
187 <Output TaskParameter="Include" ItemName="%(_NuGetContentItems.NuGetItemType)" />
191 <Target Name="RuntimeImplementationProjectOutputGroup" Returns="@(RuntimeImplementationProjectOutputGroupOutput)" Condition="'$(ResolveNuGetPackages)' == 'true' and exists('$(ProjectLockFile)')">
192 <!-- This output group must contain the implementation assemblies for the host (i.e. design time) environment, not the
193 target environment. Thus, we explicitly pass the RuntimeIdentifier that doesn't have the -aot suffix -->
194 <ResolveNuGetPackageAssets AllowFallbackOnTargetSelection="$(DesignTimeBuild)"
195 NuGetPackagesDirectory="$(NuGetPackagesDirectory)"
196 RuntimeIdentifier="$(_NuGetRuntimeIdentifierWithoutAot)"
197 ProjectLanguage="$(Language)"
198 ProjectLockFile="$(ProjectLockFile)"
199 TargetMonikers="$(NuGetTargetMoniker);$(_NuGetTargetFallbackMoniker)">
201 <Output TaskParameter="ResolvedCopyLocalItems" ItemName="NonAheadOfTimeRuntimeImplementations" />
202 </ResolveNuGetPackageAssets>
205 <RuntimeImplementationProjectOutputGroupOutput Include="%(NonAheadOfTimeRuntimeImplementations.Identity)">
206 <FinalOutputPath>%(NonAheadOfTimeRuntimeImplementations.FullPath)</FinalOutputPath>
207 <TargetPath>%(NonAheadOfTimeRuntimeImplementations.FullPath)</TargetPath>
208 </RuntimeImplementationProjectOutputGroupOutput>
213 ============================================================
214 Framework injection into mixed-target applications
215 ============================================================
218 <NuGetTargetFrameworkMonikerToInject Condition="'$(NuGetTargetFrameworkMonikerToInject)' == ''">.NETCore,Version=v5.0</NuGetTargetFrameworkMonikerToInject>
219 <NuGetTargetMonikerToInject Condition="'$(NuGetTargetMonikerToInject)' == ''">.NETCore,Version=v5.0</NuGetTargetMonikerToInject>
220 <_ComputeNetCoreFrameworkInjectionParametersBeforeTargets Condition="'$(AppxPackage)' == 'true' and '$(TargetPlatformIdentifier)' == 'UAP'">BeforeGenerateProjectPriFile</_ComputeNetCoreFrameworkInjectionParametersBeforeTargets>
223 <Target Name="ComputeNetCoreFrameworkInjectionParameters" BeforeTargets="$(_ComputeNetCoreFrameworkInjectionParametersBeforeTargets)" DependsOnTargets="_AddUnionWinmd" Condition="'$(_ComputeNetCoreFrameworkInjectionParametersBeforeTargets)' != ''">
225 <_PackagingOutputsIncludesFramework Condition="'%(PackagingOutputs.FileName)%(PackagingOutputs.Extension)' == 'System.Runtime.dll'">true</_PackagingOutputsIncludesFramework>
226 <_AppContainsManagedCodeForInjection Condition="'%(PackagingOutputs.Identity)' == '$(_TargetPlatformSdkDir)UnionMetadata\Windows.winmd'">true</_AppContainsManagedCodeForInjection>
230 <_NetCoreFrameworkInjectionNeeded Condition="'$(_PackagingOutputsIncludesFramework)' != 'true' and '$(_AppContainsManagedCodeForInjection)' == 'true'">true</_NetCoreFrameworkInjectionNeeded>
234 <Target Name="InjectNetCoreFrameworkBlockIfLockFileExists" AfterTargets="ComputeNetCoreFrameworkInjectionParameters" Condition="'$(_NetCoreFrameworkInjectionNeeded)' == 'true' and '$(ResolveNuGetPackages)' == 'true' and Exists('$(ProjectLockFile)')">
235 <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." />
238 <Target Name="InjectNetCoreFramework" AfterTargets="ComputeNetCoreFrameworkInjectionParameters" Condition="'$(_NetCoreFrameworkInjectionNeeded)' == 'true' and ('$(ResolveNuGetPackages)' != 'true' or !Exists('$(ProjectLockFile)'))">
239 <GetReferenceAssemblyPaths TargetFrameworkMoniker="$(NuGetTargetFrameworkMonikerToInject)" Condition="'$(FrameworkInjectionLockFile)' == ''">
240 <Output TaskParameter="ReferenceAssemblyPaths" ItemName="_NuGetInjectionSourceDirectories" />
241 </GetReferenceAssemblyPaths>
244 <FrameworkInjectionLockFile Condition="'$(FrameworkInjectionLockFile)' == ''">@(_NuGetInjectionSourceDirectories->'%(Identity)\project.lock.json')</FrameworkInjectionLockFile>
245 <FrameworkInjectionPackagesDirectory Condition="'$(FrameworkInjectionPackagesDirectory)' == ''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\NuGet\Repository', 'NETCoreSDK', null, RegistryView.Registry32, RegistryView.Default))</FrameworkInjectionPackagesDirectory>
248 <ResolveNuGetPackageAssets Condition="Exists('$(FrameworkInjectionLockFile)')"
249 NuGetPackagesDirectory="$(FrameworkInjectionPackagesDirectory)"
250 RuntimeIdentifier="$(NuGetRuntimeIdentifier)"
251 TargetMonikers="$(NuGetTargetMonikerToInject)"
252 ProjectLockFile="$(FrameworkInjectionLockFile)">
254 <Output TaskParameter="ResolvedCopyLocalItems" ItemName="_InjectNetCoreFrameworkPayload" />
255 </ResolveNuGetPackageAssets>
258 <_CoreRuntimePackageId Condition="'%(_InjectNetCoreFrameworkPayload.FileName)%(_InjectNetCoreFrameworkPayload.Extension)' == 'mscorlib.dll' OR '%(_InjectNetCoreFrameworkPayload.FileName)%(_InjectNetCoreFrameworkPayload.Extension)' == 'mscorlib.ni.dll'">%(_InjectNetCoreFrameworkPayload.NuGetPackageId)</_CoreRuntimePackageId>
262 <PackagingOutputs Include="@(_InjectNetCoreFrameworkPayload)" Condition="'%(_InjectNetCoreFrameworkPayload.NuGetPackageId)' != '$(_CoreRuntimePackageId)' or '$(UseDotNetNativeToolchain)' == 'true'">
263 <TargetPath>%(Filename)%(Extension)</TargetPath>
264 <ProjectName>$(ProjectName)</ProjectName>
265 <OutputGroup>CopyLocalFilesOutputGroup</OutputGroup>
270 <Import Project="$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuget.targets" Condition="Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuget.targets') AND '$(IncludeNuGetImports)' != 'false'" />