2 ***********************************************************************************************
\r
3 Microsoft.NET.Sdk.DefaultItems.targets
\r
5 WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
\r
6 created a backup copy. Incorrect changes to this file will make it
\r
7 impossible to load or build your projects from the command-line or the IDE.
\r
9 Copyright (c) .NET Foundation. All rights reserved.
\r
10 ***********************************************************************************************
\r
12 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
\r
15 <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
\r
19 <EnableDefaultItems Condition=" '$(EnableDefaultItems)' == '' ">true</EnableDefaultItems>
\r
20 <EnableDefaultCompileItems Condition=" '$(EnableDefaultCompileItems)' == '' ">true</EnableDefaultCompileItems>
\r
21 <EnableDefaultEmbeddedResourceItems Condition=" '$(EnableDefaultEmbeddedResourceItems)' == '' ">true</EnableDefaultEmbeddedResourceItems>
\r
22 <EnableDefaultNoneItems Condition=" '$(EnableDefaultNoneItems)' == '' ">true</EnableDefaultNoneItems>
\r
26 <!-- Set DefaultItemExcludes property for items that should be excluded from the default Compile, etc items.
\r
27 This is in the .targets because it needs to come after the final BaseOutputPath has been evaluated. -->
\r
29 <!-- bin folder, by default -->
\r
30 <DefaultItemExcludes>$(DefaultItemExcludes);$(BaseOutputPath)/**</DefaultItemExcludes>
\r
31 <!-- obj folder, by default -->
\r
32 <DefaultItemExcludes>$(DefaultItemExcludes);$(BaseIntermediateOutputPath)/**</DefaultItemExcludes>
\r
34 <!-- Various files that should generally always be ignored -->
\r
35 <DefaultItemExcludes>$(DefaultItemExcludes);**/*.user</DefaultItemExcludes>
\r
36 <DefaultItemExcludes>$(DefaultItemExcludes);**/*.*proj</DefaultItemExcludes>
\r
37 <DefaultItemExcludes>$(DefaultItemExcludes);**/*.sln</DefaultItemExcludes>
\r
38 <DefaultItemExcludes>$(DefaultItemExcludes);**/*.vssscc</DefaultItemExcludes>
\r
40 <!-- WARNING: This pattern is there to ignore folders such as .git and .vs, but it will also match items included with a
\r
41 relative path outside the project folder (for example "..\Shared\Shared.cs"). So be sure only to apply it to items
\r
42 that are in the project folder. -->
\r
43 <DefaultExcludesInProjectFolder>$(DefaultItemExcludesInProjectFolder);**/.*/**</DefaultExcludesInProjectFolder>
\r
45 <!-- TODO: Verify why this was originally added and whether we really need it -->
\r
46 <DefaultItemExcludes>$(DefaultItemExcludes);packages/**</DefaultItemExcludes>
\r
50 <!-- Set the default versions of the NETStandard.Library or Microsoft.NETCore.App packages to reference.
\r
51 The implicit package references themselves are defined in Microsoft.NET.Sdk.props, so that they can be overridden
\r
52 in the project file. -->
\r
53 <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">
\r
54 <!-- If targeting the same release that is bundled with the .NET Core SDK, use the bundled package version provided by Microsoft.NETCoreSdk.BundledVersions.props -->
\r
55 <NETStandardImplicitPackageVersion Condition="'$(NETStandardImplicitPackageVersion)' =='' And '$(_TargetFrameworkVersionWithoutV)' == '$(BundledNETStandardTargetFrameworkVersion)'">$(BundledNETStandardPackageVersion)</NETStandardImplicitPackageVersion>
\r
57 <!-- If targeting .NET Standard 1.x, use version 1.6.1 of the package. This is so that when projects are packed, the dependency on the package produced won't change when
\r
58 updating to the 2.0 or higher SDK. When targeting .NET Standard 2.0 or higher, the NETStandard.Library reference won't show up as a dependency of the package
\r
59 produced, so we will roll forward to the latest version. -->
\r
60 <NETStandardImplicitPackageVersion Condition="'$(NETStandardImplicitPackageVersion)' =='' And '$(_TargetFrameworkVersionWithoutV)' < '2.0'">1.6.1</NETStandardImplicitPackageVersion>
\r
62 <!-- Default to use the latest stable release. Currently this is the same as the previous clause, but when we have a stable 2.0 package this should change. -->
\r
63 <NETStandardImplicitPackageVersion Condition="'$(NETStandardImplicitPackageVersion)' ==''">1.6.1</NETStandardImplicitPackageVersion>
\r
67 Determine the RuntimeFrameworkVersion when targeting .NET Core
\r
69 When targeting .NET Core, the TargetFramework is generally used to specify which version of the runtime to use.
\r
71 In order to target a specific patch version, or to float the version number (2.0-*), the RuntimeFrameworkVersion
\r
72 property can be used.
\r
74 The framework version that is written to the runtimeconfig.json file is based on the actual resolved package version
\r
75 of Microsoft.NETCore.App. This is to allow floating the verion number.
\r
77 If RuntimeFrameworkVersion is not specified, the following logic applies:
\r
79 - When targeting .NET Core 2.0 or higher, Framework-dependent apps use the target framework version with a ".0" patch version
\r
80 - When targeting .NET Core 2.0 or higher, Self-contained apps use the latest patch version (from when the SDK shipped) for
\r
81 the specified major.minor version of .NET Core
\r
82 - When targeting .NET Core 1.x, the latest patch version (from when the SDK shipped) is used for both Framework-dependent and
\r
83 Self-contained apps. This is to preserve the same behavior between 1.x and 2.0 SDKs. If we ship further patch versions
\r
84 after 1.0.5 and 1.1.2, we may choose to apply the Framework-dependent / Self-contained split to 1.x for those versions.
\r
87 <!-- These properties are mainly here as a test hook, as at the time we're implementing the logic which will choose
\r
88 different versions depending on whether an app is self-contained or not, there aren't any patch versions of
\r
89 .NET Core 2.0. So these properties allow us to apply the new behavior to .NET Core 1.x by overriding them.
\r
91 Once there is a patch version of .NET Core, we may want to remove these properties and just put the version
\r
92 numbers directly inside the <Choose> element below. -->
\r
93 <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(RuntimeFrameworkVersion)' == ''">
\r
94 <ImplicitRuntimeFrameworkVersionForFrameworkDependentNetCoreApp1_0
\r
95 Condition="'$(ImplicitRuntimeFrameworkVersionForFrameworkDependentNetCoreApp1_0)' == ''">1.0.5</ImplicitRuntimeFrameworkVersionForFrameworkDependentNetCoreApp1_0>
\r
96 <ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0
\r
97 Condition="'$(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0)' == ''">1.0.5</ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0>
\r
98 <ImplicitRuntimeFrameworkVersionForFrameworkDependentNetCoreApp1_1
\r
99 Condition="'$(ImplicitRuntimeFrameworkVersionForFrameworkDependentNetCoreApp1_1)' == ''">1.1.2</ImplicitRuntimeFrameworkVersionForFrameworkDependentNetCoreApp1_1>
\r
100 <ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1
\r
101 Condition="'$(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1)' == ''">1.1.2</ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1>
\r
104 <!-- Select implicit runtime framework versions -->
\r
106 <!-- If not targeting .NET Core, or if RuntimeFrameworkVersion is already set, do nothing -->
\r
107 <When Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' Or '$(RuntimeFrameworkVersion)' != ''" />
\r
109 <When Condition="'$(_TargetFrameworkVersionWithoutV)' == '1.0'">
\r
111 <ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>$(ImplicitRuntimeFrameworkVersionForFrameworkDependentNetCoreApp1_0)</ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>
\r
112 <ImplicitRuntimeFrameworkVersionForSelfContainedApp>$(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_0)</ImplicitRuntimeFrameworkVersionForSelfContainedApp>
\r
115 <When Condition="'$(_TargetFrameworkVersionWithoutV)' == '1.1'">
\r
117 <ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>$(ImplicitRuntimeFrameworkVersionForFrameworkDependentNetCoreApp1_1)</ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>
\r
118 <ImplicitRuntimeFrameworkVersionForSelfContainedApp>$(ImplicitRuntimeFrameworkVersionForSelfContainedNetCoreApp1_1)</ImplicitRuntimeFrameworkVersionForSelfContainedApp>
\r
122 <!-- If targeting the same release that is bundled with the .NET Core SDK, use the bundled package version provided by Microsoft.NETCoreSdk.BundledVersions.props -->
\r
123 <When Condition="'$(_TargetFrameworkVersionWithoutV)' == '$(BundledNETCoreAppTargetFrameworkVersion)'">
\r
125 <ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>$(BundledNETCoreAppPackageVersion)</ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>
\r
126 <ImplicitRuntimeFrameworkVersionForSelfContainedApp>$(BundledNETCoreAppPackageVersion)</ImplicitRuntimeFrameworkVersionForSelfContainedApp>
\r
130 <!-- If not covered by the previous cases, use the target framework version for the implicit RuntimeFrameworkVersions -->
\r
133 <ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>$(_TargetFrameworkVersionWithoutV)</ImplicitRuntimeFrameworkVersionForFrameworkDependentApp>
\r
134 <ImplicitRuntimeFrameworkVersionForSelfContainedApp>$(_TargetFrameworkVersionWithoutV)</ImplicitRuntimeFrameworkVersionForSelfContainedApp>
\r
139 <PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(RuntimeFrameworkVersion)' == ''">
\r
140 <RuntimeFrameworkVersion Condition="'$(SelfContained)' == 'true' ">$(ImplicitRuntimeFrameworkVersionForSelfContainedApp)</RuntimeFrameworkVersion>
\r
141 <RuntimeFrameworkVersion Condition="'$(SelfContained)' != 'true' ">$(ImplicitRuntimeFrameworkVersionForFrameworkDependentApp)</RuntimeFrameworkVersion>
\r
145 Automatically add Link metadata to items of specific types if they are outside of the project folder and don't already have the Link metadata set.
\r
146 This will cause them to be shown in the Solution Explorer. If an item has LinkBase metadata, the automatic Link will start with that value, and
\r
147 the items will appear in the Solution Explorer under the folder specified by LinkBase.
\r
149 <ItemGroup Condition="'$(SetLinkMetadataAutomatically)' != 'false'">
\r
150 <Compile Update="@(Compile)">
\r
151 <!-- First, add a trailing slash to the LinkBase metadata if necessary. This allows us to use the same value
\r
152 for the Link metadata whether or not LinkBase metadata is set: %(LinkBase)%(RecursiveDir)%(Filename)%(Extension)
\r
154 Note that RecursiveDir already includes the trailing slash.
\r
156 <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
\r
158 <!-- Set the Link metadata if it's not already set and the item is outside of the project directory.
\r
159 Check whether an item is inside the project directory by seeing if the FullPath starts with EnuserTrailingSlash(MSBuildProjectDirectory)
\r
160 The FullPath and the MSBuildProjectDirectory will both already be normalized full paths.
\r
161 The call to [MSBuild]::ValueOrDefault() is there in order to allow calling StartsWith on the FullPath value, since it's
\r
162 not possible to call a string method on a metadata item directly. The intrinsic ValueOrDefault() will be more
\r
163 performant than calling String.Copy(), which has been used for this in other contexts, but actually makes a copy
\r
164 of the string data.
\r
166 <Link Condition="'%(Link)' == '' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
\r
169 <AdditionalFiles Update="@(AdditionalFiles)">
\r
170 <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
\r
171 <Link Condition="'%(Link)' == '' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
\r
174 <None Update="@(None)">
\r
175 <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
\r
176 <Link Condition="'%(Link)' == '' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
\r
179 <Content Update="@(Content)">
\r
180 <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
\r
181 <Link Condition="'%(Link)' == '' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
\r
184 <EmbeddedResource Update="@(EmbeddedResource)">
\r
185 <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
\r
186 <Link Condition="'%(Link)' == '' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
\r
187 </EmbeddedResource>
\r
190 <UsingTask TaskName="CheckForImplicitPackageReferenceOverrides" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
\r
192 <!-- Remove package references with metadata IsImplicitlyDefined = true, if there are other PackageReference items with the same identity -->
\r
193 <Target Name="CheckForImplicitPackageReferenceOverrides" BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CollectPackageReferences">
\r
195 <ImplicitPackageReferenceInformationLink>https://aka.ms/sdkimplicitrefs</ImplicitPackageReferenceInformationLink>
\r
198 <CheckForImplicitPackageReferenceOverrides
\r
199 PackageReferenceItems="@(PackageReference)"
\r
200 MoreInformationLink="$(ImplicitPackageReferenceInformationLink)">
\r
201 <Output TaskParameter="ItemsToRemove" ItemName="_PackageReferenceToRemove" />
\r
202 </CheckForImplicitPackageReferenceOverrides>
\r
205 <!-- Note that the condition here is important, otherwise the Remove will operate based just on item identity and remove all items
\r
206 that had duplicates, instead of leaving the ones without IsImplicitlyDefined set to true. -->
\r
207 <PackageReference Remove="@(_PackageReferenceToRemove)" Condition="'%(PackageReference.IsImplicitlyDefined)' == 'true' "/>
\r
212 <!-- Running an SDK task before the NuGet restore task causes issues when running on .NET Framework because it causes the
\r
213 .NET Standard NuGet DLLs to be loaded from the SDK path rather than the .NET Framework versions from the NuGet targets
\r
214 path. To avoid this, we create a separate target to run before NuGet restore which deduplicates the items without
\r
215 causing the SDK tasks to be loaded (but doesn't generate a warning message, because we need to load the tasks for that). -->
\r
216 <PropertyGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true'">
\r
217 <_ImplicitPackageName Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">NETStandard.Library</_ImplicitPackageName>
\r
218 <_ImplicitPackageName Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">Microsoft.NETCore.App</_ImplicitPackageName>
\r
221 <ItemGroup Condition="'$(_ImplicitPackageName)' != ''">
\r
222 <!-- Filter PackageReference to items where the ItemSpec matches the implicit package name, and add IsImplicitlyDefined metadata
\r
223 for items that don't have it-->
\r
224 <_ImplicitPackageReferenceCheck
\r
225 Include="@(PackageReference->WithMetadataValue('Identity', '$(_ImplicitPackageName)'))">
\r
226 <IsImplicitlyDefined Condition="'%(IsImplicitlyDefined)' != 'true' ">false</IsImplicitlyDefined>
\r
227 </_ImplicitPackageReferenceCheck>
\r
229 <!-- Now filter down to an item with just the implicit reference and another one with just the overriding reference -->
\r
230 <_ImplicitPackageReference Include="@(_ImplicitPackageReferenceCheck->WithMetadataValue('IsImplicitlyDefined', 'true'))"/>
\r
231 <_OverridingPackageReference Include="@(_ImplicitPackageReferenceCheck->WithMetadataValue('IsImplicitlyDefined', 'false'))"/>
\r
234 <Target Name="CheckForImplicitPackageReferenceOverridesBeforeRestore" BeforeTargets="_GetRestoreProjectStyle">
\r
236 <!-- Remove both the implicit and the override item, if there was both an implicit and an override item -->
\r
237 <PackageReference Remove="@(PackageReference->WithMetadataValue('Identity', '$(_ImplicitPackageName)'))"
\r
238 Condition="'@(_ImplicitPackageReference)' != '' And '@(_OverridingPackageReference)' != ''"
\r
241 <!-- Add the override item back -->
\r
242 <PackageReference Include="@(_OverridingPackageReference)"
\r
243 Condition="'@(_ImplicitPackageReference)' != '' And '@(_OverridingPackageReference)' != ''" />
\r
247 <UsingTask TaskName="CheckForDuplicateItems" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
\r
249 <Target Name="CheckForDuplicateItems" BeforeTargets="_CheckForInvalidConfigurationAndPlatform;CoreCompile">
\r
252 <DefaultItemsMoreInformationLink>https://aka.ms/sdkimplicititems</DefaultItemsMoreInformationLink>
\r
254 <!-- For the design-time build, we will continue on error and remove the duplicate items.
\r
255 This is because otherwise there won't be any references to pass to the compiler, leading to design-time
\r
256 compilation errors for every API that is used in the project. Amidst all the compile errors, it would
\r
257 be easy to miss the duplicate items error which is the real source of the problem. -->
\r
258 <CheckForDuplicateItemsContinueOnError>false</CheckForDuplicateItemsContinueOnError>
\r
259 <CheckForDuplicateItemsContinueOnError Condition="'$(DesignTimeBuild)' == 'true'">ErrorAndContinue</CheckForDuplicateItemsContinueOnError>
\r
262 <CheckForDuplicateItems
\r
265 DefaultItemsEnabled="$(EnableDefaultItems)"
\r
266 DefaultItemsOfThisTypeEnabled="$(EnableDefaultCompileItems)"
\r
267 PropertyNameToDisableDefaultItems="EnableDefaultCompileItems"
\r
268 MoreInformationLink="$(DefaultItemsMoreInformationLink)"
\r
269 ContinueOnError="$(CheckForDuplicateItemsContinueOnError)">
\r
270 <Output TaskParameter="DeduplicatedItems" ItemName="DeduplicatedCompileItems" />
\r
271 </CheckForDuplicateItems>
\r
273 <CheckForDuplicateItems
\r
274 Items="@(EmbeddedResource)"
\r
275 ItemName="EmbeddedResource"
\r
276 DefaultItemsEnabled="$(EnableDefaultItems)"
\r
277 DefaultItemsOfThisTypeEnabled="$(EnableDefaultEmbeddedResourceItems)"
\r
278 PropertyNameToDisableDefaultItems="EnableDefaultEmbeddedResourceItems"
\r
279 MoreInformationLink="$(DefaultItemsMoreInformationLink)"
\r
280 ContinueOnError="$(CheckForDuplicateItemsContinueOnError)">
\r
281 <Output TaskParameter="DeduplicatedItems" ItemName="DeduplicatedEmbeddedResourceItems" />
\r
282 </CheckForDuplicateItems>
\r
284 <!-- Default content items are enabled by the Web SDK, not the .NET SDK, but we check it here for simplicity -->
\r
285 <CheckForDuplicateItems
\r
288 DefaultItemsEnabled="$(EnableDefaultItems)"
\r
289 DefaultItemsOfThisTypeEnabled="$(EnableDefaultContentItems)"
\r
290 PropertyNameToDisableDefaultItems="EnableDefaultContentItems"
\r
291 MoreInformationLink="$(DefaultItemsMoreInformationLink)"
\r
292 ContinueOnError="$(CheckForDuplicateItemsContinueOnError)">
\r
293 <Output TaskParameter="DeduplicatedItems" ItemName="DeduplicatedContentItems" />
\r
294 </CheckForDuplicateItems>
\r
296 <ItemGroup Condition="'$(DesignTimeBuild)' == 'true' And '@(DeduplicatedCompileItems)' != ''">
\r
297 <Compile Remove="@(Compile)" />
\r
298 <Compile Include="@(DeduplicatedCompileItems)" />
\r
301 <ItemGroup Condition="'$(DesignTimeBuild)' == 'true' And '@(DeduplicatedEmbeddedResourceItems)' != ''">
\r
302 <EmbeddedResource Remove="@(EmbeddedResource)" />
\r
303 <EmbeddedResource Include="@(DeduplicatedEmbeddedResourceItems)" />
\r
306 <ItemGroup Condition="'$(DesignTimeBuild)' == 'true' And '@(DeduplicatedContentItems)' != ''">
\r
307 <Content Remove="@(Content)" />
\r
308 <Content Include="@(DeduplicatedContentItems)" />
\r