1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-09 17:44:48 +09:00

Move reference assembly logic into root msbuild files (#79268)

* Move reference assembly logic into root msbuild files

That allows other components like the linker that don't reside under src/libraries to build reference assemblies without duplicating the infrastructure.
This commit is contained in:
Viktor Hofer 2022-12-06 14:40:19 +01:00 committed by GitHub
parent 89938fd6d7
commit b4a0be4516
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 64 additions and 67 deletions

View file

@ -41,6 +41,13 @@
<Platform Condition="'$(Platform)' == '' and '$(InferPlatformFromTargetArchitecture)' == 'true'">$(TargetArchitecture)</Platform>
</PropertyGroup>
<PropertyGroup>
<!-- Set OutDirName (Arcade specific property that must be set before the Arcade SDK is imported) to change the BaseOutputPath and
BaseIntermediateOutputPath properties to include the ref subfolder. -->
<IsReferenceAssemblyProject Condition="$([System.IO.Path]::GetFileName('$(MSBuildProjectDirectory)')) == 'ref'">true</IsReferenceAssemblyProject>
<OutDirName Condition="'$(IsReferenceAssemblyProject)' == 'true'">$(MSBuildProjectName)$([System.IO.Path]::DirectorySeparatorChar)ref</OutDirName>
</PropertyGroup>
<!-- Import the Arcade SDK -->
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />
@ -319,6 +326,31 @@
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(IsReferenceAssemblyProject)' == 'true'">
<!-- Reference assemblies are special and don't initialize fields or have empty finalizers, etc. -->
<RunAnalyzers>false</RunAnalyzers>
<!-- disable warnings about unused fields -->
<NoWarn>$(NoWarn);CS0169;CS0649;CS8618</NoWarn>
<!-- disable CS8597 because we throw null on reference assemblies. -->
<NoWarn>$(NoWarn);CS8597</NoWarn>
<!-- We base calls from constructors with null literals. -->
<NoWarn>$(NoWarn);CS8625</NoWarn>
<!-- We dont need to add null annotation within the ref for explicit interface methods. -->
<NoWarn>$(NoWarn);CS8617</NoWarn>
<!-- No symbols are produced for ref assemblies, but some parts of the SDK still expect pdbs, so we explicitly tell it there are none. -->
<!-- Must be set after importing Arcade to override its defaults. -->
<DebugType>none</DebugType>
</PropertyGroup>
<!-- All reference assemblies should have a ReferenceAssemblyAttribute and the 0x70 flag which prevents them from loading. -->
<ItemGroup Condition="'$(IsReferenceAssemblyProject)' == 'true'">
<AssemblyAttribute Include="System.Runtime.CompilerServices.ReferenceAssemblyAttribute" />
<AssemblyAttribute Include="System.Reflection.AssemblyFlags">
<_Parameter1>(System.Reflection.AssemblyNameFlags)0x70</_Parameter1>
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
</AssemblyAttribute>
</ItemGroup>
<PropertyGroup>
<CustomBeforeNoTargets>$(RepositoryEngineeringDir)NoTargetsSdk.BeforeTargets.targets</CustomBeforeNoTargets>
<CustomAfterNoTargets>$(RepositoryEngineeringDir)NoTargetsSdk.AfterTargets.targets</CustomAfterNoTargets>

View file

@ -76,6 +76,37 @@
<Description>$(PackageDescription)</Description>
</PropertyGroup>
<ItemDefinitionGroup>
<TargetPathWithTargetPlatformMoniker>
<IsReferenceAssemblyProject>$(IsReferenceAssemblyProject)</IsReferenceAssemblyProject>
</TargetPathWithTargetPlatformMoniker>
</ItemDefinitionGroup>
<Target Name="ValidateReferenceAssemblyProjectReferencesAndTargetFramework"
AfterTargets="ResolveReferences"
Condition="'$(IsReferenceAssemblyProject)' == 'true' and
'$(SkipValidateReferenceAssemblyProjectReferences)' != 'true'">
<Error Text="Reference assemblies must only reference other reference assemblies and '%(ReferencePath.ProjectReferenceOriginalItemSpec)' is not a reference assembly project and does not set 'ProduceReferenceAssembly'."
Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IsReferenceAssemblyProject)' != 'true' and '%(ReferencePath.ReferenceAssembly)' == ''" />
<Error Text="Reference assemblies must be TargetPlatform agnostic. $(MSBuildProjectName) incorrectly targets $(TargetFramework), platform: $(TargetPlatformIdentifier)."
Condition="'$(TargetPlatformIdentifier)' != ''" />
</Target>
<!-- For experimental ref assemblies (which typically have the same name as a regular ref
assembly), bump their minor file version by 100 to make it distinguishable from the regular
ref assembly. -->
<Target Name="UpdateExperimentalRefAssemblyFileVersion"
AfterTargets="_InitializeAssemblyVersion"
Condition="'$(IsReferenceAssemblyProject)' == 'true' and '$(IsExperimentalRefAssembly)' == 'true'">
<PropertyGroup>
<_FileVersionMaj>$(FileVersion.Split('.')[0])</_FileVersionMaj>
<_FileVersionMin>$(FileVersion.Split('.')[1])</_FileVersionMin>
<_FileVersionBld>$(FileVersion.Split('.')[2])</_FileVersionBld>
<_FileVersionRev>$(FileVersion.Split('.')[3])</_FileVersionRev>
<FileVersion>$(_FileVersionMaj).$([MSBuild]::Add($(_FileVersionMin), 100)).$(_FileVersionBld).$(_FileVersionRev)</FileVersion>
</PropertyGroup>
</Target>
<!--
Arcade SDK versioning is defined by static properties in a targets file: work around this by
moving properties based on versioning into a target.

View file

@ -1,29 +0,0 @@
<Project>
<PropertyGroup>
<!-- Reference assemblies are special and don't initialize fields or have empty finalizers, etc. -->
<RunAnalyzers>false</RunAnalyzers>
<!-- disable warnings about unused fields -->
<NoWarn>$(NoWarn);CS0169;CS0649;CS8618</NoWarn>
<!-- disable CS8597 because we throw null on reference assemblies. -->
<NoWarn>$(NoWarn);CS8597</NoWarn>
<!-- We base calls from constructors with null literals. -->
<NoWarn>$(NoWarn);CS8625</NoWarn>
<!-- We dont need to add null annotation within the ref for explicit interface methods. -->
<NoWarn>$(NoWarn);CS8617</NoWarn>
</PropertyGroup>
<!-- All reference assemblies should have a ReferenceAssemblyAttribute and the 0x70 flag which prevents them from loading. -->
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.ReferenceAssemblyAttribute" />
<AssemblyAttribute Include="System.Reflection.AssemblyFlags">
<_Parameter1>(System.Reflection.AssemblyNameFlags)0x70</_Parameter1>
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
</AssemblyAttribute>
</ItemGroup>
</Project>

View file

@ -79,22 +79,6 @@
</ItemGroup>
</Target>
<ItemDefinitionGroup>
<TargetPathWithTargetPlatformMoniker>
<IsReferenceAssemblyProject>$(IsReferenceAssemblyProject)</IsReferenceAssemblyProject>
</TargetPathWithTargetPlatformMoniker>
</ItemDefinitionGroup>
<Target Name="ValidateReferenceAssemblyProjectReferencesAndTargetFramework"
AfterTargets="ResolveReferences"
Condition="'$(IsReferenceAssemblyProject)' == 'true' and
'$(SkipValidateReferenceAssemblyProjectReferences)' != 'true'">
<Error Text="Reference assemblies must only reference other reference assemblies and '%(ReferencePath.ProjectReferenceOriginalItemSpec)' is not a reference assembly project and does not set 'ProduceReferenceAssembly'."
Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IsReferenceAssemblyProject)' != 'true' and '%(ReferencePath.ReferenceAssembly)' == ''" />
<Error Text="Reference assemblies must be TargetPlatform agnostic. $(MSBuildProjectName) incorrectly targets $(TargetFramework), platform: $(TargetPlatformIdentifier)."
Condition="'$(TargetPlatformIdentifier)' != ''" />
</Target>
<!-- An opt-in target to trim out private assemblies from the ref assembly ReferencePath. -->
<Target Name="TrimOutPrivateAssembliesFromReferencePath"
Condition="'$(CompileUsingReferenceAssemblies)' == 'true' and '$(TrimOutPrivateAssembliesFromReferencePath)' == 'true'"
@ -114,19 +98,4 @@
<ReferencePathWithRefAssemblies Include="@(_resolvedCoreLibProjectReference->Metadata('ReferenceAssembly'))" />
</ItemGroup>
</Target>
<!-- For experimental ref assemblies (which typically have the same name as a regular ref
assembly), bump their minor file version by 100 to make it distinguishable from the regular
ref assembly. -->
<Target Name="UpdateExperimentalRefAssemblyFileVersion"
AfterTargets="_InitializeAssemblyVersion"
Condition="'$(IsReferenceAssemblyProject)' == 'true' and '$(IsExperimentalRefAssembly)' == 'true'">
<PropertyGroup>
<_FileVersionMaj>$(FileVersion.Split('.')[0])</_FileVersionMaj>
<_FileVersionMin>$(FileVersion.Split('.')[1])</_FileVersionMin>
<_FileVersionBld>$(FileVersion.Split('.')[2])</_FileVersionBld>
<_FileVersionRev>$(FileVersion.Split('.')[3])</_FileVersionRev>
<FileVersion>$(_FileVersionMaj).$([MSBuild]::Add($(_FileVersionMin), 100)).$(_FileVersionBld).$(_FileVersionRev)</FileVersion>
</PropertyGroup>
</Target>
</Project>

View file

@ -2,11 +2,6 @@
<PropertyGroup>
<SkipInferTargetOSName>true</SkipInferTargetOSName>
<DisableArcadeTestFramework>true</DisableArcadeTestFramework>
<!-- Set OutDirName to change the BaseOutputPath and BaseIntermediateOutputPath properties to include the ref subfolder. -->
<_projectDirName>$([System.IO.Path]::GetFileName('$(MSBuildProjectDirectory)'))</_projectDirName>
<IsReferenceAssemblyProject Condition="'$(_projectDirName)' == 'ref'">true</IsReferenceAssemblyProject>
<OutDirName Condition="'$(IsReferenceAssemblyProject)' == 'true'">$(MSBuildProjectName)$([System.IO.Path]::DirectorySeparatorChar)ref</OutDirName>
</PropertyGroup>
<Import Project="..\..\Directory.Build.props" />
@ -32,7 +27,7 @@
<PropertyGroup>
<!-- Treat as a generator project if either the parent or the parent parent directory is named gen. -->
<IsGeneratorProject Condition="'$(_projectDirName)' == 'gen' or
<IsGeneratorProject Condition="$([System.IO.Path]::GetFileName('$(MSBuildProjectDirectory)')) == 'gen' or
$([System.IO.Path]::GetFileName('$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..'))')) == 'gen'">true</IsGeneratorProject>
<IsSourceProject Condition="'$(IsSourceProject)' == '' and
'$(IsReferenceAssemblyProject)' != 'true' and
@ -69,7 +64,6 @@
</ItemGroup>
<Import Project="NetCoreAppLibrary.props" />
<Import Project="$(RepositoryEngineeringDir)referenceAssemblies.props" Condition="'$(IsReferenceAssemblyProject)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)testing\linker\trimmingTests.props" Condition="'$(IsPublishedAppTestProject)' == 'true'" />
<PropertyGroup>