Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Commit

Permalink
Create common manifest file
Browse files Browse the repository at this point in the history
This will trim additional packages such as runtime.win-arm64.runtime.native.system.data.sqlclient.sni
  • Loading branch information
JunTaoLuo committed Jul 4, 2017
1 parent 368883b commit bb1d80b
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 3 deletions.
20 changes: 18 additions & 2 deletions build/repo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,24 @@
<Copy SourceFiles="$(RepositoryRoot)build\Build.RS.nuspec" DestinationFolder="$(ArtifactsDir)" Condition="'$(OSPlatform)'=='Linux'" />
<WriteLinesToFile File="$(ArtifactsDir)version.txt" Lines="$(VersionPrefix)-$(VersionSuffix)" Overwrite="true" Condition="'$(OSPlatform)'=='Linux'" />

<!-- Preview 2 Workaround: remove Microsoft.AspNetCore.Mvc.Razor.ViewCompilation from publish manifest -->
<Exec Command="sed -i -e '/microsoft.aspnetcore.mvc.razor.viewcompilation/d' $(ArtifactsDir)%(PackageStoreManifestFiles.TimestampDestinationFile)" Condition="'$(OS)' != 'Windows_NT'" />
<!-- Add a common manifest for package trimming -->
<MSBuild Projects="$(ProjectPath)" Targets="CreateCommonManifest" Condition="'$(OSPlatform)' == 'Windows' AND '$(PACKAGE_CACHE_PLATFORM)' == 'x64'"/>
</Target>

<Target Name="CreateCommonManifest">
<PropertyGroup>
<CommonManifestFileName>aspnetcore-store-$(TimestampVersion)-common.xml</CommonManifestFileName>
</PropertyGroup>

<ItemGroup>
<PackageToTrim Include="runtime.win-arm64.runtime.native.system.data.sqlclient.sni" />
</ItemGroup>

<MSBuild Projects="$(RuntimeStoreReferenceDirectory)\Build.RuntimeStore.References.csproj" Targets="GetPackageDefinitions" >
<Output TaskParameter="TargetOutputs" ItemName="_PackageDefinitions" />
</MSBuild>

<RepoTasks.CreateCommonManifest DestinationFilePath="$(ArtifactsDir)$(CommonManifestFileName)" PackageDefinitions="@(_PackageDefinitions)" Packages="@(PackageToTrim)"/>
</Target>

<Target Name="ConvertZipToTGZ">
Expand Down
67 changes: 67 additions & 0 deletions build/tasks/CreateCommonManifest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace RepoTasks
{
/// <summary>
/// Creates a common manifest file used for trimming publish output given a list of packages and package definitions containing their versions.
/// </summary>
public class CreateCommonManifest : Task
{
/// <summary>
/// The path for the common manifest file to be created.
/// </summary>
/// <returns></returns>
[Required]
public string DestinationFilePath { get; set; }

/// <summary>
/// The packages to include in the common manifest file.
/// </summary>
/// <returns></returns>
[Required]
public ITaskItem[] Packages { get; set; }

/// <summary>
/// The package definitions used for resolving package versions.
/// </summary>
/// <returns></returns>
[Required]
public ITaskItem[] PackageDefinitions { get; set; }

public override bool Execute()
{
var xmlDoc = new XmlDocument();
var packagesElement = xmlDoc.CreateElement("StoreArtifacts");

foreach (var package in Packages)
{
var packageName = package.ItemSpec;
var packageElement = xmlDoc.CreateElement("Package");

var idAttribute = xmlDoc.CreateAttribute("Id");
idAttribute.Value = packageName;
packageElement.Attributes.Append(idAttribute);

var versionAttribute = xmlDoc.CreateAttribute("Version");
versionAttribute.Value = PackageDefinitions
.Where(p => string.Equals(p.GetMetadata("Name"), packageName, StringComparison.OrdinalIgnoreCase))
.Select(p => p.GetMetadata("Version")).Single();
packageElement.Attributes.Append(versionAttribute);

packagesElement.AppendChild(packageElement);
}

xmlDoc.AppendChild(packagesElement);
xmlDoc.Save(DestinationFilePath);

return true;
}
}
}
9 changes: 9 additions & 0 deletions build/tasks/RepoTasks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(RepoTasksSdkPath)\Sdk.props" Condition="'$(RepoTasksSdkPath)' != '' "/>

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<Import Project="$(RepoTasksSdkPath)\Sdk.targets" Condition="'$(RepoTasksSdkPath)' != '' "/>
</Project>
3 changes: 3 additions & 0 deletions build/tasks/RepoTasks.tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<UsingTask TaskName="RepoTasks.CreateCommonManifest" AssemblyFile="$(MSBuildThisFileDirectory)bin\publish\RepoTasks.dll" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<UsingTask TaskName="Microsoft.NET.Build.Tasks.ResolvePackageDependencies" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

<Import Project="..\..\build\common.props" />

<PropertyGroup>
Expand All @@ -8,6 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="@(RuntimeStorePackageReference)" />
<PackageReference Include="@(RuntimeStorePackageReference)" />
<ProjectAssetsJson Include="$(MSBuildThisFileDirectory)**\project.assets.json" />
</ItemGroup>

<Target Name="GetPackageDefinitions" Returns="@(_PackageDefinitions)" >
<ResolvePackageDependencies ProjectPath="$(MSBuildThisFileFullPath)" ProjectAssetsFile="@(ProjectAssetsJson)">
<Output TaskParameter="PackageDefinitions" ItemName="_PackageDefinitions" />
</ResolvePackageDependencies>
</Target>
</Project>

0 comments on commit bb1d80b

Please sign in to comment.