/
Microsoft.NET.Sdk.DefaultItems.targets
168 lines (141 loc) · 12 KB
/
Microsoft.NET.Sdk.DefaultItems.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
<!--
***********************************************************************************************
Microsoft.NET.Sdk.DefaultItems.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">
<!-- Don't get the default item globs by default when the flag is not set. -->
<PropertyGroup Condition="'$(UsingNETSdkDefaults)' == 'true'">
<EnableDefaultItems Condition=" '$(EnableDefaultItems)' == '' ">true</EnableDefaultItems>
<EnableDefaultCompileItems Condition=" '$(EnableDefaultCompileItems)' == '' ">true</EnableDefaultCompileItems>
<EnableDefaultEmbeddedResourceItems Condition=" '$(EnableDefaultEmbeddedResourceItems)' == '' ">true</EnableDefaultEmbeddedResourceItems>
<EnableDefaultNoneItems Condition=" '$(EnableDefaultNoneItems)' == '' ">true</EnableDefaultNoneItems>
</PropertyGroup>
<PropertyGroup>
<!-- Set DefaultItemExcludes property for items that should be excluded from the default Compile, etc items.
This is in the .targets because it needs to come after the final BaseOutputPath has been evaluated. -->
<!-- bin folder, by default -->
<DefaultItemExcludes>$(DefaultItemExcludes);$(BaseOutputPath)/**</DefaultItemExcludes>
<!-- obj folder, by default -->
<DefaultItemExcludes>$(DefaultItemExcludes);$(BaseIntermediateOutputPath)/**</DefaultItemExcludes>
<!-- Various files that should generally always be ignored -->
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.user</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.*proj</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.sln</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.vssscc</DefaultItemExcludes>
<DefaultItemExcludes>$(DefaultItemExcludes);**/.DS_Store</DefaultItemExcludes>
<!-- WARNING: This pattern is there to ignore folders such as .git and .vs, but it will also match items included with a
relative path outside the project folder (for example "..\Shared\Shared.cs"). So be sure only to apply it to items
that are in the project folder. Support both DefaultItemExcludesInProjectFolder and DefaultExcludesInProjectFolder
properties because of a naming mistake. -->
<DefaultExcludesInProjectFolder>$(DefaultExcludesInProjectFolder);$(DefaultItemExcludesInProjectFolder);**/.*/**</DefaultExcludesInProjectFolder>
</PropertyGroup>
<!-- Set the default versions of the NETStandard.Library or Microsoft.NETCore.App packages to reference.
The implicit package references themselves are defined in Microsoft.NET.Sdk.props, so that they can be overridden
in the project file. -->
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard' And '$(_TargetFrameworkVersionWithoutV)' < '2.1'">
<!-- 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
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
produced, so we will roll forward to the latest version. -->
<NETStandardImplicitPackageVersion Condition="'$(NETStandardImplicitPackageVersion)' =='' And '$(_TargetFrameworkVersionWithoutV)' < '2.0'">1.6.1</NETStandardImplicitPackageVersion>
<!-- Default to use the latest stable 2.0.x release. -->
<NETStandardImplicitPackageVersion Condition="'$(NETStandardImplicitPackageVersion)' ==''">2.0.3</NETStandardImplicitPackageVersion>
</PropertyGroup>
<Import Project="Microsoft.NET.Sdk.DefaultItems.Shared.targets" />
<!-- This target runs before build but not before restore, to avoid duplicating these warnings
if building with an implicit restore. -->
<Target Name="WarnForExplicitVersions" BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
DependsOnTargets="ApplyImplicitVersions"
Condition="'@(SdkBuildWarning)' != ''">
<NetSdkWarning FormattedText="%(SdkBuildWarning.Identity)" />
</Target>
<!--
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.
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
the items will appear in the Solution Explorer under the folder specified by LinkBase.
-->
<ItemGroup Condition="'$(SetLinkMetadataAutomatically)' != 'false'">
<Compile Update="@(Compile)">
<!-- First, add a trailing slash to the LinkBase metadata if necessary. This allows us to use the same value
for the Link metadata whether or not LinkBase metadata is set: %(LinkBase)%(RecursiveDir)%(Filename)%(Extension)
Note that RecursiveDir already includes the trailing slash.
-->
<LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
<!-- Set the Link metadata if it's not already set, if the item wasn't defined in a shared project, and the item is outside of the project directory.
Check whether the item was defined in a shared project by checking whether the extension of the defining project was .projitems.
Check whether an item is inside the project directory by seeing if the FullPath starts with EnsureTrailingSlash(MSBuildProjectDirectory)
The FullPath and the MSBuildProjectDirectory will both already be normalized full paths.
The call to [MSBuild]::ValueOrDefault() is there in order to allow calling StartsWith on the FullPath value, since it's
not possible to call a string method on a metadata item directly. The intrinsic ValueOrDefault() will be more
performant than calling String.Copy(), which has been used for this in other contexts, but actually makes a copy
of the string data.
-->
<Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
</Compile>
<AdditionalFiles Update="@(AdditionalFiles)">
<LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
<Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
</AdditionalFiles>
<None Update="@(None)">
<LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
<Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
</None>
<Content Update="@(Content)">
<LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
<Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
</Content>
<EmbeddedResource Update="@(EmbeddedResource)">
<LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
<Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
</EmbeddedResource>
<Page Update="@(Page)">
<LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
<Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
</Page>
<Resource Update="@(Resource)">
<LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase>
<Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link>
</Resource>
</ItemGroup>
<Target Name="_CheckForFailedSDKResolution"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Condition="'$(SdkResolverHonoredGlobalJson)' == 'false'">
<NetSdkError ResourceName="GlobalJsonSDKResolutionFailed"
FormatArguments="$(SdkResolverGlobalJsonPath)" />
</Target>
<Target Name="_WarnWhenUsingNET8AndVSPriorTo178"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Condition="$([MSBuild]::VersionLessThan($(MSBuildVersion), '17.8.0')) and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '8.0'))">
<NetSdkWarning ResourceName="Net8NotCompatibleWithDev177"/>
</Target>
<Target Name="_CheckForInvalidWindowsDesktopTargetingConfiguration"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '5.0')) and ('$(UseWindowsForms)' == 'true' or '$(UseWPF)' == 'true')">
<NETSdkError Condition="'$(TargetPlatformIdentifier)' != 'Windows'"
ResourceName="WindowsDesktopTargetPlatformMustBeWindows" />
</Target>
<Target Name="_CheckForUnnecessaryWindowsDesktopSDK"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(_TargetFrameworkVersionWithoutV), '5.0')) and '$(_MicrosoftWindowsDesktopSdkImported)' == 'true' and '$(TargetFrameworks)' == ''">
<NETSdkWarning ResourceName="UnnecessaryWindowsDesktopSDK" />
</Target>
<!-- Default the value of PublishRelease for 8.0+ TFMs. Note that this is pre-evaluated by the CLI in an evaluation before evaluation (see ReleasePropertyProjectLocator.cs).-->
<PropertyGroup Condition="'$(PublishRelease)' == '' and '$(_TargetFrameworkVersionWithoutV)' >= '8.0'">
<PublishRelease>true</PublishRelease>
</PropertyGroup>
<!-- This verifies that the configuration between projects in a solution set by PackRelease agree.
PackRelease only affects the CLI since VS has its own Configuration UI and it's not possible to detect like this in MSBuild.
_IsPacking will only be set if packing in the CLI, so that's fine here. The pack targets are all outside of the SDK, which is why this is here.-->
<Target Name="_VerifyPackReleaseConfigurations"
BeforeTargets="PrepareForBuild"
Condition="'$(_IsPacking)' == 'true' and '$(DOTNET_CLI_DISABLE_PUBLISH_AND_PACK_RELEASE)' != 'true' and '$(DOTNET_CLI_LAZY_PUBLISH_AND_PACK_RELEASE_FOR_SOLUTIONS)' == 'true'">
<NETSdkError Condition="'$(SolutionExt)' == '.sln' and
'$(_SolutionLevelPackRelease)' != '$(PackRelease)'"
ResourceName="SolutionProjectConfigurationsConflict"
FormatArguments="PackRelease;$(ProjectName)"/>
</Target>
</Project>