|
| 1 | +<Project> |
| 2 | + |
| 3 | + <UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ReplaceTextInFile" /> |
| 4 | + |
| 5 | + <!-- |
| 6 | + Find text-only nupkgs and decompose them into text files to include in the tarball as source |
| 7 | + code. This simplifies maintenance by removing the need to put a new version of these files in |
| 8 | + dotnet/source-build-reference-packages for potentially every single servicing release. |
| 9 | +
|
| 10 | + 'dotnet new' template packages are a prominent example of text-only packages that change often. |
| 11 | + --> |
| 12 | + <Target Name="AddAllUnpackedTextOnlyPackageSource" |
| 13 | + DependsOnTargets="GetTarballDirProps" |
| 14 | + BeforeTargets="AddTarballPackages"> |
| 15 | + <PropertyGroup> |
| 16 | + <TarballUnpackedTextOnlyPackageSourceDir>$([MSBuild]::NormalizeDirectory('$(TarballRootDir)', 'packages', 'text-only'))</TarballUnpackedTextOnlyPackageSourceDir> |
| 17 | + </PropertyGroup> |
| 18 | + |
| 19 | + <!-- |
| 20 | + Find .nupkg files in package cache in order to locate the extraction directory, then filter |
| 21 | + which files are copied to the tarball to exclude the nupkg itself and unnecessary metadata. |
| 22 | + --> |
| 23 | + <ItemGroup> |
| 24 | + <TextOnlyPrebuiltNupkgFile Include=" |
| 25 | + $(ProjectDir)packages\restored\**\microsoft.dotnet.web.itemtemplates.5.0.*.nupkg; |
| 26 | + $(ProjectDir)packages\restored\**\microsoft.dotnet.web.projecttemplates.5.0.5.0.*.nupkg; |
| 27 | + $(ProjectDir)packages\restored\**\microsoft.dotnet.web.spa.projecttemplates.5.0.5.0.*.nupkg; |
| 28 | + " /> |
| 29 | + |
| 30 | + <!-- Make prebuilt nupkg copy logic ignore these text-only nupkgs. --> |
| 31 | + <RefOnlyPackageFilename Include="@(TextOnlyPrebuiltNupkgFile->'%(Filename)')" /> |
| 32 | + |
| 33 | + <TextOnlyPrebuiltNupkgProject |
| 34 | + Include="$(MSBuildProjectFullPath)" |
| 35 | + Properties=" |
| 36 | + TextOnlyPackageRootDir=%(TextOnlyPrebuiltNupkgFile.RootDir)%(TextOnlyPrebuiltNupkgFile.Directory)" /> |
| 37 | + </ItemGroup> |
| 38 | + |
| 39 | + <MSBuild |
| 40 | + Projects="@(TextOnlyPrebuiltNupkgProject)" |
| 41 | + Targets="AddUnpackedTextOnlyPackageSource"> |
| 42 | + <Output TaskParameter="TargetOutputs" ItemName="TarballCopyFile" /> |
| 43 | + </MSBuild> |
| 44 | + </Target> |
| 45 | + |
| 46 | + <Target Name="AddUnpackedTextOnlyPackageSource" |
| 47 | + DependsOnTargets="GetTarballDirProps" |
| 48 | + Returns="@(TarballCopyFile)"> |
| 49 | + <PropertyGroup> |
| 50 | + <PackageVersionDirFile>$([System.IO.Path]::GetDirectoryName('$(TextOnlyPackageRootDir)'))</PackageVersionDirFile> |
| 51 | + <PackageIdDirFile>$([System.IO.Path]::GetDirectoryName('$(PackageVersionDirFile)'))</PackageIdDirFile> |
| 52 | + <PackageVersion>$([System.IO.Path]::GetFileName('$(PackageVersionDirFile)'))</PackageVersion> |
| 53 | + <PackageId>$([System.IO.Path]::GetFileName('$(PackageIdDirFile)'))</PackageId> |
| 54 | + |
| 55 | + <PackageIntermediateDir>$([MSBuild]::NormalizeDirectory('$(TextOnlyPackageBaseDir)', '$(PackageId)', '$(PackageVersion)'))</PackageIntermediateDir> |
| 56 | + </PropertyGroup> |
| 57 | + |
| 58 | + <MakeDir Directories="$(PackageIntermediateDir)" /> |
| 59 | + |
| 60 | + <ItemGroup> |
| 61 | + <NuspecFile Include="$(TextOnlyPackageRootDir)*.nuspec" /> |
| 62 | + <PackableNuspecFile Include="@(NuspecFile->'$(PackageIntermediateDir)%(Filename)%(Extension)')" /> |
| 63 | + </ItemGroup> |
| 64 | + |
| 65 | + <Error Condition="@(NuspecFile->Count()) != 1" Text="Expected exactly one nuspec file in $(TextOnlyPackageRootDir)" /> |
| 66 | + |
| 67 | + <Copy SourceFiles="@(NuspecFile)" DestinationFiles="@(PackableNuspecFile)" /> |
| 68 | + |
| 69 | + <ReplaceTextInFile |
| 70 | + InputFile="@(PackableNuspecFile)" |
| 71 | + OldText="</package>" |
| 72 | + NewText="<files><file src=".\**\*"/></files></package>" /> |
| 73 | + |
| 74 | + <ItemGroup> |
| 75 | + <TextOnlyPackageContentFile |
| 76 | + Include=" |
| 77 | + $(TextOnlyPackageRootDir)**; |
| 78 | + $(PackageIntermediateDir)**" |
| 79 | + Exclude=" |
| 80 | + @(NuspecFile); |
| 81 | + $(TextOnlyPackageRootDir)**\.nupkg.metadata; |
| 82 | + $(TextOnlyPackageRootDir)**\.signature.p7s; |
| 83 | + $(TextOnlyPackageRootDir)**\*.nupkg; |
| 84 | + $(TextOnlyPackageRootDir)**\*.nupkg.sha512" /> |
| 85 | + |
| 86 | + <TarballCopyFile |
| 87 | + Include="@(TextOnlyPackageContentFile)" |
| 88 | + RelativeDestination="packages\text-only\$(PackageId)\$(PackageVersion)\%(RecursiveDir)%(Filename)%(Extension)" /> |
| 89 | + </ItemGroup> |
| 90 | + </Target> |
| 91 | + |
| 92 | +</Project> |
0 commit comments