Strong name the build tasks for the IDE (#14080)

* Strong name the MSBuild tasks
* Only sign on Windows
* Also merge the satellite assemblies
* Use a local build of ILRepack
  From https://github.com/mattleibow/il-repack which support portable PDB symbol files.
This commit is contained in:
Matthew Leibowitz 2023-04-14 16:12:31 +02:00 коммит произвёл GitHub
Родитель 22a1cb1c40
Коммит 5c142d5187
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 245 добавлений и 24 удалений

Просмотреть файл

@ -131,6 +131,7 @@
<_MauiBuildTasksLocation>$(_MauiBuildTasksLocation)</_MauiBuildTasksLocation>
<_MauiBuildTasksLocation Condition="'$(_MauiBuildTasksLocation)' == ''">$(MSBuildThisFileDirectory).buildtasks\</_MauiBuildTasksLocation>
<_MauiAOTProfileLocation>$(MauiSrcDirectory)Controls\src\Build.Tasks\nuget\buildTransitive\netstandard2.0\</_MauiAOTProfileLocation>
<StrongNamerKeyFile>$(MauiRootDirectory)eng/microsoft.maui.controls.snk</StrongNamerKeyFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>portable</DebugType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>

Двоичные данные
eng/ILRepack.exe Normal file

Двоичный файл не отображается.

200
eng/ILRepack.targets Normal file
Просмотреть файл

@ -0,0 +1,200 @@
<Project>
<!--
======================================================================
This target ensures that the input is valid.
======================================================================
-->
<Target Name="_ILRepackParameters">
<PropertyGroup>
<!-- The primary assmbly is used for the attributes, TFM, version, and filenames -->
<ILRepackPrimaryAssembly Condition="'$(ILRepackPrimaryAssembly)' == ''">$(OutputPath)$(AssemblyName).dll</ILRepackPrimaryAssembly>
<!-- The output file location, all satellite assemblies will be named this and in this folder -->
<ILRepackOutputAssembly Condition="'$(ILRepackOutputAssembly)' == ''">$(OutputPath)ILRepacked\$(AssemblyName).dll</ILRepackOutputAssembly>
<!-- The output folder for all the related files -->
<ILRepackOutputPath>$([System.IO.Path]::GetDirectoryName($(ILRepackOutputAssembly)))</ILRepackOutputPath>
</PropertyGroup>
</Target>
<!--
======================================================================
This target takes all the imput files and and collects and/or
calculate various related inputs as well as all the outputs.
======================================================================
-->
<Target Name="_ILRepackProperties">
<PropertyGroup>
<!-- NOTE: Strong naming is only supported by the .NET Full Framework and/or on Windows -->
<_ILRepackPerformRepack Condition="'$(OS)' == 'Windows_NT'">true</_ILRepackPerformRepack>
<!-- This is a binary from https://github.com/mattleibow/il-repack which has support for portable PDB -->
<ILRepackPath Condition="'$(ILRepackPath)' == ''">$(MSBuildThisFileDirectory)ILRepack.exe</ILRepackPath>
</PropertyGroup>
<!-- Determine the primary and output assembly names/paths -->
<ItemGroup>
<_ILRepackPrimaryAssembly Include="$(ILRepackPrimaryAssembly)" />
<_ILRepackInputAssemblies Include="@(ILRepackInputAssemblies)" />
<_ILRepackOutputAssembly Include="$(ILRepackOutputAssembly)" />
</ItemGroup>
<ItemGroup>
<_ILRepackAllAssemblies Include="@(_ILRepackPrimaryAssembly->'%(RootDir)%(Directory)%(Filename)%(Extension)')" />
<_ILRepackAllAssemblies Include="@(_ILRepackInputAssemblies->'%(RootDir)%(Directory)%(Filename)%(Extension)')" />
<_ILRepackAllAssembliesPdb Include="@(_ILRepackAllAssemblies->'%(RootDir)%(Directory)%(Filename).pdb')" />
<_ILRepackOutputAssemblyPdb Include="@(_ILRepackOutputAssembly->'%(RootDir)%(Directory)%(Filename).pdb')" />
</ItemGroup>
<!-- Locate the .NET Standard assembly -->
<ItemGroup>
<_NetstandardPath Include="@(ReferencePath->'%(RootDir)%(Directory)')" Condition="'%(FileName)%(Extension)' == 'netstandard.dll'" />
</ItemGroup>
<PropertyGroup>
<_NetstandardDir>@(_NetstandardPath)</_NetstandardDir>
</PropertyGroup>
<!-- Generate the ILRepack args that are common for all assemblies -->
<PropertyGroup>
<_ILRepackCommonArgs>/ver:$(FileVersion) /internalize /keyfile:"$(StrongNamerKeyFile)" /lib:"$(_NetstandardDir.TrimEnd('\'))"</_ILRepackCommonArgs>
</PropertyGroup>
<!-- Collect all the satallite assemblies and "group" into language folders -->
<CreateItem Include="@(_ILRepackAllAssemblies->'%(RootDir)%(Directory)*\%(Filename).resources.dll')">
<Output TaskParameter="Include" ItemName="_ILRepackSatellite" />
</CreateItem>
<ItemGroup>
<_ILRepackSatelliteLanguage Include="@(_ILRepackSatellite->Distinct())" />
<_ILRepackAllSatellites Include="@(_ILRepackSatellite)" />
</ItemGroup>
</Target>
<!--
======================================================================
This target generates all the merged satellite assemblies.
======================================================================
-->
<Target Name="_ILRepackSatelliteAssemblies"
Outputs="%(_ILRepackSatelliteLanguage.Identity)"
DependsOnTargets="_ILRepackProperties"
Condition="@(_ILRepackSatellite->Count()) > 0">
<!-- Calculate the output paths -->
<PropertyGroup>
<_ILRepackLanguage>%(_ILRepackSatelliteLanguage.RecursiveDir)</_ILRepackLanguage>
<_ILRepackLanguageOutput>@(_ILRepackOutputAssembly->'%(RootDir)%(Directory)$(_ILRepackLanguage)%(Filename).resources.dll')</_ILRepackLanguageOutput>
<_ILRepackLanguageOutputDir>@(_ILRepackOutputAssembly->'%(RootDir)%(Directory)$(_ILRepackLanguage)')</_ILRepackLanguageOutputDir>
</PropertyGroup>
<!-- Collect all the assemblies for this language -->
<ItemGroup>
<_ILRepackSatelliteForLanguage Remove="@(_ILRepackSatelliteForLanguage)" />
<_ILRepackSatelliteForLanguage Include="@(_ILRepackAllSatellites)" Condition="'%(_ILRepackAllSatellites.RecursiveDir)' == '$(_ILRepackLanguage)'" />
</ItemGroup>
<!-- Merge the assemblies, if we can -->
<Exec
Command="&quot;$(ILRepackPath)&quot; /out:&quot;$(_ILRepackLanguageOutput)&quot; @(_ILRepackSatelliteForLanguage->'&quot;%(Identity)&quot;', ' ') $(_ILRepackCommonArgs)"
WorkingDirectory="$(TargetDir)"
Condition="'$(_ILRepackPerformRepack)' == 'true'" />
<!-- Otherwise, just copy to the output foler -->
<Copy
SourceFiles="@(_ILRepackSatelliteForLanguage)"
DestinationFolder="$(_ILRepackLanguageOutputDir)"
SkipUnchangedFiles="true"
Condition="'$(_ILRepackPerformRepack)' != 'true'">
<Output TaskParameter="CopiedFiles" ItemName="_ILRepackCopiedFiles" />
</Copy>
<ItemGroup>
<_ILRepackCopiedFiles Include="$(_ILRepackLanguageOutput)" />
<FileWrites Include="@(_ILRepackCopiedFiles)" />
</ItemGroup>
</Target>
<!--
======================================================================
This target generates the merged primary assembly.
======================================================================
-->
<Target Name="_ILRepackAssemblies"
DependsOnTargets="_ILRepackProperties">
<!-- Merge the assemblies, if we can -->
<Exec
Command="&quot;$(ILRepackPath)&quot; /out:&quot;@(_ILRepackOutputAssembly->'%(RootDir)%(Directory)%(Filename)%(Extension)')&quot; @(_ILRepackAllAssemblies->'&quot;%(Identity)&quot;', ' ') $(_ILRepackCommonArgs)"
WorkingDirectory="$(TargetDir)"
Condition="'$(_ILRepackPerformRepack)' == 'true'" />
<!-- Otherwise, just copy to the output foler -->
<Copy
SourceFiles="@(_ILRepackAllAssemblies);@(_ILRepackAllAssembliesPdb)"
DestinationFolder="$(ILRepackOutputPath)"
SkipUnchangedFiles="true"
Condition="'$(_ILRepackPerformRepack)' != 'true'">
<Output TaskParameter="CopiedFiles" ItemName="_ILRepackCopiedFiles" />
</Copy>
<Touch Files="$(IntermediateOutputPath)ILRepacker.stamp" AlwaysCreate="True" />
<ItemGroup>
<_ILRepackCopiedFiles Include="$(_ILRepackOutputAssembly);@(_ILRepackOutputAssemblyPdb)" />
<FileWrites Include="$(IntermediateOutputPath)ILRepacker.stamp;@(_ILRepackCopiedFiles)" />
</ItemGroup>
</Target>
<!--
======================================================================
This target initiates the merge of both the primary and
satellite assemblies.
======================================================================
-->
<Target Name="_ILRepack"
Inputs="$(MSBuildAllProjects);@(ILRepackPrimaryAssembly);@(ILRepackInputAssemblies)"
Outputs="$(IntermediateOutputPath)ILRepacker.stamp"
DependsOnTargets="_ILRepackAssemblies;_ILRepackSatelliteAssemblies">
<ItemGroup>
<ILRepackOutput Include="$(ILRepackOutputPath)\**" />
</ItemGroup>
</Target>
<!--
======================================================================
This target is meant to be replaced by a project-specific target
and will run before any merging takes place.
======================================================================
-->
<Target Name="BeforeILRepack" />
<!--
======================================================================
This target is meant to be replaced by a project-specific target
and will run after all merging has taken place.
======================================================================
-->
<Target Name="AfterILRepack" />
<!--
======================================================================
This target is the main entrypoint for doing assembly merges.
======================================================================
-->
<Target Name="ILRepack"
DependsOnTargets="BeforeILRepack;_ILRepackParameters;_ILRepack;AfterILRepack" />
<!--
======================================================================
This target can be used to automatically enable merging as part of
the build process using the `$(ILRepackBeforePack)` property.
======================================================================
-->
<Target Name="_ILRepackBeforeNuGetPack"
AfterTargets="Build"
Condition="'$(ILRepackBeforePack)' == 'True'"
DependsOnTargets="ILRepack" />
</Project>

Просмотреть файл

@ -9,14 +9,17 @@
<IsPackable>true</IsPackable>
<!-- Suppresses the warnings about the package not having assemblies in lib/*/.dll.-->
<NoPackageAnalysis>true</NoPackageAnalysis>
<!-- Change the default location where NuGet will put the build output -->
<BuildOutputTargetFolder>buildTransitive</BuildOutputTargetFolder>
<!-- Do not include any assemblies from this project as we will do it manually -->
<IncludeBuildOutput>false</IncludeBuildOutput>
<!-- Make sure to copy all the NuGet files into the build output -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!-- ILRepack this assembly and add a strong name and version -->
<ILRepackBeforePack>true</ILRepackBeforePack>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mono.Cecil" Version="0.11.4" PrivateAssets="all" />
<PackageReference Include="Mono.Cecil" Version="0.11.4" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="System.CodeDom" Version="7.0.0" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.Build" Version="15.9.20" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" Version="15.9.20" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.9.20" PrivateAssets="all" />
@ -30,6 +33,18 @@
</ItemGroup>
<ItemGroup>
<None Include="$(PkgMono_Cecil)\lib\netstandard2.0\Mono.Cecil.dll" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="$(PkgMono_Cecil)\lib\netstandard2.0\Mono.Cecil.pdb" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="$(PkgMono_Cecil)\lib\netstandard2.0\Mono.Cecil.Mdb.dll" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="$(PkgMono_Cecil)\lib\netstandard2.0\Mono.Cecil.Mdb.pdb" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="$(PkgMono_Cecil)\lib\netstandard2.0\Mono.Cecil.Pdb.dll" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="$(PkgMono_Cecil)\lib\netstandard2.0\Mono.Cecil.Pdb.pdb" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="$(PkgMono_Cecil)\lib\netstandard2.0\Mono.Cecil.Rocks.dll" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="$(PkgMono_Cecil)\lib\netstandard2.0\Mono.Cecil.Rocks.pdb" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="$(PkgSystem_CodeDom)\lib\netstandard2.0\System.CodeDom.dll" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="..\SourceGen\bin\$(Configuration)\netstandard2.0\Microsoft.Maui.Controls.SourceGen.dll" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Include="..\SourceGen\bin\$(Configuration)\netstandard2.0\Microsoft.Maui.Controls.SourceGen.pdb" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0" />
<None Remove="$(OutputPath)*.xml" />
<None Include="nuget\**" PackagePath="" Pack="true" Exclude="nuget\**\*.aotprofile.txt" />
</ItemGroup>
@ -55,22 +70,17 @@
<Copy SourceFiles="@(_CopyItems)" DestinationFolder="$(_MauiBuildTasksLocation)%(RecursiveDir)" ContinueOnError="true" Retries="0" />
</Target>
<!-- Add additional packages to the NuGet -->
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>
$(TargetsForTfmSpecificBuildOutput);
_MauiPackAdditionalAssemblies
</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="_MauiPackAdditionalAssemblies">
<ItemGroup>
<ILRepackInputAssemblies Include="$(TargetDir)Microsoft.Maui.Graphics.dll" />
<ILRepackInputAssemblies Include="$(TargetDir)Microsoft.Maui.Essentials.dll" />
<ILRepackInputAssemblies Include="$(TargetDir)Microsoft.Maui.dll" />
<ILRepackInputAssemblies Include="$(TargetDir)Microsoft.Maui.Controls.dll" />
<ILRepackInputAssemblies Include="$(TargetDir)Microsoft.Maui.Controls.Xaml.dll" />
</ItemGroup>
<Import Project="$(MauiRootDirectory)eng\ILRepack.targets" />
<Target Name="AfterILRepack">
<ItemGroup>
<BuildOutputInPackage Include="..\SourceGen\bin\$(Configuration)\netstandard2.0\Microsoft.Maui.Controls.SourceGen.dll" />
<BuildOutputInPackage Include="..\SourceGen\bin\$(Configuration)\netstandard2.0\Microsoft.Maui.Controls.SourceGen.pdb" />
<BuildOutputInPackage Include="$(OutputPath)Microsoft.Maui.*" />
<BuildOutputInPackage Include="$(OutputPath)Mono.Cecil.*" />
<BuildOutputInPackage Include="$(OutputPath)System.CodeDom.*" />
<BuildOutputInPackage Remove="$(OutputPath)$(AssemblyName).*" />
<BuildOutputInPackage Remove="$(OutputPath)*.xml" />
<None Include="@(ILRepackOutput)" Visible="false" Pack="true" PackagePath="buildTransitive\netstandard2.0\%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
</Target>

Просмотреть файл

@ -12,18 +12,32 @@
<NoPackageAnalysis>true</NoPackageAnalysis>
<!-- Do not include any assemblies from this project as we will do it manually -->
<IncludeBuildOutput>false</IncludeBuildOutput>
<!-- ILRepack this assembly and add a strong name and version -->
<ILRepackBeforePack>true</ILRepackBeforePack>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="15.9.20" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" Version="15.9.20" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.9.20" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.9.20" PrivateAssets="all" />
</ItemGroup>
<Import Project="ResizetizerPackages.projitems" />
<Import Project="$(MauiRootDirectory)eng\ILRepack.targets" />
<Target Name="AfterILRepack">
<ItemGroup>
<None Include="@(ILRepackOutput)" Visible="false" Pack="true" PackagePath="buildTransitive\%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
</Target>
<ItemGroup>
<None Include="@(_ResizetizerFiles)" Visible="false" Pack="true" PackagePath="buildTransitive/%(Arch)" />
<None Include="$(OutputPath)$(AssemblyName).dll" Visible="false" Pack="true" PackagePath="buildTransitive" />
<None Include="$(OutputPath)$(AssemblyName).pdb" Visible="false" Pack="true" PackagePath="buildTransitive" />
<None Include="nuget\**" Pack="true" PackagePath="" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

Просмотреть файл

@ -7,8 +7,6 @@
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="$(_HarfBuzzSharpVersion)" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Win32" Version="$(_HarfBuzzSharpVersion)" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.macOS" Version="$(_HarfBuzzSharpVersion)" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Framework" Version="16.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.7.0" PrivateAssets="all" />
<PackageReference Include="SkiaSharp" Version="$(_SkiaSharpVersion)" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="$(_SkiaSharpVersion)" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="SkiaSharp.NativeAssets.macOS" Version="$(_SkiaSharpVersion)" GeneratePathProperty="true" PrivateAssets="all" />
@ -29,8 +27,6 @@
<PackageReference Include="System.Numerics.Vectors" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" GeneratePathProperty="true" PrivateAssets="all" />
<PackageReference Include="System.ObjectModel" GeneratePathProperty="true" PrivateAssets="all" />
<!-- "temporary" build hacks -->
<PackageReference Include="Mono.ApiTools.MSBuildTasks" Version="0.1.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>