dotnet-installer/src/SourceBuild/content/repo-projects/Directory.Build.targets

721 lines
38 KiB
Text
Raw Normal View History

<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
<PropertyGroup Condition="'$(UseInnerClone)' == 'true'">
<BuildArgs>$(BuildArgs) /p:UseInnerClone=true</BuildArgs>
<BuildArgs>$(BuildArgs) /p:CopySrcInsteadOfClone=true</BuildArgs>
<BuildArgs>$(BuildArgs) /p:CopyWipIntoInnerSourceBuildRepo=true</BuildArgs>
</PropertyGroup>
<PropertyGroup>
<BuildCommand Condition="'$(BuildCommand)' == '' and '$(IsUtilityProject)' != 'true'">$(BuildScript) $(BuildActions) $(BuildArgs)</BuildCommand>
<!-- The default PackageVersionPropsFlowType behavior (DependenciesOnly) triggers logic that looks for a
Version.Details.xml file. Setting the type to AllPackages will skip that logic. -->
<PackageVersionPropsFlowType Condition="'$(IsUtilityProject)' == 'true'">AllPackages</PackageVersionPropsFlowType>
<!-- MinimalConsoleLogOutput determines if the repository build should be logged to a separate file or directly to the console. -->
<RepoConsoleLogFile>$(ArtifactsLogDir)$(RepositoryName).log</RepoConsoleLogFile>
<MinimalConsoleLogOutput Condition="'$(MinimalConsoleLogOutput)' == '' and '$(ContinuousIntegrationBuild)' == 'true'">true</MinimalConsoleLogOutput>
<PackageReportDataFile>$(PackageReportDir)prebuilt-usage.xml</PackageReportDataFile>
<ProjectAssetsJsonArchiveFile>$(PackageReportDir)all-project-assets-json-files.zip</ProjectAssetsJsonArchiveFile>
<ProdConManifestFile>$(PackageReportDir)prodcon-build.xml</ProdConManifestFile>
<RepoManifestFile>$([MSBuild]::NormalizePath('$(ProjectDirectory)', 'artifacts', 'RepoManifest.xml'))</RepoManifestFile>
</PropertyGroup>
<!-- Exclude repositories that currently don't build when not building source-only. -->
<ItemGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
<RepositoryReference Remove="roslyn" />
<RepositoryReference Remove="wpf" />
<RepositoryReference Remove="msbuild" />
<RepositoryReference Remove="aspnetcore" />
<RepositoryReference Remove="razor" />
<RepositoryReference Remove="deployment-tools" />
<RepositoryReference Remove="format" />
<RepositoryReference Remove="nuget-client" />
<RepositoryReference Remove="templating" />
<RepositoryReference Remove="test-templates" />
<RepositoryReference Remove="fsharp" />
<RepositoryReference Remove="vstest" />
<RepositoryReference Remove="sdk" />
<RepositoryReference Remove="aspire" />
<RepositoryReference Remove="installer" />
</ItemGroup>
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="AddSourceToNuGetConfig" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ReadNuGetPackageInfos" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="RemoveInternetSourcesFromNuGetConfig" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="UpdateJson" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="UpdateNuGetConfigPackageSourcesMappings" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ValidateUsageAgainstBaseline" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WritePackageVersionsProps" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WritePackageUsageData" />
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WriteUsageReports" />
<Target Name="CopyNuGetConfig"
Condition="'$(NuGetConfigFile)' != ''"
Inputs="$(MSBuildProjectFullPath);$(OriginalNuGetConfigFile)"
Outputs="$(NuGetConfigFile)">
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('$(NuGetConfigFile)'))" />
<Copy
SourceFiles="$(OriginalNuGetConfigFile)"
DestinationFiles="$(NuGetConfigFile)">
<Output TaskParameter="CopiedFiles" ItemName="FileWrites" />
</Copy>
</Target>
<Target Name="UpdateNuGetConfig"
DependsOnTargets="CopyNuGetConfig"
Condition="'$(NuGetConfigFile)' != ''"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)UpdateNuGetConfig.complete">
<PropertyGroup>
<SourceBuiltNuGetSourceName>source-built</SourceBuiltNuGetSourceName>
<ExtraSourcesNuGetSourceName>ExtraSources</ExtraSourcesNuGetSourceName>
<SourceBuildSources>$(SourceBuiltNuGetSourceName)</SourceBuildSources>
<SourceBuildSources Condition="'$(ExtraRestoreSourcePath)' != ''">$(SourceBuildSources);$(ExtraSourcesNuGetSourceName)</SourceBuildSources>
</PropertyGroup>
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' == 'true'">
<PrebuiltNuGetSourceName>prebuilt</PrebuiltNuGetSourceName>
<PreviouslySourceBuiltNuGetSourceName>previously-source-built</PreviouslySourceBuiltNuGetSourceName>
<ReferencePackagesNuGetSourceName>reference-packages</ReferencePackagesNuGetSourceName>
<SourceBuildSources>$(SourceBuildSources);$(PrebuiltNuGetSourceName);$(PreviouslySourceBuiltNuGetSourceName);$(ReferencePackagesNuGetSourceName)</SourceBuildSources>
</PropertyGroup>
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
<!-- When not building source-only, repositories lagging behind on the .NET SDK (e.g. tooling repos)
that need to utilize a VS-aligned version for development purposes may not have the latest product
daily build feed in their NuGet.config. This means that when a newer globally-specified .NET SDK
attempts to restore shared framework packages, they will not be found. Work around this by
ensuring that repos have the supporting SDK feed. Note that this is not required when the SDK
in use is a released SDK.
Currently we are using a preview .NET 9 SDK and not all repos are using the Net 9 SDK
If either of these are not true, set below to false.
-->
<AddNetSdkSupportingFeed>true</AddNetSdkSupportingFeed>
<NetSdkSupportingFeedName>net-sdk-supporting-feed</NetSdkSupportingFeedName>
<NetSdkSupportingFeed>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json</NetSdkSupportingFeed>
</PropertyGroup>
<RemoveInternetSourcesFromNuGetConfig
NuGetConfigFile="$(NuGetConfigFile)"
BuildWithOnlineFeeds="$(DotNetBuildWithOnlineFeeds)"
KeepFeedPrefixes="@(KeepFeedPrefixes)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(PrebuiltNuGetSourceName)"
SourcePath="$(PrebuiltPackagesPath)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(PreviouslySourceBuiltNuGetSourceName)"
SourcePath="$(PrebuiltSourceBuiltPackagesPath)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(ReferencePackagesNuGetSourceName)"
SourcePath="$(ReferencePackagesDir)"
Condition="'$(DotNetBuildSourceOnly)' == 'true'" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(SourceBuiltNuGetSourceName)"
SourcePath="$(SourceBuiltPackagesPath)" />
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(ExtraSourcesNuGetSourceName)"
SourcePath="$(ExtraRestoreSourcePath)"
Condition="'$(ExtraRestoreSourcePath)' != ''" />
<!-- See root Directory.Build.props for value. -->
<AddSourceToNuGetConfig NuGetConfigFile="$(NuGetConfigFile)"
SourceName="$(NetSdkSupportingFeedName)"
SourcePath="$(NetSdkSupportingFeed)"
Condition="'$(AddNetSdkSupportingFeed)' == 'true'" />
<UpdateNuGetConfigPackageSourcesMappings
NuGetConfigFile="$(NuGetConfigFile)"
BuildWithOnlineFeeds="$(DotNetBuildWithOnlineFeeds)"
SourceBuildSources="$(SourceBuildSources)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)UpdateNuGetConfig.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<!-- Update the SDK version in the repo's global.json file.
This guarantees that all repositories build with the VMR's SDK version. -->
<Target Name="UpdateGlobalJsonVersions"
Condition="'$(GlobalJsonFile)' != ''"
Inputs="$(MSBuildProjectFullPath);$(MSBuildThisFileFullPath)"
Outputs="$(BaseIntermediateOutputPath)UpdateGlobalJsonVersions.complete">
<ItemGroup>
<_PossibleCliVersionJsonPath Include="sdk:version" />
<_PossibleCliVersionJsonPath Include="tools:dotnet" />
</ItemGroup>
<UpdateJson JsonFilePath="$(GlobalJsonFile)"
PathToAttribute="%(_PossibleCliVersionJsonPath.Identity)"
NewAttributeValue="$(NETCoreSdkVersion)"
SkipUpdateIfMissingKey="true" />
<!-- VB PoC, remove the global runtimes until https://github.com/dotnet/arcade/issues/14283 is resolved. -->
<UpdateJson JsonFilePath="$(GlobalJsonFile)"
PathToAttribute="tools:runtimes"
SkipUpdateIfMissingKey="true" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)UpdateGlobalJsonVersions.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<!-- TODO: Remove when all repos use a consistent set of eng/common files: https://github.com/dotnet/source-build/issues/3710. -->
<Target Name="UpdateEngCommonFiles"
Condition="'$(UpdateEngCommonFiles)' == 'true' or '$(DotNetBuildSourceOnly)' != 'true'">
<ItemGroup>
<OrchestratorEngCommonFile Include="$(RepositoryEngineeringDir)common\**\*" />
</ItemGroup>
<Copy SourceFiles="@(OrchestratorEngCommonFile)"
DestinationFolder="$(ProjectDirectory)eng\common\%(RecursiveDir)"
SkipUnchangedFiles="true" />
</Target>
<!-- Before a repository builds, set up the version property files that override the repo's defaults.
There are 3 files generated -->
<Target Name="CreateBuildInputProps"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)CreateBuildInputProps.complete">
<ItemGroup>
<_CurrentSourceBuiltPackages Include="$(SourceBuiltPackagesPath)*.nupkg"
Exclude="$(SourceBuiltPackagesPath)*.symbols.nupkg" />
<_PreviouslyBuiltSourceBuiltPackages Include="$(PrebuiltSourceBuiltPackagesPath)*.nupkg" />
</ItemGroup>
<Error Condition="'$(PackageVersionPropsFlowType)' != 'AllPackages' and '$(PackageVersionPropsFlowType)' != 'DependenciesOnly'"
Text="Invalid PackageVersionPropsFlowType '$(PackageVersionPropsFlowType)'. Must be 'AllPackages' or 'DependenciesOnly'." />
<PropertyGroup>
<_VersionDetailsXml Condition="'$(PackageVersionPropsFlowType)' == 'DependenciesOnly'">$(ProjectDirectory)/eng/Version.Details.xml</_VersionDetailsXml>
</PropertyGroup>
<!-- Write the build input properties, then save off a copy that will be used for generating usage reports later -->
<WritePackageVersionsProps NuGetPackages="@(_CurrentSourceBuiltPackages)"
ExtraProperties="@(ExtraPackageVersionPropsPackageInfo)"
VersionPropsFlowType="$(PackageVersionPropsFlowType)"
VersionDetails="$(_VersionDetailsXml)"
OutputPath="$(CurrentSourceBuiltPackageVersionPropsPath)" />
<!-- Create previously source-built inputs info -->
<WritePackageVersionsProps NuGetPackages="@(_PreviouslyBuiltSourceBuiltPackages)"
VersionPropsFlowType="$(PackageVersionPropsFlowType)"
VersionDetails="$(_VersionDetailsXml)"
OutputPath="$(PreviouslySourceBuiltPackageVersionPropsPath)" />
<!-- Write a full package version props (unfiltered) that will be used to track which repo creates a package.
Because not all repos implement the repo API (e.g. some are external), it's difficult to consistently gather
a list of packages from the output of each repo. This may be an area for improvement later.
Instead, we rely on the package version props file that is built up
before each build. If the full list of packages grows by package A, B and C between repo Y and Z, then Y produced
A B and C.
A key element of this algorith is that we must write the full package version props and not the filtered version. -->
<WritePackageVersionsProps NuGetPackages="@(_CurrentSourceBuiltPackages)"
VersionPropsFlowType="AllPackages"
OutputPath="$(SnapshotPackageVersionPropsPath)" />
<!-- Write a single file that contains imports for both the current and previously built packages -->
<PropertyGroup>
<PackageVersionsPropsContents>
<![CDATA[
<Project>
<Import Project="$(PreviouslySourceBuiltPackageVersionPropsPath)" />
<Import Project="$(CurrentSourceBuiltPackageVersionPropsPath)" />
</Project>
]]>
</PackageVersionsPropsContents>
</PropertyGroup>
<WriteLinesToFile File="$(PackageVersionPropsPath)"
Lines="$(PackageVersionsPropsContents)"
Overwrite="true" />
<Message Importance="High" Text="$(RepositoryName) using package version properties saved at $(CurrentSourceBuiltPackageVersionPropsPath) and $(PreviouslySourceBuiltPackageVersionPropsPath)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)CreateBuildInputProps.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<!-- SkipRepoReferences is a developer innerloop switch to skip building dependencies. -->
<Target Name="BuildRepoReferences"
Condition="'@(RepositoryReference)' != '' and '$(SkipRepoReferences)' != 'true'">
<Message Importance="High" Text="Building dependencies [@(RepositoryReference)] needed by '$(RepositoryName)'." />
<ItemGroup>
<_DependentProject Include="@(RepositoryReference -> '%(Identity).proj')" />
</ItemGroup>
<MSBuild Projects="@(_DependentProject)"
Targets="Build"
BuildInParallel="$(BuildInParallel)"
StopOnFirstFailure="true" />
</Target>
<Target Name="RepoBuild"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)Build.complete"
Condition="'$(BuildCommand)' != ''"
DependsOnTargets="BuildRepoReferences;
UpdateNuGetConfig;
UpdateGlobalJsonVersions;
CreateBuildInputProps;
UpdateEngCommonFiles;
SetSourceBuiltSdkOverrides">
<Exec Command="$(DotnetTool) build-server shutdown" />
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(RepositoryName)" />
<Message Importance="High" Text="Running command:" />
<Message Importance="High" Text=" $(BuildCommand)" />
<Message Importance="High" Text=" Log: $(RepoConsoleLogFile)" Condition="'$(MinimalConsoleLogOutput)' == 'true'" />
<Message Importance="High" Text=" With Environment Variables:"/>
<Message Importance="High" Text=" %(EnvironmentVariables.Identity)" />
<Message Text="DirSize Before Building $(RepositoryName)" Importance="High"
Condition=" '$(CleanWhileBuilding)' == 'true' and '$(BuildOS)' != 'windows'" />
<Exec Command="df -h $(RepoRoot)"
Condition=" '$(CleanWhileBuilding)' == 'true' and '$(BuildOS)' != 'windows'" />
<PropertyGroup>
<FullCommand>$(BuildCommand)</FullCommand>
<FullCommand Condition="'$(LogVerbosityOptOut)' != 'true'">$(FullCommand) /v:$(LogVerbosity)</FullCommand>
<FullCommand Condition="'$(MinimalConsoleLogOutput)' == 'true'">$(FullCommand) &gt;&gt; $(RepoConsoleLogFile) 2&gt;&amp;1</FullCommand>
</PropertyGroup>
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('$(RepoConsoleLogFile)'));
$(SourceBuiltPackagesPath)" />
<!-- Create directories for extra debugging. -->
<MakeDir Directories="$(MSBuildDebugPathTargetDir);
$(RoslynDebugPathTargetDir);
$(AspNetRazorBuildServerLogDir)"
Condition="'$(EnableExtraDebugging)' == 'true'" />
<Exec Command="$(FullCommand)"
WorkingDirectory="$(ProjectDirectory)"
EnvironmentVariables="@(EnvironmentVariables)" />
<Message Importance="High" Text="[$([System.DateTime]::Now.ToString('HH:mm:ss.ff'))] Building $(RepositoryName)...done" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)Build.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
<!-- Propagate errors to the output when using the minimal console log feature. -->
<OnError ExecuteTargets="LogRepoBuildError" Condition="'$(MinimalConsoleLogOutput)' == 'true'" />
</Target>
<Target Name="LogRepoBuildError">
<Message Importance="High" Text="$([System.IO.File]::ReadAllText('$(RepoConsoleLogFile)'))" Condition="Exists('$(RepoConsoleLogFile)') and '$(MinimalConsoleLogOutput)' == 'true'" />
<Message Importance="High" Text="'$(RepositoryName)' failed during build." />
<Message Importance="High" Text="See '$(RepoConsoleLogFile)' for more information." Condition="Exists('$(RepoConsoleLogFile)') and '$(MinimalConsoleLogOutput)' == 'true'" />
</Target>
<Target Name="Build" DependsOnTargets="BuildRepoReferences;RepoBuild" />
<Target Name="Package" AfterTargets="Build" />
<Target Name="GatherBuiltPackages">
<ItemGroup>
<!-- Filter out packages for WriteVersions -->
<_BuiltPackages Condition="'$(PackagesOutput)' != ''" Include="$(PackagesOutput)/*.nupkg" Exclude="$(PackagesOutput)/*.symbols.nupkg"/>
<_BuiltPackages Condition="'@(PackagesOutputList)' != ''" Include="%(PackagesOutputList.Identity)/*.nupkg" Exclude="%(PackagesOutputList.Identity)/*.symbols.nupkg"/>
</ItemGroup>
</Target>
<Target Name="CopyRepoArtifacts"
AfterTargets="Package"
Condition="'$(IsUtilityProject)' != 'true'"
Inputs="$(RepoManifestFile)"
Outputs="$(BaseIntermediateOutputPath)ArtifactsCopy.complete">
<Error Text="Repo manifest file doesn't exist." Condition="!Exists('$(RepoManifestFile)')" />
<XmlPeek XmlInputPath="$(RepoManifestFile)"
Query="Build/Artifact/@Path">
<Output TaskParameter="Result" ItemName="RepoManifestArtifact" />
</XmlPeek>
<ItemGroup>
<RepoManifestAsset Include="@(RepoManifestArtifact)" Condition="'%(Extension)' != '.nupkg'"/>
<RepoManifestPackage Include="@(RepoManifestArtifact)" Condition="'%(Extension)' == '.nupkg'"/>
<RepoManifestNonShippingPackage Include="@(RepoManifestPackage)" Condition="$([System.String]::Copy('%(Identity)').Contains('$([System.IO.Path]::DirectorySeparatorChar)NonShipping$([System.IO.Path]::DirectorySeparatorChar)'))"/>
</ItemGroup>
<PropertyGroup>
<_NupkgsDestination>$(SourceBuiltPackagesPath)</_NupkgsDestination>
<_NupkgsDestination Condition="'$(RepositoryName)' == 'source-build-reference-packages'">$(ReferencePackagesDir)</_NupkgsDestination>
</PropertyGroup>
<!-- Building SBRP: At this point the References directory contains the previously-source-built SBRPs,
clear it before copying the current SBRPs. This ensures n-1 SBRPs aren't required to build the product repos. -->
<RemoveDir
Condition="'$(RepositoryName)' == 'source-build-reference-packages'"
Directories="$(ReferencePackagesDir)" />
<!-- Copy nupkgs -->
<Copy
Condition="'@(RepoManifestPackage)' != ''"
SourceFiles="@(RepoManifestPackage)"
DestinationFolder="$(_NupkgsDestination)" />
<!-- Copy assets -->
<Copy
Condition="'@(RepoManifestAsset)' != ''"
SourceFiles="@(RepoManifestAsset)"
DestinationFolder="$(SourceBuiltAssetsDir)" />
<!-- Generate non-shipping package list -->
<PropertyGroup>
<NonShippingPackagesList Condition="'@(RepoManifestNonShippingPackage)' != ''">$(PackageListsDir)$(NonShippingPackagesListPrefix)$(RepositoryName).lst</NonShippingPackagesList>
</PropertyGroup>
<WriteLinesToFile
Condition="'$(NonShippingPackagesList)' != ''"
File="$(NonShippingPackagesList)"
Lines="@(RepoManifestNonShippingPackage->'%(Filename)%(Extension)')"
Overwrite="true" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)ArtifactsCopy.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<!-- Copy restored packages from inner build to ensure they're included in the
main build prebuilt check -->
<Target Name="CopyInnerBuildRestoredPackages"
AfterTargets="Package">
<ItemGroup>
<_InnerPackageCacheFiles Include="$(ProjectDirectory)artifacts/sb/package-cache/**/*" />
</ItemGroup>
<Copy SourceFiles="@(_InnerPackageCacheFiles)"
DestinationFiles="$(NuGetPackageRoot)%(RecursiveDir)%(Filename)%(Extension)"
Condition=" '@(_InnerPackageCacheFiles)' != '' " />
</Target>
<Target Name="CopyPackage"
AfterTargets="Package"
Condition="'$(PackagesOutput)' != '' OR '@(PackagesOutputList)' != ''"
DependsOnTargets="GatherBuiltPackages">
<Copy SourceFiles="@(_BuiltPackages)"
DestinationFolder="$(SourceBuiltPackagesPath)"
Condition="'@(_BuiltPackages)'!=''"
SkipUnchangedFiles="true" />
</Target>
<Target Name="RemoveBuiltPackagesFromCache"
AfterTargets="Package"
Condition="'@(_BuiltPackages)'!=''"
DependsOnTargets="GatherBuiltPackages"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)RemoveBuiltPackagesFromCache.complete">
<ItemGroup>
<!-- Excluding Arcade here will keep it in the cache, because that's where we're running from.
Subsequent projects will get Arcade from eng/source-built-sdks. -->
<PackagePaths Include="@(_BuiltPackages)" Exclude="$(PackagesOutput)/Microsoft.DotNet.Arcade.Sdk.*.nupkg" />
</ItemGroup>
<ReadNuGetPackageInfos PackagePaths="@(PackagePaths)">
<Output TaskParameter="PackageInfoItems" ItemName="_BuiltPackageInfos" />
</ReadNuGetPackageInfos>
<!-- Copy built nupkgs from nuget packages cache directory to the previouslyRestored directory
and then delete all expanded files and the nupkg from the package cache so the next time
the package is used, it will reload the source-built version -->
<ItemGroup>
<_FilesToCopy Include="$(NuGetPackageRoot)$([System.String]::copy('%(_BuiltPackageInfos.PackageId)').ToLowerInvariant())/%(_BuiltPackageInfos.PackageVersion)/**/*.nupkg" />
<_FilesToDelete Include="$(NuGetPackageRoot)$([System.String]::copy('%(_BuiltPackageInfos.PackageId)').ToLowerInvariant())/%(_BuiltPackageInfos.PackageVersion)/**/*.*" />
</ItemGroup>
<Copy SourceFiles="@(_FilesToCopy)" DestinationFolder="$(PreviouslyRestoredPackagesPath)$(RepositoryName)/" />
<Delete Files="@(_FilesToDelete)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)RemoveBuiltPackagesFromCache.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<Target Name="CleanupRepo"
AfterTargets="RemoveBuiltPackagesFromCache"
Condition="'$(CleanWhileBuilding)' == 'true' and Exists('$(ProjectDirectory)artifacts')">
<PropertyGroup>
<BuildLogsDir>$([MSBuild]::NormalizeDirectory('$(ProjectDirectory)', 'artifacts', 'buildLogs'))</BuildLogsDir>
<BuildObjDir>$([MSBuild]::NormalizeDirectory('$(ProjectDirectory)', 'artifacts', 'buildObj'))</BuildObjDir>
</PropertyGroup>
<ItemGroup>
<LogFilesToCopy Include="$(ProjectDirectory)artifacts/**/*.log" />
<LogFilesToCopy Include="$(ProjectDirectory)artifacts/**/*.binlog" />
<ObjFilesToCopy Include="$(ProjectDirectory)artifacts/**/project.assets.json" />
</ItemGroup>
<!-- Make a copy of the build logs & project.assets.json files -->
<Copy SourceFiles="@(LogFilesToCopy)"
DestinationFolder="$(BuildLogsDir)%(RecursiveDir)"
SkipUnchangedFiles="true"
Condition="'@(LogFilesToCopy)' != ''" />
<Copy SourceFiles="@(ObjFilesToCopy)"
DestinationFolder="$(BuildObjDir)%(RecursiveDir)"
SkipUnchangedFiles="true"
Condition="'@(ObjFilesToCopy)' != ''" />
<ItemGroup>
<DirsToDelete Include="$([System.IO.Directory]::GetDirectories('$(ProjectDirectory)artifacts'))" />
<DirsToDeleteWithTrailingSeparator Include="$([MSBuild]::EnsureTrailingSlash('%(DirsToDelete.Identity)'))" />
<DirsToDeleteWithTrailingSeparator Remove="$(BuildLogsDir)" />
<DirsToDeleteWithTrailingSeparator Remove="$(BuildObjDir)" />
</ItemGroup>
<Message Text="DirSize After Building $(RepositoryName)" Importance="High" Condition="'$(BuildOS)' != 'windows' and '@(DirsToDeleteWithTrailingSeparator)' != ''" />
<Exec Command="df -h $(RepoRoot)" Condition="'$(BuildOS)' != 'windows' and '@(DirsToDeleteWithTrailingSeparator)' != ''" />
<!-- Cleanup everything else -->
<RemoveDir Directories="@(DirsToDeleteWithTrailingSeparator)" />
<Message Text="DirSize After CleanupRepo $(RepositoryName)" Importance="High" Condition="'$(BuildOS)' != 'windows'and '@(DirsToDeleteWithTrailingSeparator)' != ''" />
<Exec Command="df -h $(RepoRoot)" Condition="'$(BuildOS)' != 'windows'and '@(DirsToDeleteWithTrailingSeparator)' != ''" />
</Target>
<Target Name="ExtractToolPackage"
DependsOnTargets="GatherBuiltPackages"
AfterTargets="Build"
Condition="'@(BuiltSdkPackageOverride)' != ''"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)ExtractToolPackage.complete">
<PropertyGroup>
<_ToolPackagesRoot Condition="'$(RepositoryName)' != 'source-build-reference-packages'">$(SourceBuiltPackagesPath)</_ToolPackagesRoot>
<_ToolPackagesRoot Condition="'$(RepositoryName)' == 'source-build-reference-packages'">$(ReferencePackagesDir)</_ToolPackagesRoot>
</PropertyGroup>
<ItemGroup>
<_ToolPackage
Condition="'%(BuiltSdkPackageOverride.Version)' == ''"
Include="$(_ToolPackagesRoot)%(BuiltSdkPackageOverride.Identity)*.nupkg"
Exclude="$(_ToolPackagesRoot)%(BuiltSdkPackageOverride.Identity)*.symbols.nupkg"
Id="%(BuiltSdkPackageOverride.Identity)" />
<_ToolPackage
Condition="'%(BuiltSdkPackageOverride.Version)' != ''"
Include="$(_ToolPackagesRoot)%(BuiltSdkPackageOverride.Identity).%(BuiltSdkPackageOverride.Version).nupkg"
Exclude="$(_ToolPackagesRoot)%(BuiltSdkPackageOverride.Identity).%(BuiltSdkPackageOverride.Version).symbols.nupkg"
Id="%(BuiltSdkPackageOverride.Identity)" />
</ItemGroup>
<Unzip SourceFiles="%(_ToolPackage.Identity)"
DestinationFolder="$(SourceBuiltSdksDir)%(_ToolPackage.Id)\"
SkipUnchangedFiles="true" />
<ItemGroup>
<ExtractedToolFiles Include="$(SourceBuiltSdksDir)%(_ToolPackage.Id)/**/*netcore*/*.dll" />
</ItemGroup>
<Copy SourceFiles="@(ExtractedToolFiles)" DestinationFolder="$(SourceBuiltSdksDir)/" />
<!-- When unpacking, this executable file has the wrong permissions on
non-windows systems: https://github.com/NuGet/Home/issues/13121. -->
<Exec Command="chmod 755 git-clone-to-dir.sh"
Condition=" '%(_ToolPackage.Id)' == 'Microsoft.DotNet.Arcade.Sdk' and !$([MSBuild]::IsOSPlatform(Windows))"
WorkingDirectory="$(SourceBuiltSdksDir)%(_ToolPackage.Id)/tools/SourceBuild/" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)ExtractToolPackage.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<Target Name="EnsurePackagesCreated"
AfterTargets="CopyPackage"
Condition="'$(SkipEnsurePackagesCreated)' != 'true' and '$(IsUtilityProject)' != 'true'"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)EnsurePackagesCreated.complete">
<ItemGroup>
<JustSourceBuiltPackages
Include="$(SourceBuiltPackagesPath)*.nupkg"
Exclude="
$(SourceBuiltPackagesPath)*.symbols.nupkg;
@(PreviouslySourceBuiltPackages)" />
</ItemGroup>
<ItemGroup>
<_PackagesNotCreatedReason Include="^ There may have been a silent failure in the submodule build. To confirm, check the build log file for undetected errors that may have prevented package creation: $(RepoConsoleLogFile)" />
<_PackagesNotCreatedReason Include="^ This error might be a false positive if $(RepositoryName) intentionally builds no nuget packages. If so, set the SkipEnsurePackagesCreated property to true in $(MSBuildProjectFullPath)" />
<_PackagesNotCreatedReason Include="^ The 'bin' directory might be dirty from a previous build and the package files already existed. If so, perform a clean build, or check which packages were already in 'bin' by opening $(CurrentSourceBuiltPackageVersionPropsPath)" />
<_PackagesNotCreatedReason Include="^ The packages may have been written to an unexpected directory. For example, some repos used bin/ and changed to artifacts/ to match Arcade. Check PackagesOutput in $(MSBuildProjectFullPath) (currently '$(PackagesOutput)')" />
</ItemGroup>
<Error Condition="'@(JustSourceBuiltPackages)' == ''"
Text="$(RepositoryName) produced no new source-built package identities. Known possible causes:%0A@(_PackagesNotCreatedReason, '%0A')" />
<ReadNuGetPackageInfos PackagePaths="@(JustSourceBuiltPackages)">
<Output TaskParameter="PackageInfoItems" ItemName="_JustSourceBuiltPackageInfos" />
</ReadNuGetPackageInfos>
<Message Importance="High" Text="New NuGet package(s) after building $(RepositoryName):" />
<Message Importance="High" Text=" -> %(_JustSourceBuiltPackageInfos.PackageId) %(_JustSourceBuiltPackageInfos.PackageVersion)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)EnsurePackagesCreated.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<Target Name="SetSourceBuiltSdkOverrides"
Condition="'@(SourceBuiltSdkOverride)' != ''">
<ItemGroup>
<!-- Set the environment variables for MSBuild to look for our additional SDK Resolvers and or our resolver to find our source-built SDKs. -->
<EnvironmentVariables Include="MSBUILDADDITIONALSDKRESOLVERSFOLDER=$(VSMSBuildSdkResolversDir)" />
<EnvironmentVariables Include="SOURCE_BUILT_SDK_ID_%(SourceBuiltSdkOverride.Group)=%(SourceBuiltSdkOverride.Identity)" />
<EnvironmentVariables Include="SOURCE_BUILT_SDK_VERSION_%(SourceBuiltSdkOverride.Group)=%(SourceBuiltSdkOverride.Version)" />
<EnvironmentVariables Condition="'%(SourceBuiltSdkOverride.Location)' != ''" Include="SOURCE_BUILT_SDK_DIR_%(SourceBuiltSdkOverride.Group)=%(SourceBuiltSdkOverride.Location)/" />
<EnvironmentVariables Condition="'%(SourceBuiltSdkOverride.Location)' == ''" Include="SOURCE_BUILT_SDK_DIR_%(SourceBuiltSdkOverride.Group)=$(SourceBuiltSdksDir)%(SourceBuiltSdkOverride.Identity)/" />
</ItemGroup>
</Target>
<Target Name="WritePrebuiltUsageData"
DependsOnTargets="GetAllProjectDirectories"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)WritePrebuiltUsageData.complete">
<!-- Save the PVP snapshot of each build step to be evaluated while building the report. -->
<ItemGroup>
<PackageVersionPropsSnapshotFiles Include="$(SharedIntermediateOutputPath)PackageVersions.*.Snapshot.props" />
</ItemGroup>
<Copy SourceFiles="@(PackageVersionPropsSnapshotFiles)" DestinationFolder="$(PackageReportDir)snapshots/" />
<ItemGroup>
<AllRestoredPackageFiles Include="$(NuGetPackageRoot)**/*.nupkg" />
<!-- Only contains packages when building. -->
<TarballPrebuiltPackageFiles Include="$(PrebuiltPackagesPath)*.nupkg" />
<SourceBuiltPackageFiles Include="$(SourceBuiltBlobFeedDir)**/*.nupkg" />
<SourceBuiltPackageFiles Include="$(PrebuiltSourceBuiltPackagesPath)*.nupkg" />
<ReferencePackageFiles Include="$(ReferencePackagesDir)**/*.nupkg" />
<!-- Check all RIDs from all restored Microsoft.NETCore.Platforms packages. -->
<PlatformsRuntimeJsonFiles Include="$(NuGetPackageRoot)microsoft.netcore.platforms/*/PortableRuntimeIdentifierGraph.json" />
<!-- Add some other potential top-level project directories for a more specific report. -->
<ProjectDirectories Include="$(SourceBuiltSdksDir);$(TasksDir);$(ArtifactsObjDir)" />
<!-- Finally, scan entire source-build, in case project.assets.json ends up in an unexpected place. -->
<ProjectDirectories Include="$(RepoRoot)" />
</ItemGroup>
<ItemGroup>
<!-- This file is a resource tracked by Git, not generated by restore. Ignore false positive. -->
<IgnoredProjectAssetsJsonFiles Include="$(SrcDir)*nuget-client*/**/test/NuGet.Core.Tests/NuGet.Build.Tasks.Pack.Test/compiler/resources/project.assets.json"/>
</ItemGroup>
<WritePackageUsageData
RestoredPackageFiles="@(AllRestoredPackageFiles)"
TarballPrebuiltPackageFiles="@(TarballPrebuiltPackageFiles)"
SourceBuiltPackageFiles="@(SourceBuiltPackageFiles)"
ReferencePackageFiles="@(ReferencePackageFiles)"
PlatformsRuntimeJsonFiles="@(PlatformsRuntimeJsonFiles)"
TargetRid="$(TargetRid)"
ProjectDirectories="@(ProjectDirectories)"
RootDir="$(RepoRoot)"
IgnoredProjectAssetsJsonFiles="@(IgnoredProjectAssetsJsonFiles)"
DataFile="$(PackageReportDataFile)"
ProjectAssetsJsonArchiveFile="$(ProjectAssetsJsonArchiveFile)" />
<!-- Copy packages detected as prebuilts to the artifacts prebuilt folder -->
<ItemGroup>
<AllowedPackageFiles Include="@(TarballPrebuiltPackageFile)" />
<AllowedPackageFiles Include="@(SourceBuiltPackageFiles)" />
<AllowedPackageFiles Include="@(ReferencePackageFiles)" />
<AllowedPackageFiles>
<LCFilename>$([System.String]::Copy(%(Filename)).ToLowerInvariant())</LCFilename>
</AllowedPackageFiles>
<PrebuiltPackageFiles Include="@(AllRestoredPackageFiles)" >
<LCFilename>$([System.String]::Copy(%(Filename)).ToLowerInvariant())</LCFilename>
</PrebuiltPackageFiles>
<PrebuiltPackageFiles Remove="@(AllowedPackageFiles)" MatchOnMetadata="LCFilename" />
</ItemGroup>
<Copy
SourceFiles="@(PrebuiltPackageFiles)"
DestinationFolder="$(ResultingPrebuiltPackagesDir)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)WritePrebuiltUsageData.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<Target Name="GetAllProjectDirectories">
<ItemGroup>
<AllRepoProjects Include="$(RepoProjectsDir)*.proj" />
</ItemGroup>
<Message Importance="High" Text="Finding project directories..." />
<MSBuild Projects="@(AllRepoProjects)"
Targets="GetProjectDirectory">
<Output TaskParameter="TargetOutputs" ItemName="ProjectDirectories" />
</MSBuild>
</Target>
<Target Name="ReportPrebuiltUsage"
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(BaseIntermediateOutputPath)ReportPrebuiltUsage.complete">
<PropertyGroup>
<FailOnPrebuiltBaselineError Condition="'$(FailOnPrebuiltBaselineError)' == ''">false</FailOnPrebuiltBaselineError>
</PropertyGroup>
<ItemGroup>
<PackageVersionPropsSavedSnapshotFiles Include="$(PackageReportDir)snapshots/PackageVersions.*.Snapshot.props" />
</ItemGroup>
<WriteUsageReports DataFile="$(PackageReportDataFile)"
PackageVersionPropsSnapshots="@(PackageVersionPropsSavedSnapshotFiles)"
ProdConBuildManifestFile="$(ProdConManifestFile)"
PoisonedReportFile="$(PoisonedReportFile)"
OutputDirectory="$(PackageReportDir)" />
<PropertyGroup Condition="'$(ContinueOnPrebuiltBaselineError)' == ''">
<ContinueOnPrebuiltBaselineError>false</ContinueOnPrebuiltBaselineError>
<ContinueOnPrebuiltBaselineError Condition="'$(FailOnPrebuiltBaselineError)' != 'true'">true</ContinueOnPrebuiltBaselineError>
</PropertyGroup>
<ValidateUsageAgainstBaseline
DataFile="$(PackageReportDataFile)"
BaselineDataFile="$(BaselineDataFile)"
OutputBaselineFile="$(PackageReportDir)generated-new-baseline.xml"
OutputReportFile="$(PackageReportDir)baseline-comparison.xml"
AllowTestProjectUsage="$(AllowTestProjectUsage)"
ContinueOnError="$(ContinueOnPrebuiltBaselineError)" />
<MakeDir Directories="$(BaseIntermediateOutputPath)" />
<Touch Files="$(BaseIntermediateOutputPath)ReportPrebuiltUsage.complete" AlwaysCreate="true">
<Output TaskParameter="TouchedFiles" ItemName="FileWrites" />
</Touch>
</Target>
<Target Name="GetProjectDirectory" Outputs="$(ProjectDirectory)" />
<Target Name="GetRepositoryReferences" Outputs="@(RepositoryReference)" />
</Project>