upgrade-assistant/Extensions.targets

122 строки
5.4 KiB
XML

<Project>
<PropertyGroup>
<IsCI>false</IsCI>
<IsCI Condition=" '$(BuildingInsideVisualStudio)' == '' ">true</IsCI>
</PropertyGroup>
<!-- If building an extension with a _ExtensionIntermediateOutputPath, we want to redirect bin and obj folders to reduce file lock conflicts -->
<PropertyGroup Condition=" '$(_ExtensionIntermediateOutputPath)' != '' ">
<_AssemblyIntermediatePath>$(_ExtensionIntermediateOutputPath)$(ExtensionDir)$(AssemblyName)\</_AssemblyIntermediatePath>
<OutDir>$(_AssemblyIntermediatePath)bin\</OutDir>
<IntermediateOutputPath>$(_AssemblyIntermediatePath)$(ExtensionDir)obj\</IntermediateOutputPath>
</PropertyGroup>
<!-- Publish the extension and collect its output -->
<Target Name="ComputePublishOutput"
DependsOnTargets="Build;ComputeFilesToPublish"
Returns="@(ExtensionFiles)">
<ItemGroup>
<ExtensionFiles Include="@(ResolvedFileToPublish)">
<Link>$(ExtensionDir)/%(ResolvedFileToPublish.RelativePath)</Link>
<TargetPath>$(ExtensionDir)/%(ResolvedFileToPublish.RelativePath)</TargetPath>
</ExtensionFiles>
</ItemGroup>
</Target>
<Target Name="_AddMetadataToExtensions"
BeforeTargets="RestoreExtensions;PublishUpgradeAssistantExtensions">
<!-- Add the relative directory the extension will be added to -->
<ItemGroup>
<Extension Update="@(Extension)">
<Properties>Configuration=$(Configuration);ExtensionDir=extensions\%(Name)\</Properties>
</Extension>
</ItemGroup>
<!-- When compiling outside of VS, we want to set a new intermediate path to prevent race conditions of multiple writes to the output -->
<ItemGroup Condition="$(IsCI)">
<Extension Update="@(Extension)">
<Properties>%(Properties);_ExtensionIntermediateOutputPath=$(IntermediateOutputPath)</Properties>
</Extension>
</ItemGroup>
</Target>
<!--
Since we will be publishing extensions, we want to ensure they are restored. Must run before the following targets:
Restore: For clean builds
PrepareForBuild: For incremental builds in VS
PackDependsOn: For pack commands
-->
<Target Name="RestoreExtensions"
BeforeTargets="Restore;PrepareForBuild;$(PackDependsOn)">
<MSBuild Projects="%(Extension.Identity)"
Targets="Restore"
Properties="%(Properties)"
RemoveProperties="TargetFramework"
Condition=" '%(Name)' != '' " />
</Target>
<!-- Publish each extension into its own directory -->
<Target Name="PublishUpgradeAssistantExtensions"
DependsOnTargets="ResolveAssemblyReferences"
BeforeTargets="AssignTargetPaths"
Outputs="%(Extension.Identity)">
<Message Text="Publishing extension %(Extension.Name)" Importance="high" Condition=" '%(Extension.Name)' != '' "/>
<!--
Publish the extension and collect its extension.
- We also pass in some custom configuration so it'll know its an extension.
- We want to remove any TargetFramework that is set so that isn't flowed through to the next project.
-->
<MSBuild Projects="%(Extension.Identity)"
BuildInParallel="true"
Targets="ComputePublishOutput"
RemoveProperties="TargetFramework"
Properties="%(Properties)"
Condition=" '%(Name)' != '' ">
<Output TaskParameter="TargetOutputs" ItemName="_ExtensionArtifacts" />
</MSBuild>
<!-- Create a list of all assemblies included by host and framework -->
<ItemGroup>
<_ExcludeFromExtension Include="Microsoft.DotNet.UpgradeAssistant.Abstractions.dll" />
<_ExcludeFromExtension Include="System.ComponentModel.Annotations.dll" />
<_ExcludeFromExtension Include="System.Memory.dll" />
<_ExcludeFromExtension Include="System.Numerics.Vectors.dll" />
<_ExcludeFromExtension Include="System.Reflection.Emit.dll" />
<_ExcludeFromExtension Include="System.Text.Encodings.Web.dll" />
<_ExcludeFromExtension Include="System.Threading.Tasks.Extensions.dll" />
<_ExcludeFromExtension Include="%(ReferenceCopyLocalPaths.DestinationSubPath)" />
<_ExcludeFromExtension Include="%(RuntimeCopyLocalItems.DestinationSubPath)" />
</ItemGroup>
<ItemGroup>
<!-- Create a collection of the extension files by their relative path while maintaining metadata -->
<_ExtensionArtifactsByRelativePath Include="%(_ExtensionArtifacts.RelativePath)">
<OriginalIdentity>%(Identity)</OriginalIdentity>
<TargetPath>%(TargetPath)</TargetPath>
<Link>%(Link)</Link>
</_ExtensionArtifactsByRelativePath>
<!-- Remove the host supplied assemblies -->
<_FilteredExtensionArtifactsMinusExclusions Include="@(_ExtensionArtifactsByRelativePath)" Exclude="@(_ExcludeFromExtension)" />
<!-- Transform the filtered list back to include the appropriate metadata to be added to -->
<_FilteredExtensionArtifacts Include="%(_FilteredExtensionArtifactsMinusExclusions.OriginalIdentity)">
<RelativePath>%(TargetPath)</RelativePath>
<TargetPath>%(TargetPath)</TargetPath>
<Link>%(Link)</Link>
</_FilteredExtensionArtifacts>
<None Include="@(_FilteredExtensionArtifacts)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Message Text="Published extension %(Extension.Name)" Importance="high" Condition=" '%(Extension.Name)' != '' "/>
</Target>
</Project>