aspnetcore/eng/targets/ReferenceAssembly.targets

99 lines
4.4 KiB
XML

<Project>
<Target Name="GenerateReferenceSource" Condition="'$(HasReferenceAssembly)' == 'true'">
<PropertyGroup>
<_RefSourceOutputPath>$([System.IO.Directory]::GetParent('$(MSBuildProjectDirectory)'))/ref/</_RefSourceOutputPath>
<_RefProjectFileOutputPath>$(_RefSourceOutputPath)$(AssemblyName).csproj</_RefProjectFileOutputPath>
</PropertyGroup>
<ItemGroup>
<_AllTargetFrameworks Remove="@(_AllTargetFrameworks)" />
<_AllTargetFrameworks Include="$(TargetFrameworks);$(TargetFramework)" />
<_DeduplicatedTargetFramework Include="%(_AllTargetFrameworks.Identity)" />
</ItemGroup>
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="_GenerateProjectSourceInner"
Properties="TargetFramework=%(_DeduplicatedTargetFramework.Identity)">
<Output TaskParameter="TargetOutputs" ItemName="ProjectListContentItem" />
</MSBuild>
<ItemGroup>
<_ResultTargetFramework Include="%(ProjectListContentItem.TargetFramework)" />
</ItemGroup>
<PropertyGroup>
<ProjectListContentLines><![CDATA[
<!-- This file is automatically generated. -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>@(_ResultTargetFramework)</TargetFrameworks>
</PropertyGroup>
@(ProjectListContentItem->'%(Identity)', '%0A')
</Project>
]]></ProjectListContentLines>
</PropertyGroup>
<!-- Workaround https://github.com/Microsoft/msbuild/issues/1024 -->
<WriteLinesToFile Condition="'$(OS)' == 'Windows_NT'"
File="$(_RefProjectFileOutputPath)" Lines="$([MSBuild]::Escape($(ProjectListContentLines)))" Overwrite="true" />
<Exec Condition="'$(OS)' != 'Windows_NT'"
Command="echo '$(ProjectListContentLines.Replace('\t','\\t'))' > $(_RefProjectFileOutputPath)" />
<Message Importance="High" Text="Generated $(_RefProjectFileOutputPath)" />
</Target>
<Target Name="_GenerateProjectSourceInner" Returns="@(ProjectListContent)" DependsOnTargets="Build" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
<PropertyGroup>
<_RefSourceOutputPath>$([System.IO.Directory]::GetParent('$(MSBuildProjectDirectory)'))/ref/</_RefSourceOutputPath>
<_RefSourceFileName>$(AssemblyName).$(TargetFramework).cs</_RefSourceFileName>
<_RefSourceFileOutputPath>$(_RefSourceOutputPath)$(_RefSourceFileName)</_RefSourceFileOutputPath>
</PropertyGroup>
<ItemGroup>
<_ReferenceDirectoriesWithDuplicates Include="@(ReferencePath->'%(RootDir)%(Directory)'->TrimEnd('\'))" />
<_ReferencePathDirectories Include="%(_ReferenceDirectoriesWithDuplicates.Identity)" />
</ItemGroup>
<PropertyGroup>
<_GenAPICommand Condition="'$(MSBuildRuntimeType)' == 'core'">"$(DotNetTool)" --roll-forward-on-no-candidate-fx 2 "$(_GenAPIPath)"</_GenAPICommand>
<_GenAPICmd>$(_GenAPICommand)</_GenAPICmd>
<_GenAPICmd>$(_GenAPICmd) "$(TargetPath)"</_GenAPICmd>
<_GenAPICmd>$(_GenAPICmd) --lib-path "@(_ReferencePathDirectories)"</_GenAPICmd>
<_GenAPICmd>$(_GenAPICmd) --out "$(_RefSourceFileOutputPath)"</_GenAPICmd>
<_GenAPICmd>$(_GenAPICmd) --header-file "$(RepoRoot)/eng/LicenseHeader.txt"</_GenAPICmd>
<_GenAPICmd>$(_GenAPICmd) --exclude-api-list "$(RepoRoot)/eng/GenAPI.exclusions.txt"</_GenAPICmd>
</PropertyGroup>
<MakeDir Directories="$(_RefSourceOutputPath)" />
<Message Importance="High" Text="Generating $(_RefSourceFileOutputPath)" />
<Exec Command="$(_GenAPICmd)" />
<ItemGroup>
<FilteredOriginalReferences
Include="%(_OriginalReferences.Identity)"
Condition="'%(_OriginalReferences.NuGetPackageId)' == '' AND '%(_OriginalReferences.PrivateAssets)' != 'All'" />
</ItemGroup>
<PropertyGroup>
<ProjectListFile>$(MSBuildThisFileDirectory)..\eng\ProjectReferences.props</ProjectListFile>
<RefsTargetFramework>$(TargetFrameworks)</RefsTargetFramework>
<RefsTargetFramework Condition="'$(RefsTargetFramework)' == ''">$(TargetFramework)</RefsTargetFramework>
<ReferencesContent>
<![CDATA[
<ItemGroup Condition="'%24(TargetFramework)' == '$(TargetFramework)'">
<Compile Include="$(_RefSourceFileName)" />
@(FilteredOriginalReferences->'<Reference Include="%(Identity)" />', '%0A ')
</ItemGroup>
]]>
</ReferencesContent>
</PropertyGroup>
<ItemGroup>
<ProjectListContent Include="$(ReferencesContent)" TargetFramework="$(TargetFramework)" />
</ItemGroup>
</Target>
</Project>