aspnetcore/build/SharedFx.targets

281 lines
14 KiB
XML

<Project>
<Import Project="common.props" />
<Import Project="SharedFx.props" />
<PropertyGroup>
<SharedFxOutputPath>$([MSBuild]::NormalizeDirectory($(ArtifactsDir)))assets\Runtime\$(PackageVersion)\</SharedFxOutputPath>
</PropertyGroup>
<Target Name="BuildMetapackage" DependsOnTargets="ResolveRepoInfo">
<!-- Clear working directory -->
<RemoveDir Directories="$(_WorkRoot)" />
<PropertyGroup>
<MetapackageWorkDirectory>$(_WorkRoot)Microsoft.AspNetCore.All\</MetapackageWorkDirectory>
<_SharedFxProps>Configuration=$(Configuration);DotNetRestoreSourcePropsPath=$(GeneratedRestoreSourcesPropsPath);AspNetUniverseBuildOffline=true</_SharedFxProps>
<_SharedFxProps>$(_SharedFxProps);RuntimeFrameworkVersion=$(MicrosoftNETCoreApp21PackageVersion)</_SharedFxProps>
</PropertyGroup>
<ItemGroup>
<AllMetapackageFiles Include="$(_AllMetapackageDir)**\*" />
</ItemGroup>
<!-- Move to working dir -->
<Copy SourceFiles="@(AllMetapackageFiles)" DestinationFolder="$(MetapackageWorkDirectory)\%(RecursiveDir)" />
<Copy SourceFiles="$(_SrcDir)Directory.Build.props" DestinationFolder="$(_WorkRoot)" />
<!-- Add references to project -->
<RepoTasks.AddMetapackageReferences
ReferencePackagePath="$(MetapackageWorkDirectory)Microsoft.AspNetCore.All.csproj"
BuildArtifacts="@(ArtifactInfo)"
PackageArtifacts="@(PackageArtifact)"
ExternalDependencies="@(ExternalDependency)" />
<!-- Set _Target=Restore so the project will be re-evaluated to include Internal.AspNetCore.Sdk MSBuild properties on the next step. -->
<MSBuild Projects="$(MetapackageWorkDirectory)Microsoft.AspNetCore.All.csproj" Targets="Restore" Properties="$(_SharedFxProps);_Target=Restore" />
<!-- Pack -->
<MSBuild Projects="$(MetapackageWorkDirectory)Microsoft.AspNetCore.All.csproj" Targets="Pack" Properties="$(_SharedFxProps);PackageOutputPath=$(BuildDir)" />
</Target>
<Target Name="PrepareForSharedFx">
<PropertyGroup>
<RIDIsAcceptable Condition="'%(AllSharedFxRIDs.Identity)' == '$(SharedFxRID)'">true</RIDIsAcceptable>
</PropertyGroup>
<Error Text="&quot;$(SharedFxRID)&quot; not acceptable as a SharedFxRID, please specify an acceptable value: {@(AllSharedFxRIDs)}." Condition="'$(RIDIsAcceptable)' != 'true'"/>
<!-- Clear working directory -->
<RemoveDir Directories="$(_WorkRoot)" />
<PropertyGroup>
<SharedFxWorkDirectory>$(_WorkRoot)SharedFx\</SharedFxWorkDirectory>
<SharedFxIntermediateOutputPath>$(_WorkRoot)Publish\</SharedFxIntermediateOutputPath>
<SharedFxCrossGenDirectory>$(_WorkRoot)CrossGen\</SharedFxCrossGenDirectory>
<SharedFxCrossGenSymbolsDirectory>$(_WorkRoot)CrossGenSymbols\</SharedFxCrossGenSymbolsDirectory>
<SharedFxCrossGenToolDirectory>$(_WorkRoot)CrossGenTool\</SharedFxCrossGenToolDirectory>
<SharedFxCrossGenRspDirectory>$(_WorkRoot)CrossGenRsp\</SharedFxCrossGenRspDirectory>
<SharedFxPublishDirectory>$(SharedFxIntermediateOutputPath)shared\Microsoft.AspNetCore.All\$(PackageVersion)\</SharedFxPublishDirectory>
<SharedFxRestoreRid>$(SharedFxRID)</SharedFxRestoreRid>
<!-- Required because SQLitePCLRaw 1.1.8 uses win7-x64/win7-x86 as its RIDs, even though the e_sqlite3.dll file works on all supported win-x64/win-x86 platforms. -->
<SharedFxRestoreRid Condition="'$(SharedFxRID)' == 'win-x64'">win7-x64</SharedFxRestoreRid>
<SharedFxRestoreRid Condition="'$(SharedFxRID)' == 'win-x86'">win7-x86</SharedFxRestoreRid>
<_SharedFxProps>Configuration=$(Configuration);RuntimeIdentifier=$(SharedFxRestoreRid)</_SharedFxProps>
<_SharedFxProps>$(_SharedFxProps);RuntimeFrameworkVersion=$(MicrosoftNETCoreApp21PackageVersion)</_SharedFxProps>
<_SharedFxProps>$(_SharedFxProps);DotNetRestoreSourcePropsPath=$(GeneratedRestoreSourcesPropsPath)</_SharedFxProps>
<_SharedFxProps>$(_SharedFxProps);AspNetUniverseBuildOffline=true</_SharedFxProps>
</PropertyGroup>
<!-- Move to working dir -->
<ItemGroup>
<SharedFxFiles Include="$(_TemplatesDir)SharedFx\**\*" />
</ItemGroup>
<Copy SourceFiles="@(SharedFxFiles)" DestinationFolder="$(SharedFxWorkDirectory)\%(RecursiveDir)" />
<Copy SourceFiles="$(_SrcDir)Directory.Build.props" DestinationFolder="$(_WorkRoot)" />
<!-- Set _Target=Restore so the project will be re-evaluated to include Internal.AspNetCore.Sdk MSBuild properties on the next step. -->
<MSBuild Projects="$(SharedFxWorkDirectory)SharedFx.csproj"
Targets="Restore"
Properties="$(_SharedFxProps);MicrosoftAspNetCoreAllVersion=$(PackageVersion);_Target=Restore" />
</Target>
<Target Name="ResolveSharedFxFiles" DependsOnTargets="PrepareForSharedFx;ResolveCommitHash">
<!-- Publish -->
<MSBuild Projects="$(SharedFxWorkDirectory)SharedFx.csproj"
Targets="Publish"
Properties="$(_SharedFxProps);GenerateRuntimeConfigurationFiles=true;SelfContained=false;PublishDir=$(SharedFxPublishDirectory)" />
<!-- Clean deps.json -->
<RepoTasks.TrimDeps DepsFiles="$(SharedFxPublishDirectory)/SharedFx.deps.json" />
<!-- Clean up artifacts that publish generates which we don't need -->
<ItemGroup>
<ToDelete Include="$(SharedFxPublishDirectory)\SharedFx" />
<ToDelete Include="$(SharedFxPublishDirectory)\SharedFx.dll" />
<ToDelete Include="$(SharedFxPublishDirectory)\SharedFx.pdb" />
</ItemGroup>
<Delete Files="@(ToDelete)" />
<!-- Rename deps file -->
<Move SourceFiles="$(SharedFxPublishDirectory)\SharedFx.deps.json"
DestinationFiles="$(SharedFxPublishDirectory)\Microsoft.AspNetCore.All.deps.json" />
<!-- Rename runtimeconfig.json file -->
<Move SourceFiles="$(SharedFxPublishDirectory)\SharedFx.runtimeconfig.json"
DestinationFiles="$(SharedFxPublishDirectory)\Microsoft.AspNetCore.All.runtimeconfig.json" />
<!-- Generate Runtime Graph -->
<PropertyGroup>
<RuntimeGraphGeneratorRuntime Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</RuntimeGraphGeneratorRuntime>
<RuntimeGraphGeneratorRuntime Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</RuntimeGraphGeneratorRuntime>
<RuntimeGraphGeneratorRuntime Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</RuntimeGraphGeneratorRuntime>
</PropertyGroup>
<ItemGroup>
<SharedFxAssetsFile Include="$(SharedFxWorkDirectory)**\project.assets.json" />
</ItemGroup>
<ProcessSharedFrameworkDeps
AssetsFilePath="@(SharedFxAssetsFile)"
DepsFilePath="$(SharedFxPublishDirectory)\Microsoft.AspNetCore.All.deps.json"
Runtime="$(RuntimeGraphGeneratorRuntime)" />
<!-- Generate .version file -->
<ItemGroup>
<VersionLines Include="$(CommitHash)" />
<VersionLines Include="$(PackageVersion)" />
</ItemGroup>
<WriteLinesToFile
File="$(SharedFxPublishDirectory)\.version"
Lines="@(VersionLines)"
Overwrite="true" />
<MakeDir Directories="$(SharedFxOutputPath)" />
</Target>
<Target Name="PrepareForCrossGen" DependsOnTargets="PrepareForSharedFx;ResolveSharedFxFiles">
<PropertyGroup>
<RuntimePackageName>Microsoft.NETCore.App</RuntimePackageName>
<CrossGenTool>crossgen</CrossGenTool>
<CrossGenTool Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(CrossGenTool).exe</CrossGenTool>
<LibPrefix Condition="$([MSBuild]::IsOSPlatform('Linux')) OR $([MSBuild]::IsOSPlatform('OSX'))">lib</LibPrefix>
<LibExtension>.so</LibExtension>
<LibExtension Condition="$([MSBuild]::IsOSPlatform('Windows'))">.dll</LibExtension>
<LibExtension Condition="$([MSBuild]::IsOSPlatform('OSX'))">.dylib</LibExtension>
</PropertyGroup>
<!-- Determine runtime location -->
<MSBuild Projects="$(SharedFxWorkDirectory)SharedFx.csproj" Targets="GetPackageDefinitions" >
<Output TaskParameter="TargetOutputs" ItemName="PackageDefinitions" />
</MSBuild>
<ItemGroup>
<RuntimePackage Include="@(PackageDefinitions)" Condition="$([System.String]::new('%(PackageDefinitions.Name)').Contains('runtime')) AND $([System.String]::new('%(PackageDefinitions.Name)').Contains('$(RuntimePackageName)'))" />
<RuntimePackageFiles Include="%(RuntimePackage.ResolvedPath)\runtimes\**\*" />
<CrossGenToolFile Include="%(RuntimePackage.ResolvedPath)\**\$(CrossGenTool)" />
</ItemGroup>
<!-- Create tool directory with crossgen executable and runtime assemblies -->
<Copy SourceFiles="@(RuntimePackageFiles);@(CrossGenToolFile)" DestinationFolder="$(SharedFxCrossGenToolDirectory)"/>
<ItemGroup>
<ClrJitAssembly Include="$(SharedFxCrossGenToolDirectory)\**\$(LibPrefix)clrjit$(LibExtension)" />
</ItemGroup>
<Error Text="Expected to resolve a single runtime package but instead resolved @(RuntimePackage->Count()) with identities %(RuntimePackage.Identity)" Condition="'@(RuntimePackage->Count())' != 1" />
<Error Text="Expected to resolve a single clr jit assembly but instead resolved @(ClrJitAssembly->Count()) with identities %(ClrJitAssembly.Identity)" Condition="'@(ClrJitAssembly->Count())' != 1" />
<!-- Gather details on published assemblies -->
<MSBuild Projects="$(SharedFxWorkDirectory)SharedFx.csproj"
Targets="GetPublishAssemblies"
Properties="RuntimeIdentifier=$(SharedFxRestoreRid);SelfContained=false" >
<Output TaskParameter="TargetOutputs" ItemName="PublishAssemblies" />
</MSBuild>
<ItemGroup>
<IgnoredAssemblies Include="@(PublishAssemblies)" Condition="'%(AssetType)' == 'native' OR '%(AssetType)' == 'resources'" />
<_AssembliesToCrossgen Include="$(SharedFxPublishDirectory)**\*.dll" />
</ItemGroup>
<!-- Compute the intersection of crossgen candidates and native/resources assemblies as the set of assemblies to skip crossgen -->
<CreateItem Include="@(_AssembliesToCrossgen)" Condition="'%(Filename)' != ''and '@(IgnoredAssemblies)' != ''">
<Output TaskParameter="Include" ItemName="AssembliesToRemove"/>
</CreateItem>
<!-- Resolve list of assemblies to crossgen -->
<ItemGroup>
<AssembliesToCrossgen Include="@(_AssembliesToCrossgen)">
<Source>%(FullPath)</Source>
<Rsp>$(SharedFxCrossGenRspDirectory)%(RecursiveDir)%(Filename).rsp</Rsp>
<SymbolsRsp>$(SharedFxCrossGenRspDirectory)%(RecursiveDir)%(Filename).symbols.rsp</SymbolsRsp>
<Destination>$(SharedFxCrossGenDirectory)%(RecursiveDir)%(Filename)%(Extension)</Destination>
<Symbols>$(SharedFxCrossGenDirectory)%(RecursiveDir)</Symbols>
</AssembliesToCrossgen>
<AssembliesToCrossgen Remove="@(AssembliesToRemove)" />
</ItemGroup>
</Target>
<Target Name="CrossGenAssemblies"
DependsOnTargets="PrepareForCrossGen"
Inputs="@(AssembliesToCrossgen)"
Outputs="%(AssembliesToCrossgen.Destination)">
<ItemGroup>
<CrossGenArgs Include="-nologo" />
<CrossGenArgs Include="-readytorun" />
<CrossGenArgs Include="-in %(AssembliesToCrossgen.Source)" />
<CrossGenArgs Include="-out %(AssembliesToCrossgen.Destination)" />
<CrossGenArgs Include="-platform_assemblies_paths $(SharedFxPublishDirectory)$(PathSeparator)$(SharedFxCrossGenToolDirectory)" />
<CrossGenArgs Include="-JITPath %(ClrJitAssembly.FullPath)" />
</ItemGroup>
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('%(AssembliesToCrossgen.Rsp)'))" />
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('%(AssembliesToCrossgen.Destination)'))" />
<WriteLinesToFile File="%(AssembliesToCrossgen.Rsp)" Lines="@(CrossGenArgs)" Overwrite="true" />
<Exec Command="$(SharedFxCrossGenToolDirectory)$(CrossGenTool) @%(AssembliesToCrossgen.Rsp)" EnvironmentVariables="COMPlus_PartialNGen=0" />
</Target>
<Target Name="CrossGenSymbols"
Condition="$([MSBuild]::IsOSPlatform('Linux')) OR $([MSBuild]::IsOSPlatform('Windows'))"
DependsOnTargets="CrossGenAssemblies"
Inputs="@(AssembliesToCrossgen)"
Outputs="%(AssembliesToCrossgen.SymbolsRsp)">
<PropertyGroup>
<CrossGenSymbolsType>CreatePerfMap</CrossGenSymbolsType>
<CrossGenSymbolsType Condition="'$(OS)' == 'Windows_NT'">CreatePDB</CrossGenSymbolsType>
</PropertyGroup>
<ItemGroup>
<CrossGenSymbolsArgs Include="-nologo" />
<CrossGenSymbolsArgs Include="-readytorun" />
<CrossGenSymbolsArgs Include="-platform_assemblies_paths $(SharedFxPublishDirectory)$(PathSeparator)$(SharedFxCrossGenToolDirectory)" />
<CrossGenSymbolsArgs Include="-$(CrossGenSymbolsType)" />
<CrossGenSymbolsArgs Include="%(AssembliesToCrossgen.Symbols)" />
<CrossGenSymbolsArgs Include="%(AssembliesToCrossgen.Destination)" />
</ItemGroup>
<MakeDir Directories="$([System.IO.Path]::GetDirectoryName('%(AssembliesToCrossgen.Symbols)'))" />
<WriteLinesToFile File="%(AssembliesToCrossgen.SymbolsRsp)" Lines="@(CrossGenSymbolsArgs)" Overwrite="true" />
<Exec Command="$(SharedFxCrossGenToolDirectory)$(CrossGenTool) @%(AssembliesToCrossgen.SymbolsRsp)" EnvironmentVariables="COMPlus_PartialNGen=0" />
</Target>
<Target Name="PackSharedFx">
<ItemGroup>
<CrossGenOutput Include="$(SharedFxCrossGenDirectory)**\*.dll" />
<CrossGenSymbols Include="$(SharedFxCrossGenDirectory)**\*" Exclude="@(CrossGenOutput)" />
</ItemGroup>
<!-- Create symbols archive -->
<ZipArchive
File="$(SharedFxOutputPath)$(SharedFxInstallerName)-symbols-$(PackageVersion)-$(SharedFxRID).zip"
SourceFiles="@(CrossGenSymbols)"
WorkingDirectory="$(SharedFxCrossGenDirectory)"
Overwrite="true"
Condition="$([MSBuild]::IsOSPlatform('Linux')) OR $([MSBuild]::IsOSPlatform('Windows'))"/>
<!-- Replace assemblies with crossgen output -->
<Copy
SourceFiles="$(SharedFxCrossGenDirectory)%(CrossGenOutput.RecursiveDir)%(CrossGenOutput.FileName)%(CrossGenOutput.Extension)"
DestinationFiles="$(SharedFxPublishDirectory)%(CrossGenOutput.RecursiveDir)%(CrossGenOutput.FileName)%(CrossGenOutput.Extension)"
OverwriteReadOnlyFiles="True" />
<ItemGroup>
<OutputZipFiles Include="$(SharedFxIntermediateOutputPath)**\*" />
</ItemGroup>
<!-- Create archive -->
<ZipArchive
File="$(SharedFxOutputPath)$(SharedFxIntermediateArchiveBaseName)-$(PackageVersion)-$(SharedFxRID).zip"
SourceFiles="@(OutputZipFiles)"
WorkingDirectory="$(SharedFxIntermediateOutputPath)"
Overwrite="true"/>
</Target>
<Target Name="BuildSharedFx" DependsOnTargets="ResolveSharedFxFiles;CrossGenAssemblies;CrossGenSymbols;PackSharedFx"/>
</Project>