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

packaging.targets « eng - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb182df8e553bf3da85429db882bd9cacdbf033f (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
<Project>

  <PropertyGroup>
    <EnablePackageValidation>true</EnablePackageValidation>
    <!-- Don't restore prebuilt packages during sourcebuild. -->
    <DisablePackageBaselineValidation Condition="'$(DotNetBuildFromSource)' == 'true'">true</DisablePackageBaselineValidation>
    <PackageValidationBaselineVersion Condition="'$(PackageValidationBaselineVersion)' == ''">$(NetCoreAppLatestStablePackageBaselineVersion)</PackageValidationBaselineVersion>
    <!-- PackDependsOn is the right hook in a targets file if the NuGet.Build.Tasks.Pack nuget package is used, otherwise
         BeforePack must be used. Setting both to ensure that we are always running before other targets. --> 
    <PackDependsOn>AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(PackDependsOn)</PackDependsOn>
    <BeforePack>AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(BeforePack)</BeforePack>
    <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddRuntimeSpecificFilesToPackage;IncludeProjectReferencesWithPackAttributeInPackage</TargetsForTfmSpecificContentInPackage>
    <IncludeBuildOutput Condition="'$(TargetPlatformIdentifier)' != ''">false</IncludeBuildOutput>
    <!-- Don't include target platform specific dependencies, since we use the target platform to represent RIDs instead -->
    <SuppressDependenciesWhenPacking Condition="'$(TargetPlatformIdentifier)' != ''">true</SuppressDependenciesWhenPacking>
    <PackageDesignerMarkerFile>$(MSBuildThisFileDirectory)useSharedDesignerContext.txt</PackageDesignerMarkerFile>
    <!-- Generate packages for rid specific projects or for allconfigurations during build. -->
    <!-- A package isn't generated if in servicing or in runtimelab. Intended to be overridden at project level. -->
    <IsRIDSpecificProject Condition="$(MSBuildProjectName.StartsWith('runtime.')) and
                                     !$(MSBuildProjectName.StartsWith('runtime.native'))">true</IsRIDSpecificProject>
    <GeneratePackageOnBuild Condition="('$(BuildAllConfigurations)' == 'true' or
                                       '$(IsRIDSpecificProject)' == 'true') and
                                       '$(PreReleaseVersionLabel)' != 'servicing' and
                                       '$(GitHubRepositoryName)' != 'runtimelab'">true</GeneratePackageOnBuild>
    <GeneratePackageOnBuild Condition="'$(GeneratePackageOnBuild)' != 'true'">false</GeneratePackageOnBuild>
    <!-- When in source-build we need to generate all packages when building for all configurations even in servicing. -->
    <GeneratePackageOnBuild Condition="!$(GeneratePackageOnBuild) and
                                       '$(BuildAllConfigurations)' == 'true' and
                                       '$(DotNetBuildFromSource)' == 'true'">true</GeneratePackageOnBuild>
    <!-- Search for the documentation file in the intellisense package and otherwise pick up the generated one. -->
    <LibIntellisenseDocumentationFilePath>$(XmlDocFileRoot)1033\$(AssemblyName).xml</LibIntellisenseDocumentationFilePath>
    <UseIntellisenseDocumentationFile Condition="'$(UseIntellisenseDocumentationFile)' == '' and Exists('$(LibIntellisenseDocumentationFilePath)')">true</UseIntellisenseDocumentationFile>
  </PropertyGroup>

  <PropertyGroup Condition="'$(PreReleaseVersionLabel)' == 'servicing'">
    <!-- If no servicing version is set we need to default to 0 in order for dependency versions to
    be calculated propertly, if we don't set it to 0, we would get the dependency version using the
    product Patch Version -->
    <ServicingVersion Condition="'$(ServicingVersion)' == ''">0</ServicingVersion>

    <!-- Always update the package version in servicing. -->
    <Version>$(MajorVersion).$(MinorVersion).$(ServicingVersion)</Version>
    <Version Condition="'$(VersionSuffix)' != ''">$(Version)-$(VersionSuffix)</Version>
    <_IsWindowsDesktopApp Condition="$(WindowsDesktopCoreAppLibrary.Contains('$(AssemblyName);'))">true</_IsWindowsDesktopApp>
    <_IsAspNetCoreApp Condition="$(AspNetCoreAppLibrary.Contains('$(AssemblyName);'))">true</_IsAspNetCoreApp>
    <_AssemblyInTargetingPack Condition="('$(IsNETCoreAppSrc)' == 'true' or '$(IsNetCoreAppRef)' == 'true' or '$(_IsAspNetCoreApp)' == 'true' or '$(_IsWindowsDesktopApp)' == 'true') and '$(TargetFrameworkIdentifier)' != '.NETFramework'">true</_AssemblyInTargetingPack>
    <!-- Assembly version do not get updated in non-netfx ref pack assemblies. -->
    <AssemblyVersion Condition="'$(_AssemblyInTargetingPack)' != 'true'">$(MajorVersion).$(MinorVersion).0.$(ServicingVersion)</AssemblyVersion>
  </PropertyGroup>

  <ItemGroup Condition="'$(EnablePackageValidation)' == 'true'">
    <PackageReference Include="Microsoft.DotNet.Compatibility" Version="$(MicrosoftDotNetCompatibilityVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
  </ItemGroup>

  <ItemGroup>
    <!-- Add a marker to help the designer optimize & share .NET Core packages -->
    <None Include="$(PackageDesignerMarkerFile)"
          PackagePath="$([System.IO.Path]::GetFileName('$(PackageDesignerMarkerFile)'))"
          Pack="true"
          Condition="'$(IncludeDesignerMarker)' != 'false'" />
  </ItemGroup>

  <ItemGroup Condition="'$(AddNETFrameworkAssemblyReferenceToPackage)' == 'true'">
    <_FrameworkAssemblyReferences Include="$(MSBuildProjectName)"
                                  TargetFramework="$(NetFrameworkMinimum)" />
  </ItemGroup>

  <Choose>
    <When Condition="'$(AddXamarinPlaceholderFilesToPackage)' == 'true' or '$(AddNETFrameworkPlaceholderFileToPackage)' == 'true'">
      <PropertyGroup>
        <!-- Placeholders don't need a dependency group. -->
        <NoWarn>$(NoWarn);NU5128</NoWarn>
      </PropertyGroup>
      <ItemGroup Condition="'$(AddNETFrameworkPlaceholderFileToPackage)' == 'true'">
        <None Include="$(PlaceholderFile)" PackagePath="$(BuildOutputTargetFolder)/$(NetFrameworkMinimum)" Pack="true" />
      </ItemGroup>
      <ItemGroup Condition="'$(AddXamarinPlaceholderFilesToPackage)' == 'true'">
        <None Include="$(PlaceholderFile)" PackagePath="$(BuildOutputTargetFolder)/MonoAndroid10" Pack="true" />
        <None Include="$(PlaceholderFile)" PackagePath="$(BuildOutputTargetFolder)/MonoTouch10" Pack="true" />
        <None Include="$(PlaceholderFile)" PackagePath="$(BuildOutputTargetFolder)/xamarinios10" Pack="true" />
        <None Include="$(PlaceholderFile)" PackagePath="$(BuildOutputTargetFolder)/xamarinmac20" Pack="true" />
        <None Include="$(PlaceholderFile)" PackagePath="$(BuildOutputTargetFolder)/xamarintvos10" Pack="true" />
        <None Include="$(PlaceholderFile)" PackagePath="$(BuildOutputTargetFolder)/xamarinwatchos10" Pack="true" />
      </ItemGroup>
    </When>
  </Choose>

  <!-- TODO: Remove this target when no library relies on the intellisense documentation file anymore.-->
  <Target Name="ChangeDocumentationFileForPackaging"
          AfterTargets="DocumentationProjectOutputGroup"
          Condition="'$(UseIntellisenseDocumentationFile)' == 'true'">
    <ItemGroup>
      <DocumentationProjectOutputGroupOutput Remove="@(DocumentationProjectOutputGroupOutput)" />
      <DocumentationProjectOutputGroupOutput Include="$(LibIntellisenseDocumentationFilePath)" />
    </ItemGroup>
  </Target>

  <!-- Add runtime specific file into the package if the tfm is RID specific. -->
  <Target Name="AddRuntimeSpecificFilesToPackage"
          DependsOnTargets="BuiltProjectOutputGroup;
                            DocumentationProjectOutputGroup;
                            SatelliteDllsProjectOutputGroup;
                            $(TargetsForTfmSpecificBuildOutput)"
          Condition="'$(TargetPlatformIdentifier)' != ''">
    <PropertyGroup>
      <RuntimeSymbolPath>$(TargetDir)$(TargetName).pdb</RuntimeSymbolPath>
      <_packageTargetRuntime>$(TargetPlatformIdentifier.ToLowerInvariant().Replace('windows', 'win'))</_packageTargetRuntime>
      <_targetFrameworkWithoutSuffix>$(TargetFramework)</_targetFrameworkWithoutSuffix>
      <_targetFrameworkWithoutSuffix Condition="$(TargetFramework.Contains('-'))">$(TargetFramework.SubString(0, $(TargetFramework.IndexOf('-'))))</_targetFrameworkWithoutSuffix>
    </PropertyGroup>

    <ItemGroup>
      <TfmRuntimeSpecificPackageFile Include="@(SatelliteDllsProjectOutputGroupOutput);
                                              @(BuiltProjectOutputGroupOutput);
                                              @(DocumentationProjectOutputGroupOutput)" />
      <TfmSpecificPackageFile Include="@(TfmRuntimeSpecificPackageFile)"
                              PackagePath="runtimes/$(_packageTargetRuntime)/$(BuildOutputTargetFolder)/$(_targetFrameworkWithoutSuffix)" />
      <TfmSpecificDebugSymbolsFile Include="$(RuntimeSymbolPath)"
                                   TargetPath="/runtimes/$(_packageTargetRuntime)/$(BuildOutputTargetFolder)/$(_targetFrameworkWithoutSuffix)/%(Filename)%(Extension)"
                                   TargetFramework="$(_targetFrameworkWithoutSuffix)"
                                   Condition="'$(IncludeSymbols)' == 'true' and Exists('$(RuntimeSymbolPath)')" />
    </ItemGroup>
  </Target>

  <Target Name="IncludeAnalyzersInPackage" Condition="'@(AnalyzerReference)' != ''">
    <!-- Call a target in the analyzer project to get all the files it would normally place in a package.
         These will be returned as items with identity pointing to the built file, and PackagePath metadata
         set to their location in the package.  IsSymbol metadata will be set to distinguish symbols. -->
    <MSBuild Projects="@(AnalyzerReference)"
             Targets="GetAnalyzerPackFiles">
      <Output TaskParameter="TargetOutputs" ItemName="_AnalyzerFile" />
    </MSBuild>

    <ItemGroup>
      <Content Include="@(_AnalyzerFile)" Pack="True" Condition="!%(_AnalyzerFile.IsSymbol)" />
      <!-- Symbols don't honor PackagePath.  By default they are placed in lib/%(TargetFramework).
           Pack does honor TargetPath and does Path.Combine("lib/%(TargetFramework)", "%(TargetPath)"),
           so a rooted path value for TargetPath will override lib.
           https://github.com/NuGet/Home/issues/10860 -->
      <_TargetPathsToSymbols Include="@(_AnalyzerFile)" TargetPath="/%(_AnalyzerFile.PackagePath)" Condition="%(_AnalyzerFile.IsSymbol)" />
    </ItemGroup>
  </Target>

  <PropertyGroup>
    <_MultiTargetRoslynComponentTargetsTemplate>$(MSBuildThisFileDirectory)MultiTargetRoslynComponent.targets.template</_MultiTargetRoslynComponentTargetsTemplate>
    <MultiTargetRoslynComponentTargetsFileIntermediatePath>$(IntermediateOutputPath)MultiTargetRoslynComponent.targets</MultiTargetRoslynComponentTargetsFileIntermediatePath>
    <IncludeMultiTargetRoslynComponentTargets Condition="'$(IncludeMultiTargetRoslynComponentTargets)' == ''">true</IncludeMultiTargetRoslynComponentTargets>
  </PropertyGroup>

  <!-- In packages that contain Analyzers, include a .targets file that will select the correct analyzer. -->
  <Target Name="IncludeMultiTargetRoslynComponentTargetsInPackage"
          AfterTargets="IncludeAnalyzersInPackage"
          Condition="'@(AnalyzerReference)' != '' and '$(IncludeMultiTargetRoslynComponentTargets)' == 'true'"
          DependsOnTargets="GenerateMultiTargetRoslynComponentTargetsFile">
    <ItemGroup>
      <Content Include="$(MultiTargetRoslynComponentTargetsFileIntermediatePath)"
               PackagePath="build\$(PackageId).targets"
               Pack="True" />
    </ItemGroup>
  </Target>

  <Target Name="GenerateMultiTargetRoslynComponentTargetsFile"
          Inputs="$(MSBuildProjectFullPath);$(_MultiTargetRoslynComponentTargetsTemplate)"
          Outputs="$(MultiTargetRoslynComponentTargetsFileIntermediatePath)">
    <PropertyGroup>
      <_MultiTargetRoslynComponentTargetPrefix>$(PackageId.Replace('.', '_'))</_MultiTargetRoslynComponentTargetPrefix>
      <DisableSourceGeneratorPropertyName Condition="'$(DisableSourceGeneratorPropertyName)' == ''">Disable$(PackageId.Replace('.', ''))SourceGenerator</DisableSourceGeneratorPropertyName>
    </PropertyGroup>

    <WriteLinesToFile File="$(MultiTargetRoslynComponentTargetsFileIntermediatePath)"
                      Lines="$([System.IO.File]::ReadAllText('$(_MultiTargetRoslynComponentTargetsTemplate)')
                                                 .Replace('{TargetPrefix}', '$(_MultiTargetRoslynComponentTargetPrefix)')
                                                 .Replace('{NuGetPackageId}', '$(PackageId)')
                                                 .Replace('{DisableSourceGeneratorPropertyName}', '$(DisableSourceGeneratorPropertyName)'))"
                      Overwrite="true" />
  </Target>

  <!-- Include a netstandard compat error if the project targets both .NETStandard and
       .NETCoreApp. This prohibits users to consume packages on an older .NETCoreApp version
       than the minimum supported one. -->
  <ItemGroup>
    <NETStandardCompatError Include="netcoreapp2.0"
                            Supported="$(NetCoreAppMinimum)"
                            Condition="$(TargetFrameworks.Contains('netstandard2.')) and
                                       ($(TargetFrameworks.Contains('$(NetCoreAppMinimum)')) or $(TargetFrameworks.Contains('$(NetCoreAppCurrent)'))) and
                                       '$(DisableNETStandardCompatErrorForNETCoreApp)' != 'true'" />
    <NETStandardCompatError Include="net461"
                            Supported="$(NetFrameworkMinimum)"
                            Condition="$(TargetFrameworks.Contains('netstandard2.0')) and
                                       ($(TargetFrameworks.Contains('$(NetFrameworkMinimum)')) or $(TargetFrameworks.Contains('net47')) or $(TargetFrameworks.Contains('net48'))) and
                                       '$(DisableNETStandardCompatErrorForNETFramework)' != 'true'" />

  </ItemGroup>

  <!-- Add targets file that marks a .NETStandard applicable tfm as unsupported. -->
  <Target Name="AddNETStandardCompatErrorFileForPackaging"
          Condition="'@(NETStandardCompatError)' != ''"
          Inputs="%(NETStandardCompatError.Identity)"
          Outputs="unused">
    <PropertyGroup>
      <_NETStandardCompatErrorFilePath>$(BaseIntermediateOutputPath)netstandardcompaterrors\%(NETStandardCompatError.Identity)\$(PackageId).targets</_NETStandardCompatErrorFilePath>
      <_NETStandardCompatErrorFileTarget>NETStandardCompatError_$(PackageId.Replace('.', '_'))_$([System.String]::new('%(NETStandardCompatError.Supported)').Replace('.', '_'))</_NETStandardCompatErrorFileTarget>
      <_NETStandardCompatErrorFileContent>
<![CDATA[<Project InitialTargets="$(_NETStandardCompatErrorFileTarget)">
  <Target Name="$(_NETStandardCompatErrorFileTarget)"
          Condition="'%24(SuppressTfmSupportBuildWarnings)' == ''">
    <Error Text="$(PackageId) doesn't support %24(TargetFramework). Consider updating your TargetFramework to %(NETStandardCompatError.Supported) or later." />
  </Target>
</Project>]]>
      </_NETStandardCompatErrorFileContent>
    </PropertyGroup>

    <WriteLinesToFile File="$(_NETStandardCompatErrorFilePath)"
                      Lines="$(_NETStandardCompatErrorFileContent)"
                      Overwrite="true"
                      WriteOnlyWhenDifferent="true" />

    <ItemGroup>
      <None Include="$(_NETStandardCompatErrorFilePath)"
            PackagePath="buildTransitive\%(NETStandardCompatError.Identity)"
            Pack="true" />
      <None Include="$(PlaceholderFile)"
            PackagePath="buildTransitive\%(NETStandardCompatError.Supported)"
            Pack="true" />
      <FileWrites Include="$(_NETStandardCompatErrorFilePath)" />
    </ItemGroup>
  </Target>

  <Target Name="IncludeProjectReferencesWithPackAttributeInPackage"
          Condition="'@(ProjectReference->WithMetadataValue('Pack', 'true'))' != ''"
          DependsOnTargets="BuildOnlySettings;ResolveReferences">
    <ItemGroup>
      <!-- Add ReferenceCopyLocalPaths for ProjectReferences which are flagged as Pack="true" into the package. -->
      <_projectReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('Pack', 'true'))" />
      <TfmSpecificPackageFile Include="@(_projectReferenceCopyLocalPaths)"
                              PackagePath="$([MSBuild]::ValueOrDefault('%(ReferenceCopyLocalPaths.PackagePath)', '$(BuildOutputTargetFolder)/$(TargetFramework)'))" />
      <TfmSpecificDebugSymbolsFile Include="@(TfmSpecificPackageFile->WithMetadataValue('Extension', '.pdb'))"
                                   TargetPath="/%(TfmSpecificPackageFile.PackagePath)/%(Filename)%(Extension)"
                                   TargetFramework="$(TargetFramework)"
                                   Condition="'$(IncludeSymbols)' == 'true'" />
      <!-- Remove symbol from the non symbol package. -->
      <TfmSpecificPackageFile Remove="@(TfmSpecificPackageFile->WithMetadataValue('Extension', '.pdb'))" />
      <!-- If the reference assembly is included, don't put the documentation file next to the lib assembly. -->
      <TfmSpecificPackageFile Remove="@(_projectReferenceCopyLocalPaths->WithMetadataValue('Extension', '.xml')->WithMetadataValue('IncludeReferenceAssemblyInPackage', 'true'))" />
    </ItemGroup>

    <ItemGroup>
      <!-- Include the reference assembly and put the documentation file next to it. -->
      <_referenceAssemblyPaths Include="@(_projectReferenceCopyLocalPaths->WithMetadataValue('Extension', '.dll')->WithMetadataValue('IncludeReferenceAssemblyInPackage', 'true')->Metadata('ReferenceAssembly'))" />
      <_referenceAssemblyPaths Include="@(_projectReferenceCopyLocalPaths->WithMetadataValue('Extension', '.xml')->WithMetadataValue('IncludeReferenceAssemblyInPackage', 'true'))" />
      <TfmSpecificPackageFile Include="@(_referenceAssemblyPaths)"
                              PackagePath="ref/$(TargetFramework)" />
    </ItemGroup>
  </Target>

  <Target Name="ValidateAssemblyVersionsInRefPack" 
          Condition="'$(SkipValidateAssemblyVersion)' != 'true' and '$(_AssemblyInTargetingPack)' == 'true' and '$(PreReleaseVersionLabel)' == 'servicing'"
          AfterTargets="CoreCompile" >
    <Error Condition="'$(AssemblyVersion)' != '$(LastReleasedStableAssemblyVersion)'" Text="AssemblyVersion should match last released assembly version $(LastReleasedStableAssemblyVersion)" />
  </Target>

  <Target Name="ValidateServicingVersionIsPropertlySet"
          Condition="'$(PreReleaseVersionLabel)' == 'servicing' and '$(DotNetBuildFromSource)' != 'true'"
          AfterTargets="GenerateNuspec">
    <Error Condition="'$(ServicingVersion)' == '0'" Text="ServicingVersion is set to 0 and it should be an increment of the patch version from the last released package." />
  </Target>

</Project>