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

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JunTaoLuo committed Jul 4, 2017
1 parent bed6f54 commit 063caea
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
2 changes: 0 additions & 2 deletions build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
<CoreFxVersion>4.4.0-*</CoreFxVersion>
<DotnetDebToolVersion>2.0.0-preview2-*</DotnetDebToolVersion>
<InternalAspNetCoreSdkVersion>2.1.0-*</InternalAspNetCoreSdkVersion>
<JsonNetInMSBuildVersion>9.0.1</JsonNetInMSBuildVersion>
<MoqVersion>4.7.49</MoqVersion>
<MsBuildPackageVersions>15.3.0</MsBuildPackageVersions>
<NETStandardImplicitPackageVersion>2.0.0-*</NETStandardImplicitPackageVersion>
<NETStandardLibraryNETFrameworkVersion>2.0.0-*</NETStandardLibraryNETFrameworkVersion>
<NewtonsoftJsonVersion>10.0.1</NewtonsoftJsonVersion>
Expand Down
10 changes: 8 additions & 2 deletions build/repo.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project>
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="common.props" />

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

<ItemGroup>
<!-- remove package references that don't belong in KoreBuild -->
<PackageReference Remove="Internal.AspNetCore.Sdk" />
Expand Down Expand Up @@ -191,7 +193,11 @@

<Error Text="@(ProjectAssetsJson->Count()) project.assets.json file(s) found." Condition="'@(ProjectAssetsJson->Count())' != 1" />

<RepoTasks.CreateCommonManifest DestinationFilePath="$(ArtifactsDir)$(CommonManifestFileName)" ProjectAssetsJsonFilePath="@(ProjectAssetsJson)" Packages="@(PackageToTrim)"/>
<ResolvePackageDependencies ProjectPath="$(RuntimeStoreReferenceDirectory)\Build.RuntimeStore.References.csproj" ProjectAssetsFile="@(ProjectAssetsJson)">
<Output TaskParameter="PackageDefinitions" ItemName="_PackageDefinitions" />
</ResolvePackageDependencies>

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

<Target Name="ConvertZipToTGZ">
Expand Down
30 changes: 11 additions & 19 deletions build/tasks/CreateCommonManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO;
using System.Linq;
using System.Xml;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Newtonsoft.Json.Linq;

namespace RepoTasks
{
/// <summary>
/// Creates a common manifest file used for trimming publish output given a list of packages and a project assets json used to detemine their versions.
/// 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
{
Expand All @@ -24,43 +22,37 @@ public class CreateCommonManifest : Task
public string DestinationFilePath { get; set; }

/// <summary>
/// The path for to the project.assets.json file for resolving package versions.
/// The packages to include in the common manifest file.
/// </summary>
/// <returns></returns>
[Required]
public string ProjectAssetsJsonFilePath { get; set; }
public ITaskItem[] Packages { get; set; }

/// <summary>
/// The path for to the project.assets.json file for resolving package versions.
/// The package definitions used for resolving package versions.
/// </summary>
/// <returns></returns>
[Required]
public ITaskItem[] Packages { get; set; }
public ITaskItem[] PackageDefinitions { get; set; }

public override bool Execute()
{
var projectAssets = JObject.Parse(File.ReadAllText(ProjectAssetsJsonFilePath));
var packages = projectAssets
.SelectToken("$.targets.*") // target/.NETCoreApp,Version=v2.0
.Children().Select(s => ((JProperty)s).Name); // Package.Name/Version

var xmlDoc = new XmlDocument();
var packagesElement = xmlDoc.CreateElement("StoreArtifacts");

foreach (var package in Packages.Select(i => i.ItemSpec))
foreach (var package in Packages)
{
var packageVersion = packages
.Where(s => s.StartsWith(package, StringComparison.OrdinalIgnoreCase)) // match package name
.Select(s => s.Substring(s.IndexOf('/') + 1)).Single(); // Parse version

var packageName = package.ItemSpec;
var packageElement = xmlDoc.CreateElement("Package");

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

var VersionAttribute = xmlDoc.CreateAttribute("Version");
VersionAttribute.Value = packageVersion;
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);
Expand Down
16 changes: 5 additions & 11 deletions build/tasks/RepoTasks.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(RepoTasksSdkPath)\Sdk.props" Condition="'$(RepoTasksSdkPath)' != '' "/>

<Import Project="..\..\build\dependencies.props" />
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="$(MsBuildPackageVersions)" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MsBuildPackageVersions)" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MsBuildPackageVersions)" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="$(JsonNetInMSBuildVersion)" />
</ItemGroup>
<Import Project="$(RepoTasksSdkPath)\Sdk.targets" Condition="'$(RepoTasksSdkPath)' != '' "/>
</Project>

0 comments on commit 063caea

Please sign in to comment.