Consume NETCore.App

This commit is contained in:
Eric Erhardt 2016-04-06 19:45:38 -05:00
parent 0747d31f86
commit 99371436f3
46 changed files with 190 additions and 96 deletions

View file

@ -49,7 +49,9 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success();
}
[Target(nameof(PrepareTargets.Init), nameof(PackagePkgProjects), nameof(CompileStage1), nameof(CompileStage2))]
// Moving PrepareTargets.RestorePackages after PackagePkgProjects because managed code depends on the
// Microsoft.NETCore.App package that is created during PackagePkgProjects.
[Target(nameof(PrepareTargets.Init), nameof(PackagePkgProjects), nameof(PrepareTargets.RestorePackages), nameof(CompileStage1), nameof(CompileStage2))]
public static BuildTargetResult Compile(BuildTargetContext c)
{
return c.Success();
@ -330,9 +332,26 @@ namespace Microsoft.DotNet.Cli.Build
public static void PublishSharedFramework(BuildTargetContext c, string outputDir, DotNetCli dotnetCli)
{
string SharedFrameworkSourceRoot = Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework");
string SharedFrameworkTemplateSourceRoot = Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework");
string SharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
string sharedFrameworkRid;
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
{
sharedFrameworkRid = $"win7-{PlatformServices.Default.Runtime.RuntimeArchitecture}";
}
else
{
sharedFrameworkRid = PlatformServices.Default.Runtime.GetRuntimeIdentifier();
}
string SharedFrameworkSourceRoot = GenerateSharedFrameworkProject(c, SharedFrameworkTemplateSourceRoot, sharedFrameworkRid);
dotnetCli.Restore("--verbosity", "verbose", "--disable-parallel", "--infer-runtimes", "--fallbacksource", Dirs.Corehost)
.WorkingDirectory(SharedFrameworkSourceRoot)
.Execute()
.EnsureSuccessful();
// We publish to a sub folder of the PublishRoot so tools like heat and zip can generate folder structures easier.
string SharedFrameworkNameAndVersionRoot = Path.Combine(outputDir, "shared", SharedFrameworkName, SharedFrameworkNugetVersion);
c.BuildContext["SharedFrameworkPath"] = SharedFrameworkNameAndVersionRoot;
@ -343,19 +362,10 @@ namespace Microsoft.DotNet.Cli.Build
}
string publishFramework = "dnxcore50"; // Temporary, use "netcoreapp" when we update nuget.
string publishRuntime;
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
{
publishRuntime = $"win7-{PlatformServices.Default.Runtime.RuntimeArchitecture}";
}
else
{
publishRuntime = PlatformServices.Default.Runtime.GetRuntimeIdentifier();
}
dotnetCli.Publish(
"--output", SharedFrameworkNameAndVersionRoot,
"-r", publishRuntime,
"-r", sharedFrameworkRid,
"-f", publishFramework,
SharedFrameworkSourceRoot).Execute().EnsureSuccessful();
@ -428,6 +438,30 @@ namespace Microsoft.DotNet.Cli.Build
File.WriteAllText(Path.Combine(SharedFrameworkNameAndVersionRoot, ".version"), content);
}
/// <summary>
/// Generates the real shared framework project that will get published.
/// </summary>
/// <param name="sharedFrameworkTemplatePath">The "sharedFramework" source template folder.</param>
private static string GenerateSharedFrameworkProject(BuildTargetContext c, string sharedFrameworkTemplatePath, string rid)
{
string sharedFrameworkProjectPath = Path.Combine(Dirs.Intermediate, "sharedFramework", "framework");
Utils.DeleteDirectory(sharedFrameworkProjectPath);
CopyRecursive(sharedFrameworkTemplatePath, sharedFrameworkProjectPath, true);
string templateFile = Path.Combine(sharedFrameworkProjectPath, "project.json.template");
JObject sharedFrameworkProject = JsonUtils.ReadProject(templateFile);
sharedFrameworkProject["dependencies"]["Microsoft.NETCore.App"] = c.BuildContext.Get<BuildVersion>("BuildVersion").NetCoreAppVersion;
((JObject)sharedFrameworkProject["runtimes"]).RemoveAll();
sharedFrameworkProject["runtimes"][rid] = new JObject();
string projectJsonPath = Path.Combine(sharedFrameworkProjectPath, "project.json");
JsonUtils.WriteProject(sharedFrameworkProject, projectJsonPath);
Rm(templateFile);
return sharedFrameworkProjectPath;
}
private static BuildTargetResult CompileCliSdk(BuildTargetContext c, DotNetCli dotnet, string outputDir)
{
var configuration = c.BuildContext.Get<string>("Configuration");

View file

@ -1,23 +1,24 @@
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using static Microsoft.DotNet.Cli.Build.FS;
using static Microsoft.DotNet.Cli.Build.Utils;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using System.Text.RegularExpressions;
namespace Microsoft.DotNet.Cli.Build
{
public class PrepareTargets
{
[Target(nameof(Init), nameof(RestorePackages))]
[Target(nameof(Init))]
public static BuildTargetResult Prepare(BuildTargetContext c) => c.Success();
[Target(nameof(CheckPrereqCmakePresent), nameof(CheckPlatformDependencies))]
@ -33,7 +34,7 @@ namespace Microsoft.DotNet.Cli.Build
public static BuildTargetResult CheckInstallerBuildPlatformDependencies(BuildTargetContext c) => c.Success();
// All major targets will depend on this in order to ensure variables are set up right if they are run independently
[Target(nameof(GenerateVersions), nameof(CheckPrereqs), nameof(LocateStage0), nameof(ExpectedBuildArtifacts))]
[Target(nameof(GenerateVersions), nameof(UpdateTemplateVersions), nameof(CheckPrereqs), nameof(LocateStage0), nameof(ExpectedBuildArtifacts))]
public static BuildTargetResult Init(BuildTargetContext c)
{
var runtimeInfo = PlatformServices.Default.Runtime;
@ -82,7 +83,7 @@ namespace Microsoft.DotNet.Cli.Build
};
c.BuildContext["BuildVersion"] = buildVersion;
c.BuildContext["CommitHash"] = commitHash;
c.BuildContext["SharedFrameworkNugetVersion"] = GetVersionFromProjectJson(Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework", "project.json"));
c.BuildContext["SharedFrameworkNugetVersion"] = buildVersion.NetCoreAppVersion;
c.Info($"Building Version: {buildVersion.SimpleVersion} (NuGet Packages: {buildVersion.NuGetVersion})");
c.Info($"From Commit: {commitHash}");
@ -90,6 +91,27 @@ namespace Microsoft.DotNet.Cli.Build
return c.Success();
}
/// <summary>
/// Updates the Microsoft.NETCore.App version number in the `dotnet new` project.json.template files.
/// </summary>
[Target]
public static BuildTargetResult UpdateTemplateVersions(BuildTargetContext c)
{
IEnumerable<string> templateFiles = Directory.GetFiles(
Path.Combine(Dirs.RepoRoot, @"src\dotnet\commands\dotnet-new"),
"project.json.pretemplate",
SearchOption.AllDirectories);
foreach (string templateFile in templateFiles)
{
JObject projectRoot = JsonUtils.ReadProject(templateFile);
projectRoot["dependencies"]["Microsoft.NETCore.App"]["version"] = c.BuildContext.Get<BuildVersion>("BuildVersion").NetCoreAppVersion;
JsonUtils.WriteProject(projectRoot, Path.ChangeExtension(templateFile, "template"));
}
return c.Success();
}
[Target]
public static BuildTargetResult LocateStage0(BuildTargetContext c)
{
@ -206,8 +228,14 @@ namespace Microsoft.DotNet.Cli.Build
{
var dotnet = DotNetCli.Stage0;
dotnet.Restore("--verbosity", "verbose", "--disable-parallel", "--infer-runtimes").WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "src")).Execute().EnsureSuccessful();
dotnet.Restore("--verbosity", "verbose", "--disable-parallel", "--infer-runtimes").WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "tools")).Execute().EnsureSuccessful();
dotnet.Restore("--verbosity", "verbose", "--disable-parallel", "--infer-runtimes", "--fallbacksource", Dirs.Corehost)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "src"))
.Execute()
.EnsureSuccessful();
dotnet.Restore("--verbosity", "verbose", "--disable-parallel", "--infer-runtimes")
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "tools"))
.Execute()
.EnsureSuccessful();
return c.Success();
}

View file

@ -70,7 +70,7 @@ namespace Microsoft.DotNet.Cli.Build
CleanNuGetTempCache();
var dotnet = DotNetCli.Stage2;
dotnet.Restore("--verbosity", "verbose", "--infer-runtimes")
dotnet.Restore("--verbosity", "verbose", "--infer-runtimes", "--fallbacksource", Dirs.Corehost)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages"))
.Execute()
.EnsureSuccessful();
@ -90,14 +90,16 @@ namespace Microsoft.DotNet.Cli.Build
dotnet.Restore(
"--verbosity", "verbose",
"--infer-runtimes",
"--fallbacksource", Dirs.TestPackages)
"--fallbacksource", Dirs.TestPackages,
"--fallbacksource", Dirs.Corehost)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"))
.Execute().EnsureSuccessful();
// The 'ProjectModelServer' directory contains intentionally-unresolved dependencies, so don't check for success. Also, suppress the output
dotnet.Restore(
"--verbosity", "verbose",
"--infer-runtimes")
"--infer-runtimes",
"--fallbacksource", Dirs.Corehost)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "ProjectModelServer", "DthTestProjects"))
.Execute();
@ -118,7 +120,8 @@ namespace Microsoft.DotNet.Cli.Build
dotnet.Restore("--verbosity", "verbose",
"--infer-runtimes",
"--fallbacksource", Dirs.TestPackages)
"--fallbacksource", Dirs.TestPackages,
"--fallbacksource", Dirs.Corehost)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "DesktopTestProjects"))
.Execute().EnsureSuccessful();
@ -255,7 +258,9 @@ namespace Microsoft.DotNet.Cli.Build
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
CleanNuGetTempCache();
DotNetCli.Stage2.Restore("--verbosity", "verbose", "--infer-runtimes", "--fallbacksource", Dirs.TestPackages)
DotNetCli.Stage2.Restore("--verbosity", "verbose",
"--fallbacksource", Dirs.TestPackages,
"--fallbacksource", Dirs.Corehost)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test"))
.Execute()
.EnsureSuccessful();

View file

@ -12,6 +12,7 @@
public string SimpleVersion => $"{Major}.{Minor}.{Patch}.{CommitCountString}";
public string VersionSuffix => $"{ReleaseSuffix}-{CommitCountString}";
public string NuGetVersion => $"{Major}.{Minor}.{Patch}-{VersionSuffix}";
public string NetCoreAppVersion => $"{Major}.{Minor}.{Patch}-rc2-3{CommitCountString}";
public string ProductionVersion => $"{Major}.{Minor}.{Patch}";
public string GenerateMsiVersion()

View file

@ -13,6 +13,7 @@ namespace Microsoft.DotNet.Cli.Build
"artifacts",
PlatformServices.Default.Runtime.GetRuntimeIdentifier());
public static readonly string Intermediate = Path.Combine(Output, "intermediate");
public static readonly string PackagesIntermediate = Path.Combine(Output, "packages/intermediate");
public static readonly string Packages = Path.Combine(Output, "packages");
public static readonly string Stage1 = Path.Combine(Output, "stage1");

View file

@ -0,0 +1,28 @@
using System;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Microsoft.DotNet.Cli.Build
{
public static class JsonUtils
{
public static JObject ReadProject(string projectJsonPath)
{
using (TextReader projectFileReader = File.OpenText(projectJsonPath))
{
var projectJsonReader = new JsonTextReader(projectFileReader);
var serializer = new JsonSerializer();
return serializer.Deserialize<JObject>(projectJsonReader);
}
}
public static void WriteProject(JObject projectRoot, string projectJsonPath)
{
string projectJson = JsonConvert.SerializeObject(projectRoot, Formatting.Indented);
File.WriteAllText(projectJsonPath, projectJson + Environment.NewLine);
}
}
}