-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
133 lines (114 loc) · 8.34 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
133 lines (114 loc) · 8.34 KB
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
<Project>
<ItemGroup>
<!-- Usually, GenerateSource="true" is enough for Arcade to do the generation. -->
<!-- However, MSBuild.Sdk.Extras can break us by explicitly setting Generator metadata -->
<!-- https://github.com/novotnyllc/MSBuildSdkExtras/blob/b58e1d25b530e02ce4d1b937ccf99082019cdc47/Source/MSBuild.Sdk.Extras/DefaultItems/Platforms/Common.props#L13-L21 -->
<EmbeddedResource Update="**\*.resx" GenerateSource="true" Generator="MSBuild:_GenerateResxSource" />
</ItemGroup>
<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
<!-- Pack config -->
<PropertyGroup>
<PackageTags Condition=" '$(PackageTags)' == '' ">$(CommonPackageTags)</PackageTags>
<PackageReadmeFile Condition=" '$(PackageReadmeFile)' == '' and Exists('PACKAGE.md') ">PACKAGE.md</PackageReadmeFile>
</PropertyGroup>
<!--
NuGet's Pack.targets is imported after Microsoft.Common.targets, and therefore after this file. It fills an
unset $(PackageDescription) from $(Description) and, failing that, from its own "Package Description"
literal. Record here, while the value is still exactly what the repository authored, whether a description
was supplied at all, so that the guard below does not have to rely solely on recognizing that literal.
$(Description) counts as authored because NuGet promotes it to $(PackageDescription).
-->
<PropertyGroup>
<_HasAuthoredPackageDescription Condition=" '$(PackageDescription)' != '' or '$(Description)' != '' ">true</_HasAuthoredPackageDescription>
</PropertyGroup>
<!-- Pack the package README (PACKAGE.md by default, see above) into the root of the .nupkg. -->
<ItemGroup Condition=" '$(PackageReadmeFile)' != '' ">
<None Include="$(PackageReadmeFile)" Pack="true" PackagePath="\" />
</ItemGroup>
<!--
Guard the nuget.org metadata that is easy to forget on a new package.
NuGet's Pack.targets defaults an unset $(PackageDescription) to the literal string
"Package Description" during evaluation, so Arcade's own "PackageDescription must be specified"
check (a target, and therefore evaluated later) can never fire and the placeholder ships. Three
packages reached nuget.org that way before this guard existed. $(_HasAuthoredPackageDescription),
captured above before NuGet's default is applied, is the primary signal; the placeholder text is
matched as well so the guard keeps working if that capture is ever defeated.
This runs only during pack, unlike the _ValidateBundledSdkFeatureVersions target below which also hooks
Build. Pack is where the metadata is consumed, the produced packages are checked again by
PackageMetadataCompletenessTests, and this way a plain build never breaks for someone mid-authoring a
package.
Note this deliberately also covers IsShipping=false packages: Microsoft.Testing.Extensions.AzureFoundry
is non-shipping and still reached nuget.org with the placeholder.
-->
<Target Name="_ValidatePackageMetadata"
BeforeTargets="GenerateNuspec"
Condition=" '$(IsPackable)' == 'true' ">
<PropertyGroup>
<!--
$(Description) is re-checked here rather than only at evaluation time because NuGet promotes it to
$(PackageDescription) in Pack.targets, which is imported after every Directory.Build.targets - so a
description supplied by a nested one still reaches nuget.org intact. $(PackageDescription) itself is
useless here: by now NuGet has always set it.
-->
<_HasAuthoredPackageDescription Condition=" '$(Description)' != '' ">true</_HasAuthoredPackageDescription>
</PropertyGroup>
<Error Condition=" '$(_HasAuthoredPackageDescription)' != 'true' or '$(PackageDescription)' == 'Package Description' "
Text="$(MSBuildProjectName) is packable but has no package description, so it would be published to nuget.org with NuGet's 'Package Description' placeholder. Set PackageDescription in the project; lead with what the package does and close with the shared CommonProductDescription property." />
<Error Condition=" '$(PackageReadmeFile)' == '' "
Text="$(MSBuildProjectName) is packable but has no package README, so its nuget.org page would show no rendered documentation. Add a PACKAGE.md next to the project file (it is picked up automatically) or set PackageReadmeFile." />
</Target>
<ItemGroup Condition=" '$(GenerateBuildInfo)' == 'true' ">
<PackageReference Include="Microsoft.DotNet.Build.Tasks.Templating" Version="$(MicrosoftDotNetBuildTasksTemplatingPackageVersion)" AllowExplicitReference="true" PrivateAssets="All" IsImplicitlyDefined="true" />
</ItemGroup>
<Target Name="_GenerateVersionSourceFileCache">
<PropertyGroup>
<_TemplateProperties>Version=$(Version)</_TemplateProperties>
<_TemplatePropertiesCacheFile>$(IntermediateOutputPath)$(MSBuildProjectFile).GenerateVersionSourceFile.cache</_TemplatePropertiesCacheFile>
</PropertyGroup>
<Hash ItemsToHash="$(_TemplateProperties)">
<Output TaskParameter="HashResult" PropertyName="_TemplatePropertiesHash" />
</Hash>
<WriteLinesToFile Lines="$(_TemplatePropertiesHash)" File="$(_TemplatePropertiesCacheFile)" Overwrite="true" WriteOnlyWhenDifferent="true" />
<ItemGroup>
<FileWrites Include="$(_TemplatePropertiesCacheFile)" />
</ItemGroup>
</Target>
<PropertyGroup Condition=" '$(GenerateBuildInfo)' == 'true' ">
<BuildInfoTemplateFile Condition=" '$(BuildInfoTemplateFile)' == '' ">$(MSBuildProjectDirectory)/BuildInfo.cs.template</BuildInfoTemplateFile>
</PropertyGroup>
<!-- See https://github.com/dotnet/arcade/issues/16019 -->
<!-- This can be simplified if Arcade implemented WriteOnlyWhenDifferent -->
<Target Name="GenerateVersionSourceFile"
AfterTargets="PrepareForBuild"
DependsOnTargets="_GenerateVersionSourceFileCache"
Inputs="$(_TemplatePropertiesCacheFile);$(BuildInfoTemplateFile)"
Outputs="$(IntermediateOutputPath)BuildInfo.cs"
Condition=" '$(GenerateBuildInfo)' == 'true' ">
<ItemGroup>
<_TemplateCsproj Include="$(BuildInfoTemplateFile)" Destination="$(IntermediateOutputPath)BuildInfo.cs" />
</ItemGroup>
<GenerateFileFromTemplate TemplateFile="%(_TemplateCsproj.Identity)" OutputPath="%(_TemplateCsproj.Destination)" Properties="$(_TemplateProperties)">
<Output TaskParameter="ResolvedOutputPath" ItemName="FileWrites" />
</GenerateFileFromTemplate>
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)BuildInfo.cs" />
</ItemGroup>
</Target>
<!-- Validates that the literal versions declared on the MSTest.Sdk-bundled feature PackageVersion items
in Directory.Packages.props stay in sync with the matching scalar *Version properties consumed by the
build. Authored here (rather than in Directory.Packages.props) because targets belong in .targets
files; the PackageVersion items it references are populated before this target executes regardless of
which file declares it. -->
<Target Name="_ValidateBundledSdkFeatureVersions"
BeforeTargets="CollectPackageReferences;GenerateNuspec;Build;Pack"
Condition=" '$(MSBuildProjectName)' == 'MSTest.Sdk' ">
<PropertyGroup>
<_AspireHostingTestingPackageVersion>@(PackageVersion->WithMetadataValue('Identity', 'Aspire.Hosting.Testing')->'%(Version)')</_AspireHostingTestingPackageVersion>
<_MicrosoftPlaywrightPackageVersion>@(PackageVersion->WithMetadataValue('Identity', 'Microsoft.Playwright.MSTest.v4')->'%(Version)')</_MicrosoftPlaywrightPackageVersion>
</PropertyGroup>
<Error Condition=" '$(AspireHostingTestingVersion)' != '$(_AspireHostingTestingPackageVersion)' "
Text="AspireHostingTestingVersion ('$(AspireHostingTestingVersion)') is out of sync with the 'Aspire.Hosting.Testing' PackageVersion ('$(_AspireHostingTestingPackageVersion)') in Directory.Packages.props. Update the AspireHostingTestingVersion property to match (Dependabot only updates the PackageVersion)." />
<Error Condition=" '$(MicrosoftPlaywrightVersion)' != '$(_MicrosoftPlaywrightPackageVersion)' "
Text="MicrosoftPlaywrightVersion ('$(MicrosoftPlaywrightVersion)') is out of sync with the 'Microsoft.Playwright.MSTest.v4' PackageVersion ('$(_MicrosoftPlaywrightPackageVersion)') in Directory.Packages.props. Update the MicrosoftPlaywrightVersion property to match (Dependabot only updates the PackageVersion)." />
</Target>
</Project>