CLI Build Cleanup: Round 1 (#3869)

* dotnet-cli-build non-runnable

* Usings + License
This commit is contained in:
Piotr Puszkiewicz 2016-07-15 08:31:50 -07:00 committed by GitHub
parent a477fe7253
commit 5059e9c61b
36 changed files with 82 additions and 2110 deletions

View file

@ -1,4 +1,7 @@
using System.IO;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
using System.IO.Compression;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

View file

@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

View file

@ -1,4 +1,7 @@
using System;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Linq;
using System.Text;

View file

@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

View file

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -1,6 +1,7 @@
using System;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.DotNet.InternalAbstractions;
namespace Microsoft.DotNet.Cli.Build

View file

@ -1,4 +1,7 @@
using Microsoft.DotNet.Cli.Build.Framework;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.DotNet.Cli.Build.Framework;
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -1,373 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using static Microsoft.DotNet.Cli.Build.FS;
namespace Microsoft.DotNet.Cli.Build
{
public class CompileTargets : Task
{
public static readonly bool IsWinx86 = CurrentPlatform.IsWindows && CurrentArchitecture.Isx86;
public static readonly string[] BinariesForCoreHost = new[]
{
"csc"
};
public static readonly string[] ProjectsToPublish = new[]
{
"dotnet"
};
public static readonly string[] FilesToClean = new[]
{
"vbc.exe"
};
public static string HostPackagePlatformRid => HostPackageSupportedRids[
(RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
? $"win7-{RuntimeEnvironment.RuntimeArchitecture}"
: RuntimeEnvironment.GetRuntimeIdentifier()];
public static readonly Dictionary<string, string> HostPackageSupportedRids = new Dictionary<string, string>()
{
// Key: Current platform RID. Value: The actual publishable (non-dummy) package name produced by the build system for this RID.
{ "win7-x64", "win7-x64" },
{ "win7-x86", "win7-x86" },
{ "osx.10.10-x64", "osx.10.10-x64" },
{ "osx.10.11-x64", "osx.10.10-x64" },
{ "ubuntu.14.04-x64", "ubuntu.14.04-x64" },
{ "ubuntu.16.04-x64", "ubuntu.16.04-x64" },
{ "centos.7-x64", "rhel.7-x64" },
{ "rhel.7-x64", "rhel.7-x64" },
{ "rhel.7.2-x64", "rhel.7-x64" },
{ "debian.8-x64", "debian.8-x64" },
{ "fedora.23-x64", "fedora.23-x64" },
{ "opensuse.13.2-x64", "opensuse.13.2-x64" }
};
public const string SharedFrameworkName = "Microsoft.NETCore.App";
public static Crossgen CrossgenUtil = new Crossgen(DependencyVersions.CoreCLRVersion, DependencyVersions.JitVersion);
public override bool Execute()
{
BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly<CompileTargets>().CreateBuildContext();
BuildTargetContext c = new BuildTargetContext(context, null, null);
return Compile(c).Success;
}
[Target]
public static BuildTargetResult Compile(BuildTargetContext c)
{
PrepareTargets.Init(c);
CompileStage1(c);
CompileStage2(c);
return c.Success();
}
public static BuildTargetResult CompileStage1(BuildTargetContext c)
{
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
if (Directory.Exists(Dirs.Stage1))
{
Utils.DeleteDirectory(Dirs.Stage1);
}
Directory.CreateDirectory(Dirs.Stage1);
var result = CompileCliSdk(c,
dotnet: DotNetCli.Stage0,
rootOutputDirectory: Dirs.Stage1);
CleanOutputDir(Path.Combine(Dirs.Stage1, "sdk"));
FS.CopyRecursive(Dirs.Stage1, Dirs.Stage1Symbols);
RemovePdbsFromDir(Path.Combine(Dirs.Stage1, "sdk"));
return result;
}
public static BuildTargetResult CompileStage2(BuildTargetContext c)
{
var configuration = c.BuildContext.Get<string>("Configuration");
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
if (Directory.Exists(Dirs.Stage2))
{
Utils.DeleteDirectory(Dirs.Stage2);
}
Directory.CreateDirectory(Dirs.Stage2);
var result = CompileCliSdk(c,
dotnet: DotNetCli.Stage1,
rootOutputDirectory: Dirs.Stage2,
generateNugetPackagesArchive: true);
if (!result.Success)
{
return result;
}
if (CurrentPlatform.IsWindows)
{
// build projects for nuget packages
var packagingOutputDir = Path.Combine(Dirs.Stage2Compilation, "forPackaging");
Mkdirp(packagingOutputDir);
foreach (var project in PackageTargets.ProjectsToPack)
{
// Just build them, we'll pack later
var packBuildResult = DotNetCli.Stage1.Build(
"--build-base-path",
packagingOutputDir,
"--configuration",
configuration,
Path.Combine(c.BuildContext.BuildDirectory, "src", project))
.Execute();
packBuildResult.EnsureSuccessful();
}
}
CleanOutputDir(Path.Combine(Dirs.Stage2, "sdk"));
FS.CopyRecursive(Dirs.Stage2, Dirs.Stage2Symbols);
RemovePdbsFromDir(Path.Combine(Dirs.Stage2, "sdk"));
return c.Success();
}
private static void CleanOutputDir(string directory)
{
foreach (var file in FilesToClean)
{
FS.RmFilesInDirRecursive(directory, file);
}
}
private static void RemovePdbsFromDir(string directory)
{
FS.RmFilesInDirRecursive(directory, "*.pdb");
}
private static BuildTargetResult CompileCliSdk(
BuildTargetContext c,
DotNetCli dotnet,
string rootOutputDirectory,
bool generateNugetPackagesArchive = false)
{
var configuration = c.BuildContext.Get<string>("Configuration");
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
var srcDir = Path.Combine(c.BuildContext.BuildDirectory, "src");
var sdkOutputDirectory = Path.Combine(rootOutputDirectory, "sdk", buildVersion.NuGetVersion);
CopySharedFramework(Dirs.SharedFrameworkPublish, rootOutputDirectory);
FS.CleanBinObj(c, srcDir);
Rmdir(sdkOutputDirectory);
Mkdirp(sdkOutputDirectory);
foreach (var project in ProjectsToPublish)
{
dotnet.Publish(
"--native-subdirectory",
"--output", sdkOutputDirectory,
"--configuration", configuration,
"--version-suffix", buildVersion.CommitCountString,
Path.Combine(srcDir, project))
.Execute()
.EnsureSuccessful();
}
FixModeFlags(sdkOutputDirectory);
string compilersProject = Path.Combine(Dirs.RepoRoot, "src", "compilers");
dotnet.Publish(compilersProject,
"--output",
sdkOutputDirectory,
"--framework",
"netcoreapp1.0")
.Execute()
.EnsureSuccessful();
var compilersDeps = Path.Combine(sdkOutputDirectory, "compilers.deps.json");
var compilersRuntimeConfig = Path.Combine(sdkOutputDirectory, "compilers.runtimeconfig.json");
var binaryToCorehostifyRelDir = Path.Combine("runtimes", "any", "native");
var binaryToCorehostifyOutDir = Path.Combine(sdkOutputDirectory, binaryToCorehostifyRelDir);
// Corehostify binaries
foreach (var binaryToCorehostify in BinariesForCoreHost)
{
try
{
// Yes, it is .exe even on Linux. This is the managed exe we're working with
File.Copy(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"), Path.Combine(sdkOutputDirectory, $"{binaryToCorehostify}.dll"));
File.Move(Path.Combine(binaryToCorehostifyOutDir, $"{binaryToCorehostify}.exe"), Path.Combine(sdkOutputDirectory, $"{binaryToCorehostify}.exe"));
var binaryToCoreHostifyDeps = Path.Combine(sdkOutputDirectory, binaryToCorehostify + ".deps.json");
File.Copy(compilersDeps, Path.Combine(sdkOutputDirectory, binaryToCorehostify + ".deps.json"));
File.Copy(compilersRuntimeConfig, Path.Combine(sdkOutputDirectory, binaryToCorehostify + ".runtimeconfig.json"));
PublishMutationUtilties.ChangeEntryPointLibraryName(binaryToCoreHostifyDeps, binaryToCorehostify);
foreach (var binaryToRemove in new string[] { "csc", "vbc" })
{
var assetPath = Path.Combine(binaryToCorehostifyRelDir, $"{binaryToRemove}.exe").Replace(Path.DirectorySeparatorChar, '/');
RemoveAssetFromDepsPackages.DoRemoveAssetFromDepsPackages(
binaryToCoreHostifyDeps,
"runtimeTargets",
assetPath);
RemoveAssetFromDepsPackages.DoRemoveAssetFromDepsPackages(
Path.Combine(sdkOutputDirectory, "dotnet.deps.json"),
"runtimeTargets",
assetPath);
}
}
catch (Exception ex)
{
return c.Failed($"Failed to corehostify '{binaryToCorehostify}': {ex.ToString()}");
}
}
// cleanup compilers project output we don't need
PublishMutationUtilties.CleanPublishOutput(
sdkOutputDirectory,
"compilers",
deleteRuntimeConfigJson: true,
deleteDepsJson: true);
// Crossgen SDK directory
var sharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion;
var sharedFrameworkNameVersionPath = SharedFrameworkPublisher.GetSharedFrameworkPublishPath(
rootOutputDirectory,
sharedFrameworkNugetVersion);
// Copy Host to SDK Directory
File.Copy(
Path.Combine(sharedFrameworkNameVersionPath, HostArtifactNames.DotnetHostBaseName),
Path.Combine(sdkOutputDirectory, $"corehost{Constants.ExeSuffix}"),
overwrite: true);
File.Copy(
Path.Combine(sharedFrameworkNameVersionPath, HostArtifactNames.DotnetHostFxrBaseName),
Path.Combine(sdkOutputDirectory, HostArtifactNames.DotnetHostFxrBaseName),
overwrite: true);
File.Copy(
Path.Combine(sharedFrameworkNameVersionPath, HostArtifactNames.HostPolicyBaseName),
Path.Combine(sdkOutputDirectory, HostArtifactNames.HostPolicyBaseName),
overwrite: true);
CrossgenUtil.CrossgenDirectory(
sharedFrameworkNameVersionPath,
sdkOutputDirectory);
// Generate .version file
var version = buildVersion.NuGetVersion;
var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}";
File.WriteAllText(Path.Combine(sdkOutputDirectory, ".version"), content);
if(generateNugetPackagesArchive)
{
GenerateNuGetPackagesArchive(c, dotnet, sdkOutputDirectory);
}
CopyMSBuildTargetsToSDKRoot(sdkOutputDirectory);
return c.Success();
}
private static void CopyMSBuildTargetsToSDKRoot(string sdkOutputDirectory)
{
var msbuildTargetsDirectory = Path.Combine(sdkOutputDirectory, "runtimes", "any", "native");
var filesToCopy = new List<string>();
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.targets", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.Targets", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.props", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.overridetasks", SearchOption.AllDirectories));
filesToCopy.AddRange(Directory.EnumerateFiles(msbuildTargetsDirectory, "*.tasks", SearchOption.AllDirectories));
foreach (var fileFullPath in filesToCopy)
{
var fileRelativePath = fileFullPath.Substring(msbuildTargetsDirectory.Length + 1);
var destinationFilePath = Path.Combine(sdkOutputDirectory, fileRelativePath);
File.Copy(fileFullPath, destinationFilePath, true);
}
}
private static void GenerateNuGetPackagesArchive(
BuildTargetContext c,
DotNetCli dotnet,
string sdkOutputDirectory)
{
var nuGetPackagesArchiveProject = Path.Combine(Dirs.Intermediate, "NuGetPackagesArchiveProject");
var nuGetPackagesArchiveFolder = Path.Combine(Dirs.Intermediate, "nuGetPackagesArchiveFolder");
RestoreNuGetPackagesArchive(dotnet, nuGetPackagesArchiveProject, nuGetPackagesArchiveFolder);
CompressNuGetPackagesArchive(c, dotnet, nuGetPackagesArchiveFolder, sdkOutputDirectory);
}
private static void RestoreNuGetPackagesArchive(
DotNetCli dotnet,
string nuGetPackagesArchiveProject,
string nuGetPackagesArchiveFolder)
{
Rmdir(nuGetPackagesArchiveProject);
Mkdirp(nuGetPackagesArchiveProject);
Rmdir(nuGetPackagesArchiveFolder);
Mkdirp(nuGetPackagesArchiveFolder);
dotnet.New()
.WorkingDirectory(nuGetPackagesArchiveProject)
.Execute()
.EnsureSuccessful();
dotnet.Restore("--packages", nuGetPackagesArchiveFolder)
.WorkingDirectory(nuGetPackagesArchiveProject)
.Execute()
.EnsureSuccessful();
}
private static void CompressNuGetPackagesArchive(
BuildTargetContext c,
DotNetCli dotnet,
string nuGetPackagesArchiveFolder,
string sdkOutputDirectory)
{
var configuration = c.BuildContext.Get<string>("Configuration");
var archiverExe = Path.Combine(Dirs.Output, "tools", $"Archiver{Constants.ExeSuffix}");
var intermediateArchive = Path.Combine(Dirs.Intermediate, "nuGetPackagesArchive.lzma");
var finalArchive = Path.Combine(sdkOutputDirectory, "nuGetPackagesArchive.lzma");
Rm(intermediateArchive);
Rm($"{intermediateArchive}.zip");
c.Info("Publishing Archiver");
dotnet.Publish("--output", Path.Combine(Dirs.Output, "tools"), "--configuration", configuration)
.WorkingDirectory(Path.Combine(Dirs.RepoRoot, "tools", "Archiver"))
.Execute()
.EnsureSuccessful();
Cmd(archiverExe,
"-a", intermediateArchive,
nuGetPackagesArchiveFolder)
.Execute();
File.Copy(intermediateArchive, finalArchive);
}
private static void CopySharedFramework(string sharedFrameworkPublish, string rootOutputDirectory)
{
CopyRecursive(sharedFrameworkPublish, rootOutputDirectory);
}
}
}

View file

@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

View file

@ -1,250 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using Microsoft.Build.Framework;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using Microsoft.Build.Utilities;
namespace Microsoft.DotNet.Cli.Build
{
public class DebTargets : Task
{
[Required]
public string CLISDKRoot { get; set; }
public override bool Execute()
{
BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly<DebTargets>().CreateBuildContext();
BuildTargetContext c = new BuildTargetContext(context, null, null);
return GenerateDebs(c).Success;
}
public BuildTargetResult GenerateDebs(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu))
{
PrepareTargets.Init(c);
GenerateSdkDeb(c);
}
return c.Success();
}
public BuildTargetResult GenerateSdkDeb(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu))
{
InstallSharedFramework(c);
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if (DebuildNotPresent())
{
c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}");
return c.Success();
}
var channel = c.BuildContext.Get<string>("Channel").ToLower();
var packageName = CliMonikers.GetSdkDebianPackageName(c);
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
var debFile = c.BuildContext.Get<string>("SdkInstallerFile");
var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages");
var previousVersionURL = $"https://dotnetcli.blob.core.windows.net/dotnet/{channel}/Installers/Latest/dotnet-ubuntu-x64.latest.deb";
var sharedFxDebianPackageName = Monikers.GetDebianSharedFrameworkPackageName(CliDependencyVersions.SharedFrameworkVersion);
var objRoot = Path.Combine(Dirs.Output, "obj", "debian", "sdk");
if (Directory.Exists(objRoot))
{
Directory.Delete(objRoot, true);
}
Directory.CreateDirectory(objRoot);
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"),
"-v", version,
"-i", CLISDKRoot,
"-o", debFile,
"-p", packageName,
"-b", Monikers.CLISdkBrandName,
"-m", manPagesDir,
"--framework-debian-package-name", sharedFxDebianPackageName,
"--framework-nuget-name", Monikers.SharedFrameworkName,
"--framework-nuget-version", CliDependencyVersions.SharedFrameworkVersion,
"--previous-version-url", previousVersionURL,
"--obj-root", objRoot)
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
public static BuildTargetResult TestDebInstaller(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu))
{
InstallSDK(c);
RunE2ETest(c);
RemovePackages(c);
}
return c.Success();
}
public static BuildTargetResult InstallSharedHost(BuildTargetContext c)
{
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if (DebuildNotPresent())
{
c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}");
return c.Success();
}
InstallPackage(c.BuildContext.Get<string>("SharedHostInstallerFile"));
return c.Success();
}
public static BuildTargetResult InstallHostFxr(BuildTargetContext c)
{
InstallSharedHost(c);
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if (DebuildNotPresent())
{
c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}");
return c.Success();
}
InstallPackage(c.BuildContext.Get<string>("HostFxrInstallerFile"));
return c.Success();
}
public static BuildTargetResult InstallSharedFramework(BuildTargetContext c)
{
InstallHostFxr(c);
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if (DebuildNotPresent())
{
c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}");
return c.Success();
}
InstallPackage(c.BuildContext.Get<string>("SharedFrameworkInstallerFile"));
return c.Success();
}
public static BuildTargetResult InstallSDK(BuildTargetContext c)
{
InstallSharedFramework(c);
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if (DebuildNotPresent())
{
c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}");
return c.Success();
}
InstallPackage(c.BuildContext.Get<string>("SdkInstallerFile"));
return c.Success();
}
public static BuildTargetResult RunE2ETest(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu))
{
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if (DebuildNotPresent())
{
c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}");
return c.Success();
}
Directory.SetCurrentDirectory(Path.Combine(Dirs.RepoRoot, "test", "EndToEnd"));
Cmd("dotnet", "build")
.Execute()
.EnsureSuccessful();
var testResultsPath = Path.Combine(Dirs.Output, "obj", "debian", "test", "debian-endtoend-testResults.xml");
Cmd("dotnet", "test", "-xml", testResultsPath)
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
public static BuildTargetResult RemovePackages(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Ubuntu))
{
// Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools
// So we need to skip this target if the tools aren't present.
// https://github.com/dotnet/core-setup/issues/167
if (DebuildNotPresent())
{
c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}");
return c.Success();
}
IEnumerable<string> orderedPackageNames = new List<string>()
{
CliMonikers.GetSdkDebianPackageName(c),
Monikers.GetDebianSharedFrameworkPackageName(CliDependencyVersions.SharedFrameworkVersion),
Monikers.GetDebianHostFxrPackageName(CliDependencyVersions.HostFxrVersion),
Monikers.GetDebianSharedHostPackageName(c)
};
foreach (var packageName in orderedPackageNames)
{
RemovePackage(packageName);
}
}
return c.Success();
}
private static void InstallPackage(string packagePath)
{
Cmd("sudo", "dpkg", "-i", packagePath)
.Execute()
.EnsureSuccessful();
}
private static void RemovePackage(string packageName)
{
Cmd("sudo", "dpkg", "-r", packageName)
.Execute()
.EnsureSuccessful();
}
private static bool DebuildNotPresent()
{
return Cmd("/usr/bin/env", "debuild", "-h").Execute().ExitCode != 0;
}
}
}

View file

@ -1,5 +1,5 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -1,5 +1,5 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -1,5 +1,5 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -1,5 +1,5 @@
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -1,4 +1,7 @@
using Microsoft.Build.Framework;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace Microsoft.DotNet.Cli.Build

View file

@ -1,4 +1,7 @@
using System.IO;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
using System.Net.Http;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

View file

@ -1,4 +1,7 @@
using System.IO.Compression;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO.Compression;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;

View file

@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;

View file

@ -1,4 +1,6 @@
using System.Globalization;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

View file

@ -1,3 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Security.Cryptography;
using Microsoft.Build.Framework;

View file

@ -1,4 +1,7 @@
using Microsoft.Build.Framework;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.InternalAbstractions;

View file

@ -1,28 +0,0 @@
using Microsoft.DotNet.Cli.Build.Framework;
namespace Microsoft.DotNet.Cli.Build
{
public class InstallerTargets
{
public static BuildTargetResult GenerateInstaller(BuildTargetContext c)
{
var debTargets = new DebTargets
{
CLISDKRoot = c.BuildContext.Get<string>("CLISDKRoot")
};
MsiTargets.GenerateMsisAndBundles(c);
PkgTargets.GeneratePkgs(c);
debTargets.GenerateDebs(c);
return c.Success();
}
public static BuildTargetResult TestInstaller(BuildTargetContext c)
{
DebTargets.TestDebInstaller(c);
return c.Success();
}
}
}

View file

@ -1,9 +1,11 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using Microsoft.DotNet.Cli.Build.Framework;
using Newtonsoft.Json;
namespace Microsoft.DotNet.Cli.Build
{

View file

@ -1,188 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Net.Http;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class MsiTargets
{
private const string ENGINE = "engine.exe";
private const string WixVersion = "3.10.2";
private static string WixRoot
{
get
{
return Path.Combine(Dirs.Output, $"WixTools.{WixVersion}");
}
}
private static string SdkMsi { get; set; }
private static string SdkBundle { get; set; }
private static string HostFxrMsi { get; set; }
private static string SharedHostMsi { get; set; }
private static string SharedFrameworkMsi { get; set; }
private static string SdkEngine { get; set; }
private static string MsiVersion { get; set; }
private static string CliDisplayVersion { get; set; }
private static string CliNugetVersion { get; set; }
private static string Arch { get; } = CurrentArchitecture.Current.ToString();
private static void AcquireWix(BuildTargetContext c)
{
if (File.Exists(Path.Combine(WixRoot, "candle.exe")))
{
return;
}
Directory.CreateDirectory(WixRoot);
c.Info("Downloading WixTools..");
DownloadFile($"https://dotnetcli.blob.core.windows.net/build/wix/wix.{WixVersion}.zip", Path.Combine(WixRoot, "WixTools.zip"));
c.Info("Extracting WixTools..");
ZipFile.ExtractToDirectory(Path.Combine(WixRoot, "WixTools.zip"), WixRoot);
}
private static void DownloadFile(string uri, string destinationPath)
{
using (var httpClient = new HttpClient())
{
var getTask = httpClient.GetStreamAsync(uri);
using (var outStream = File.OpenWrite(destinationPath))
{
getTask.Result.CopyTo(outStream);
}
}
}
public static BuildTargetResult InitMsi(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows))
{
SdkBundle = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile");
SdkMsi = Path.ChangeExtension(SdkBundle, "msi");
SdkEngine = GetEngineName(SdkBundle);
SharedFrameworkMsi = Path.ChangeExtension(c.BuildContext.Get<string>("SharedFrameworkInstallerFile"), "msi");
HostFxrMsi = Path.ChangeExtension(c.BuildContext.Get<string>("HostFxrInstallerFile"), "msi");
SharedHostMsi = Path.ChangeExtension(c.BuildContext.Get<string>("SharedHostInstallerFile"), "msi");
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
MsiVersion = buildVersion.GenerateMsiVersion();
CliDisplayVersion = buildVersion.SimpleVersion;
CliNugetVersion = buildVersion.NuGetVersion;
AcquireWix(c);
}
return c.Success();
}
public static BuildTargetResult GenerateMsisAndBundles(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows))
{
InitMsi(c);
GenerateCliSdkMsi(c);
GenerateCliSdkBundle(c);
}
return c.Success();
}
public static BuildTargetResult GenerateCliSdkMsi(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows))
{
var cliSdkRoot = c.BuildContext.Get<string>("CLISDKRoot");
var upgradeCode = GenerateGuidFromName.GenerateGuid(SdkMsi).ToString().ToUpper();
var cliSdkBrandName = $"'{Monikers.CLISdkBrandName}'";
Cmd("powershell", "-NoProfile", "-NoLogo",
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "clisdk", "generatemsi.ps1"),
cliSdkRoot, SdkMsi, WixRoot, cliSdkBrandName, MsiVersion, CliDisplayVersion, CliNugetVersion, upgradeCode, Arch)
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
public static BuildTargetResult GenerateCliSdkBundle(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows))
{
var upgradeCode = GenerateGuidFromName.GenerateGuid(SdkBundle).ToString().ToUpper();
var cliSdkBrandName = $"'{Monikers.CLISdkBrandName}'";
Cmd("powershell", "-NoProfile", "-NoLogo",
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "clisdk", "generatebundle.ps1"),
SdkMsi, SharedFrameworkMsi, HostFxrMsi, SharedHostMsi, SdkBundle, WixRoot, cliSdkBrandName, MsiVersion, CliDisplayVersion, CliNugetVersion, upgradeCode, Arch)
.EnvironmentVariable("Stage2Dir", Dirs.Stage2)
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
// TODO: The following "Engine" tasks need to be separate MSBuild targets so the Windows
// VSO build can invoke them directly for signing.
[Target(nameof(MsiTargets.InitMsi))]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult ExtractEngineFromBundle(BuildTargetContext c)
{
ExtractEngineFromBundleHelper(SdkBundle, SdkEngine);
return c.Success();
}
[Target(nameof(MsiTargets.InitMsi))]
[BuildPlatforms(BuildPlatform.Windows)]
public static BuildTargetResult ReattachEngineToBundle(BuildTargetContext c)
{
ReattachEngineToBundleHelper(SdkBundle, SdkEngine);
return c.Success();
}
private static void ExtractEngineFromBundleHelper(string bundle, string engine)
{
Cmd($"{WixRoot}\\insignia.exe", "-ib", bundle, "-o", engine)
.Execute()
.EnsureSuccessful();
}
private static void ReattachEngineToBundleHelper(string bundle, string engine)
{
Cmd($"{WixRoot}\\insignia.exe", "-ab", engine, bundle, "-o", bundle)
.Execute()
.EnsureSuccessful();
File.Delete(engine);
}
private static string GetEngineName(string bundle)
{
var engine = $"{Path.GetFileNameWithoutExtension(bundle)}-{ENGINE}";
return Path.Combine(Path.GetDirectoryName(bundle), engine);
}
}
}

View file

@ -1,32 +0,0 @@
using System.IO;
using System.Reflection;
using Microsoft.DotNet.Cli.Build.Framework;
using NugetProgram = NuGet.CommandLine.XPlat.Program;
namespace Microsoft.DotNet.Cli.Build
{
public static class NuGetUtil
{
public static void PushPackages(string packagesPath, string destinationUrl, string apiKey)
{
int result = RunNuGetCommand(
"push",
"-s", destinationUrl,
"-k", apiKey,
Path.Combine(packagesPath, "*.nupkg"));
if (result != 0)
{
throw new BuildFailureException($"NuGet Push failed with exit code '{result}'.");
}
}
private static int RunNuGetCommand(params string[] nugetArgs)
{
var nugetAssembly = typeof(NugetProgram).GetTypeInfo().Assembly;
var mainMethod = nugetAssembly.EntryPoint;
return (int)mainMethod.Invoke(null, new object[] { nugetArgs });
}
}
}

View file

@ -1,326 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class PackageTargets : Task
{
public static readonly string[] ProjectsToPack = new string[]
{
// TODO: https://github.com/dotnet/cli/issues/3558
// "dotnet-compile-fsc",
"Microsoft.DotNet.Cli.Utils",
"Microsoft.DotNet.Compiler.Common",
"Microsoft.DotNet.Files",
"Microsoft.DotNet.InternalAbstractions",
"Microsoft.DotNet.ProjectModel",
"Microsoft.DotNet.ProjectModel.Loader",
"Microsoft.DotNet.ProjectModel.Workspaces",
"Microsoft.Extensions.DependencyModel",
"Microsoft.Extensions.Testing.Abstractions"
};
public override bool Execute()
{
BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly<PackageTargets>().CreateBuildContext();
BuildTargetContext c = new BuildTargetContext(context, null, null);
return Package(c).Success;
}
public static BuildTargetResult InitPackage(BuildTargetContext c)
{
CopyCLISDKLayout(c);
CopySharedHostLayout(c);
CopyHostFxrLayout(c);
CopySharedFxLayout(c);
CopyCombinedFrameworkSDKHostLayout(c);
CopyCombinedFrameworkSDKLayout(c);
Directory.CreateDirectory(Dirs.Packages);
return c.Success();
}
[Target]
public static BuildTargetResult Package(BuildTargetContext c)
{
if (!EnvVars.GetBool("DOTNET_BUILD_SKIP_PACKAGING"))
{
PrepareTargets.Init(c);
InitPackage(c);
GenerateVersionBadge(c);
GenerateCompressedFile(c);
InstallerTargets.GenerateInstaller(c);
GenerateNugetPackages(c);
InstallerTargets.TestInstaller(c);
}
return c.Success();
}
public static BuildTargetResult GenerateVersionBadge(BuildTargetContext c)
{
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
var versionSvg = Path.Combine(Dirs.RepoRoot, "resources", "images", "version_badge.svg");
var outputVersionSvg = c.BuildContext.Get<string>("VersionBadge");
var versionSvgContent = File.ReadAllText(versionSvg);
versionSvgContent = versionSvgContent.Replace("ver_number", buildVersion.NuGetVersion);
File.WriteAllText(outputVersionSvg, versionSvgContent);
return c.Success();
}
public static BuildTargetResult CopyCLISDKLayout(BuildTargetContext c)
{
var cliSdkRoot = Path.Combine(Dirs.Output, "obj", "clisdk");
if (Directory.Exists(cliSdkRoot))
{
Utils.DeleteDirectory(cliSdkRoot);
}
Directory.CreateDirectory(cliSdkRoot);
Utils.CopyDirectoryRecursively(Path.Combine(Dirs.Stage2, "sdk"), cliSdkRoot, true);
FixPermissions(cliSdkRoot);
c.BuildContext["CLISDKRoot"] = cliSdkRoot;
return c.Success();
}
public static BuildTargetResult CopySharedHostLayout(BuildTargetContext c)
{
var sharedHostRoot = Path.Combine(Dirs.Output, "obj", "sharedHost");
if (Directory.Exists(sharedHostRoot))
{
Utils.DeleteDirectory(sharedHostRoot);
}
Directory.CreateDirectory(sharedHostRoot);
foreach (var file in Directory.GetFiles(Dirs.Stage2, "*", SearchOption.TopDirectoryOnly))
{
var destFile = file.Replace(Dirs.Stage2, sharedHostRoot);
File.Copy(file, destFile, true);
}
FixPermissions(sharedHostRoot);
c.BuildContext["SharedHostPublishRoot"] = sharedHostRoot;
return c.Success();
}
public static BuildTargetResult CopyHostFxrLayout(BuildTargetContext c)
{
var hostFxrRoot = Path.Combine(Dirs.Output, "obj", "hostFxr");
if (Directory.Exists(hostFxrRoot))
{
Utils.DeleteDirectory(hostFxrRoot);
}
Directory.CreateDirectory(hostFxrRoot);
Utils.CopyDirectoryRecursively(Path.Combine(Dirs.Stage2, "host"), hostFxrRoot, true);
FixPermissions(hostFxrRoot);
c.BuildContext["HostFxrPublishRoot"] = hostFxrRoot;
return c.Success();
}
public static BuildTargetResult CopySharedFxLayout(BuildTargetContext c)
{
var sharedFxRoot = Path.Combine(Dirs.Output, "obj", "sharedFx");
if (Directory.Exists(sharedFxRoot))
{
Utils.DeleteDirectory(sharedFxRoot);
}
Directory.CreateDirectory(sharedFxRoot);
Utils.CopyDirectoryRecursively(Path.Combine(Dirs.Stage2, "shared"), sharedFxRoot, true);
FixPermissions(sharedFxRoot);
c.BuildContext["SharedFrameworkPublishRoot"] = sharedFxRoot;
return c.Success();
}
public static BuildTargetResult CopyCombinedFrameworkSDKHostLayout(BuildTargetContext c)
{
var combinedRoot = Path.Combine(Dirs.Output, "obj", "combined-framework-sdk-host");
if (Directory.Exists(combinedRoot))
{
Utils.DeleteDirectory(combinedRoot);
}
string sdkPublishRoot = c.BuildContext.Get<string>("CLISDKRoot");
Utils.CopyDirectoryRecursively(sdkPublishRoot, combinedRoot);
string sharedFrameworkPublishRoot = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
Utils.CopyDirectoryRecursively(sharedFrameworkPublishRoot, combinedRoot);
string sharedHostPublishRoot = c.BuildContext.Get<string>("SharedHostPublishRoot");
Utils.CopyDirectoryRecursively(sharedHostPublishRoot, combinedRoot);
string hostFxrPublishRoot = c.BuildContext.Get<string>("HostFxrPublishRoot");
Utils.CopyDirectoryRecursively(hostFxrPublishRoot, combinedRoot);
c.BuildContext["CombinedFrameworkSDKHostRoot"] = combinedRoot;
return c.Success();
}
public static BuildTargetResult CopyCombinedFrameworkSDKLayout(BuildTargetContext c)
{
var combinedRoot = Path.Combine(Dirs.Output, "obj", "combined-framework-sdk");
if (Directory.Exists(combinedRoot))
{
Utils.DeleteDirectory(combinedRoot);
}
string sdkPublishRoot = c.BuildContext.Get<string>("CLISDKRoot");
Utils.CopyDirectoryRecursively(sdkPublishRoot, combinedRoot);
string sharedFrameworkPublishRoot = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
Utils.CopyDirectoryRecursively(sharedFrameworkPublishRoot, combinedRoot);
c.BuildContext["CombinedFrameworkSDKRoot"] = combinedRoot;
return c.Success();
}
public static BuildTargetResult GenerateCompressedFile(BuildTargetContext c)
{
GenerateZip(c);
GenerateTarBall(c);
return c.Success();
}
public static BuildTargetResult GenerateZip(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows))
{
CreateZipFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"));
CreateZipFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKCompressedFile"));
CreateZipFromDirectory(Path.Combine(Dirs.Stage2Symbols, "sdk"), c.BuildContext.Get<string>("SdkSymbolsCompressedFile"));
}
return c.Success();
}
public static BuildTargetResult GenerateTarBall(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Unix))
{
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"));
CreateTarBallFromDirectory(Path.Combine(Dirs.Stage2Symbols, "sdk"), c.BuildContext.Get<string>("SdkSymbolsCompressedFile"));
}
return c.Success();
}
public static BuildTargetResult GenerateNugetPackages(BuildTargetContext c)
{
var versionSuffix = c.BuildContext.Get<BuildVersion>("BuildVersion").CommitCountString;
var configuration = c.BuildContext.Get<string>("Configuration");
var env = GetCommonEnvVars(c);
var dotnet = DotNetCli.Stage2;
var packagingBuildBasePath = Path.Combine(Dirs.Stage2Compilation, "forPackaging");
FS.Mkdirp(Dirs.Packages);
foreach (var projectName in ProjectsToPack)
{
var projectFile = Path.Combine(Dirs.RepoRoot, "src", projectName, "project.json");
dotnet.Pack(
projectFile,
"--no-build",
"--serviceable",
"--build-base-path", packagingBuildBasePath,
"--output", Dirs.Packages,
"--configuration", configuration,
"--version-suffix", versionSuffix)
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
internal static Dictionary<string, string> GetCommonEnvVars(BuildTargetContext c)
{
// Set up the environment variables previously defined by common.sh/ps1
// This is overkill, but I want to cover all the variables used in all OSes (including where some have the same names)
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
var configuration = c.BuildContext.Get<string>("Configuration");
var architecture = RuntimeEnvironment.RuntimeArchitecture;
var env = new Dictionary<string, string>()
{
{ "RID", RuntimeEnvironment.GetRuntimeIdentifier() },
{ "OSNAME", RuntimeEnvironment.OperatingSystem },
{ "TFM", "dnxcore50" },
{ "REPOROOT", Dirs.RepoRoot },
{ "OutputDir", Dirs.Output },
{ "Stage1Dir", Dirs.Stage1 },
{ "Stage1CompilationDir", Dirs.Stage1Compilation },
{ "Stage2Dir", Dirs.Stage2 },
{ "STAGE2_DIR", Dirs.Stage2 },
{ "Stage2CompilationDir", Dirs.Stage2Compilation },
{ "PackageDir", Path.Combine(Dirs.Packages) }, // Legacy name
{ "TestBinRoot", Dirs.TestOutput },
{ "TestPackageDir", Dirs.TestPackages },
{ "MajorVersion", buildVersion.Major.ToString() },
{ "MinorVersion", buildVersion.Minor.ToString() },
{ "PatchVersion", buildVersion.Patch.ToString() },
{ "CommitCountVersion", buildVersion.CommitCountString },
{ "COMMIT_COUNT_VERSION", buildVersion.CommitCountString },
{ "DOTNET_CLI_VERSION", buildVersion.SimpleVersion },
{ "DOTNET_MSI_VERSION", buildVersion.GenerateMsiVersion() },
{ "VersionSuffix", buildVersion.VersionSuffix },
{ "CONFIGURATION", configuration },
{ "ARCHITECTURE", architecture }
};
return env;
}
private static void CreateZipFromDirectory(string directory, string artifactPath)
{
if (File.Exists(artifactPath))
{
File.Delete(artifactPath);
}
ZipFile.CreateFromDirectory(directory, artifactPath, CompressionLevel.Optimal, false);
}
private static void CreateTarBallFromDirectory(string directory, string artifactPath)
{
if (File.Exists(artifactPath))
{
File.Delete(artifactPath);
}
Cmd("tar", "-czf", artifactPath, "-C", directory, ".")
.Execute()
.EnsureSuccessful();
}
private static void FixPermissions(string directory)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Reset everything to user readable/writeable and group and world readable.
FS.ChmodAll(directory, "*", "644");
// Now make things that should be executable, executable.
FS.FixModeFlags(directory);
}
}
}
}

View file

@ -1,143 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using Microsoft.Build.Utilities;
namespace Microsoft.DotNet.Cli.Build
{
public class PkgTargets : Task
{
public static string PkgsIntermediateDir { get; set; }
public static string SharedHostComponentId { get; set; }
public static string SharedFxComponentId { get; set; }
public static string SharedFxPkgId { get; set; }
public static string SharedFrameworkNugetVersion { get; set; }
public static string CLISdkComponentId { get; set; }
public static string CLISdkPkgId { get; set; }
public static string CLISdkNugetVersion { get; set; }
public static string HostFxrComponentId { get; set; }
public static BuildTargetResult InitPkg(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.OSX))
{
PkgsIntermediateDir = Path.Combine(Dirs.Packages, "intermediate");
Directory.CreateDirectory(PkgsIntermediateDir);
SharedHostComponentId = $"com.microsoft.dotnet.sharedhost.component.osx.x64";
HostFxrComponentId = $"com.microsoft.dotnet.hostfxr.component.osx.x64";
string sharedFrameworkNugetName = Monikers.SharedFrameworkName;
SharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion;
SharedFxComponentId = $"com.microsoft.dotnet.sharedframework.{sharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.component.osx.x64";
SharedFxPkgId = $"com.microsoft.dotnet.{sharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.osx.x64";
CLISdkNugetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
CLISdkComponentId = $"com.microsoft.dotnet.dev.{CLISdkNugetVersion}.component.osx.x64";
CLISdkPkgId = $"com.microsoft.dotnet.dev.{CLISdkNugetVersion}.osx.x64";
}
return c.Success();
}
public override bool Execute()
{
BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly<DebTargets>().CreateBuildContext();
BuildTargetContext c = new BuildTargetContext(context, null, null);
return GeneratePkgs(c).Success;
}
public static BuildTargetResult GeneratePkgs(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.OSX))
{
PrepareTargets.Init(c);
InitPkg(c);
GenerateCLISdkProductArchive(c);
}
return c.Success();
}
public static BuildTargetResult GenerateCLISdkProductArchive(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.OSX))
{
GenerateCLISdkPkg(c);
string resourcePath = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "clisdk", "resources");
string outFilePath = Path.Combine(Dirs.Packages, c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile"));
// Copy SharedFX and host installers in the correct place
var sharedFrameworkPkgIntermediatePath = Path.Combine(PkgsIntermediateDir, $"{SharedFxComponentId}.pkg");
var sharedHostPkgIntermediatePath = Path.Combine(PkgsIntermediateDir, $"{SharedHostComponentId}.pkg");
var hostFxrPkgIntermediatePath = Path.Combine(PkgsIntermediateDir, $"{HostFxrComponentId}.pkg");
File.Copy(c.BuildContext.Get<string>("SharedFrameworkInstallerFile"), sharedFrameworkPkgIntermediatePath, true);
File.Copy(c.BuildContext.Get<string>("SharedHostInstallerFile"), sharedHostPkgIntermediatePath, true);
File.Copy(c.BuildContext.Get<string>("HostFxrInstallerFile"), hostFxrPkgIntermediatePath, true);
string inputDistTemplatePath = Path.Combine(
Dirs.RepoRoot,
"packaging",
"osx",
"clisdk",
"Distribution-Template");
string distTemplate = File.ReadAllText(inputDistTemplatePath);
string distributionPath = Path.Combine(PkgsIntermediateDir, "CLI-SDK-Formatted-Distribution-Template.xml");
string formattedDistContents =
distTemplate.Replace("{SharedFxComponentId}", SharedFxComponentId)
.Replace("{SharedHostComponentId}", SharedHostComponentId)
.Replace("{HostFxrComponentId}", HostFxrComponentId)
.Replace("{CLISdkComponentId}", CLISdkComponentId)
.Replace("{CLISdkNugetVersion}", CLISdkNugetVersion)
.Replace("{CLISdkBrandName}", Monikers.CLISdkBrandName)
.Replace("{SharedFxBrandName}", Monikers.SharedFxBrandName)
.Replace("{SharedHostBrandName}", Monikers.SharedHostBrandName)
.Replace("{HostFxrBrandName}", Monikers.HostFxrBrandName);
File.WriteAllText(distributionPath, formattedDistContents);
Cmd("productbuild",
"--version", CLISdkNugetVersion,
"--identifier", CLISdkPkgId,
"--package-path", PkgsIntermediateDir,
"--resources", resourcePath,
"--distribution", distributionPath,
outFilePath)
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
public static BuildTargetResult GenerateCLISdkPkg(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.OSX))
{
string outFilePath = Path.Combine(PkgsIntermediateDir, CLISdkComponentId + ".pkg");
string installLocation = "/usr/local/share/dotnet";
string scriptsLocation = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "clisdk", "scripts");
Cmd("pkgbuild",
"--root", c.BuildContext.Get<string>("CLISDKRoot"),
"--identifier", CLISdkComponentId,
"--version", CLISdkNugetVersion,
"--install-location", installLocation,
"--scripts", scriptsLocation,
outFilePath)
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
}
}

View file

@ -1,4 +1,7 @@
using System;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@ -12,26 +15,8 @@ using static Microsoft.DotNet.Cli.Build.Utils;
namespace Microsoft.DotNet.Cli.Build
{
public class PrepareTargets : Task
public class PrepareTargets
{
public override bool Execute()
{
BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly<PrepareTargets>().CreateBuildContext();
BuildTargetContext c = new BuildTargetContext(context, null, null);
return Prepare(c).Success;
}
[Target]
public static BuildTargetResult Prepare(BuildTargetContext c)
{
Init(c);
DownloadHostAndSharedFxArtifacts(c);
RestorePackages(c);
ZipTemplates(c);
return c.Success();
}
// All major targets will depend on this in order to ensure variables are set up right if they are run independently
public static BuildTargetResult Init(BuildTargetContext c)

View file

@ -1,17 +0,0 @@
using Microsoft.DotNet.Cli.Build.Framework;
namespace Microsoft.DotNet.Cli.Build
{
public class Program
{
public static int Main(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
return BuildSetup.Create(".NET Core CLI")
.UseStandardGoals()
.UseAllTargetsFromAssembly<Program>()
.Run(args);
}
}
}

View file

@ -1,4 +1,7 @@
using System;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

View file

@ -1,18 +1,12 @@
using System;
using System.Collections.Generic;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Net.Http;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework;
using Microsoft.DotNet.InternalAbstractions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
namespace Microsoft.DotNet.Cli.Build
{
public class RemoveAssetFromDepsPackages : Task

View file

@ -1,4 +1,7 @@
using System;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;

View file

@ -1,4 +1,7 @@
using System;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

View file

@ -1,222 +0,0 @@
using Microsoft.DotNet.Cli.Build.Framework;
namespace Microsoft.DotNet.Cli.Build
{
public static class TestPackageProjects
{
public class TestPackageProject
{
public string Name { get; set; }
public bool IsTool { get; set; }
public string Path { get; set; }
public bool IsApplicable { get; set; }
public string VersionSuffix { get; set; }
public bool Clean { get; set; }
public string[] Frameworks { get; set; }
}
private static string s_testPackageBuildVersionSuffix = "<buildversion>";
public static string TestPackageBuildVersionSuffix
{
get
{
return s_testPackageBuildVersionSuffix;
}
}
public static readonly TestPackageProject[] Projects = new[]
{
new TestPackageProject()
{
Name = "PackageWithFakeNativeDep",
IsTool = false,
Path = "TestAssets/TestPackages/PackageWithFakeNativeDep",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true,
Frameworks = new [] { "net45" }
},
new TestPackageProject()
{
Name = "dotnet-dependency-context-test",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-dependency-context-test",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
},
new TestPackageProject()
{
Name = "dotnet-dependency-tool-invoker",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-dependency-tool-invoker",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
},
new TestPackageProject()
{
Name = "dotnet-desktop-and-portable",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-desktop-and-portable",
IsApplicable = CurrentPlatform.IsWindows,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true,
Frameworks = new [] { "net451", "netcoreapp1.0" }
},
new TestPackageProject()
{
Name = "dotnet-desktop-binding-redirects",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-desktop-binding-redirects",
IsApplicable = CurrentPlatform.IsWindows,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true,
Frameworks = new [] { "net451" }
},
new TestPackageProject()
{
Name = "dotnet-hello",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello",
IsApplicable =true,
VersionSuffix = string.Empty,
Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
},
new TestPackageProject()
{
Name = "dotnet-hello",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello",
IsApplicable = true,
VersionSuffix = string.Empty,
Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
},
new TestPackageProject()
{
Name = "dotnet-portable",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-portable",
IsApplicable = true,
VersionSuffix = string.Empty,
Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
},
new TestPackageProject()
{
Name = "ToolWithOutputName",
IsTool = true,
Path = "TestAssets/TestPackages/ToolWithOutputName",
IsApplicable = true,
VersionSuffix = string.Empty,
Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
},
new TestPackageProject()
{
Name = "Microsoft.DotNet.Cli.Utils",
IsTool = true,
Path = "src/Microsoft.DotNet.Cli.Utils",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "net451", "netstandard1.6" }
},
new TestPackageProject()
{
Name = "Microsoft.DotNet.ProjectModel",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "net451", "netstandard1.6" }
},
new TestPackageProject()
{
Name = "Microsoft.DotNet.ProjectModel.Loader",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel.Loader",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "netstandard1.6" }
},
new TestPackageProject()
{
Name = "Microsoft.DotNet.ProjectModel.Workspaces",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel.Workspaces",
IsApplicable =true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "netstandard1.6" }
},
new TestPackageProject()
{
Name = "Microsoft.DotNet.InternalAbstractions",
IsTool = true,
Path = "src/Microsoft.DotNet.InternalAbstractions",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "net451", "netstandard1.3" }
},
new TestPackageProject()
{
Name = "Microsoft.Extensions.DependencyModel",
IsTool = true,
Path = "src/Microsoft.Extensions.DependencyModel",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "net451", "netstandard1.6" }
},
new TestPackageProject()
{
Name = "Microsoft.Extensions.Testing.Abstractions",
IsTool = true,
Path = "src/Microsoft.Extensions.Testing.Abstractions",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "net451", "netstandard1.6" }
},
new TestPackageProject()
{
Name = "Microsoft.DotNet.Compiler.Common",
IsTool = true,
Path = "src/Microsoft.DotNet.Compiler.Common",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "netstandard1.6" }
},
new TestPackageProject()
{
Name = "Microsoft.DotNet.Files",
IsTool = true,
Path = "src/Microsoft.DotNet.Files",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false,
Frameworks = new [] { "netstandard1.6" }
},
new TestPackageProject()
{
Name = "dotnet-compile-fsc",
IsTool = true,
Path = "src/dotnet-compile-fsc",
IsApplicable = true,
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true,
Frameworks = new [] { "netcoreapp1.0" }
}
};
}
}

View file

@ -1,443 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Cli.Build.Framework;
using static Microsoft.DotNet.Cli.Build.FS;
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
using static Microsoft.DotNet.Cli.Build.Utils;
using Microsoft.Build.Utilities;
namespace Microsoft.DotNet.Cli.Build
{
public class TestTargets : Task
{
private static string s_testPackageBuildVersionSuffix = "<buildversion>";
public static readonly string[] TestProjects = new[]
{
"ArgumentForwardingTests",
"crossgen.Tests",
"EndToEnd",
"dotnet.Tests",
"dotnet-build.Tests",
"dotnet-build3.Tests",
"dotnet-compile.Tests",
"dotnet-compile.UnitTests",
// TODO: https://github.com/dotnet/cli/issues/3558
// "dotnet-compile-fsc.Tests",
"dotnet-new.Tests",
"dotnet-pack.Tests",
"dotnet-publish.Tests",
"dotnet-resgen.Tests",
"dotnet-run.Tests",
"dotnet-run.UnitTests",
"dotnet-test.Tests",
"dotnet-test.UnitTests",
// TODO: https://github.com/dotnet/cli/issues/3216
//"Kestrel.Tests",
"Microsoft.DotNet.Cli.Utils.Tests",
"Microsoft.DotNet.Compiler.Common.Tests",
"Microsoft.DotNet.ProjectModel.Tests",
"Microsoft.DotNet.ProjectModel.Loader.Tests",
"Microsoft.Extensions.DependencyModel.Tests",
"Microsoft.DotNet.Configurer.UnitTests",
"Performance"
};
public static readonly string[] WindowsTestProjects = new[]
{
"binding-redirects.Tests"
};
public static readonly dynamic[] ConditionalTestAssets = new[]
{
new { Path = "AppWithDirectDependencyDesktopAndPortable", Skip = new Func<bool>(() => !CurrentPlatform.IsWindows) }
};
public override bool Execute()
{
BuildContext context = new BuildSetup("MSBuild").UseAllTargetsFromAssembly<TestTargets>().CreateBuildContext();
BuildTargetContext c = new BuildTargetContext(context, null, null);
return Test(c).Success;
}
[Target]
public static BuildTargetResult Test(BuildTargetContext c)
{
PrepareTargets.Init(c);
SetupTests(c);
RestoreTests(c);
BuildTests(c);
RunTests(c);
return c.Success();
}
public static BuildTargetResult SetupTests(BuildTargetContext c)
{
SetupTestPackages(c);
SetupTestProjects(c);
return c.Success();
}
public static BuildTargetResult SetupTestPackages(BuildTargetContext c)
{
RestoreTestAssetPackages(c);
BuildTestAssetPackages(c);
return c.Success();
}
public static BuildTargetResult SetupTestProjects(BuildTargetContext c)
{
RestoreTestAssetProjects(c);
RestoreDesktopTestAssetProjects(c);
BuildTestAssetProjects(c);
BuildDesktopTestAssetProjects(c);
return c.Success();
}
public static BuildTargetResult RestoreTestAssetPackages(BuildTargetContext c)
{
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
CleanNuGetTempCache();
var dotnet = DotNetCli.Stage2;
dotnet.Restore("--verbosity", "verbose")
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages"))
.Execute()
.EnsureSuccessful();
return c.Success();
}
public static BuildTargetResult RestoreTestAssetProjects(BuildTargetContext c)
{
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
CleanNuGetTempCache();
var dotnet = DotNetCli.Stage2;
dotnet.Restore(
"--verbosity", "verbose",
"--fallbacksource", Dirs.TestPackages)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"))
.Execute()
.EnsureSuccessful();
return c.Success();
}
public static BuildTargetResult RestoreDesktopTestAssetProjects(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows))
{
var dotnet = DotNetCli.Stage2;
dotnet.Restore("--verbosity", "verbose",
"--infer-runtimes",
"--fallbacksource", Dirs.TestPackages)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "DesktopTestProjects"))
.Execute().EnsureSuccessful();
}
return c.Success();
}
public static BuildTargetResult BuildTestAssetPackages(BuildTargetContext c)
{
CleanTestPackages(c);
CleanProductPackages(c);
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages"));
var dotnet = DotNetCli.Stage2;
Rmdir(Dirs.TestPackages);
Mkdirp(Dirs.TestPackages);
foreach (var testPackageProject in TestPackageProjects.Projects.Where(p => p.IsApplicable))
{
var relativePath = testPackageProject.Path;
var versionSuffix = testPackageProject.VersionSuffix;
if (versionSuffix.Equals(s_testPackageBuildVersionSuffix))
{
versionSuffix = c.BuildContext.Get<BuildVersion>("BuildVersion").CommitCountString;
}
var fullPath = Path.Combine(c.BuildContext.BuildDirectory, relativePath.Replace('/', Path.DirectorySeparatorChar));
c.Info($"Packing: {fullPath}");
var packageBuildFrameworks = testPackageProject.Frameworks.ToList();
if (!CurrentPlatform.IsWindows)
{
packageBuildFrameworks.RemoveAll(f => f.StartsWith("net4"));
}
foreach (var packageBuildFramework in packageBuildFrameworks)
{
var buildArgs = new List<string>();
buildArgs.Add("-f");
buildArgs.Add(packageBuildFramework);
buildArgs.Add("--build-base-path");
buildArgs.Add(Dirs.TestPackagesBuild);
buildArgs.Add(fullPath);
Mkdirp(Dirs.TestPackagesBuild);
dotnet.Build(buildArgs.ToArray())
.Execute()
.EnsureSuccessful();
}
var projectJson = Path.Combine(fullPath, "project.json");
var dotnetPackArgs = new List<string> {
projectJson,
"--no-build",
"--build-base-path", Dirs.TestPackagesBuild,
"--output", Dirs.TestPackages
};
if (!string.IsNullOrEmpty(versionSuffix))
{
dotnetPackArgs.Add("--version-suffix");
dotnetPackArgs.Add(versionSuffix);
}
dotnet.Pack(dotnetPackArgs.ToArray())
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
public static BuildTargetResult CleanProductPackages(BuildTargetContext c)
{
foreach (var packageName in PackageTargets.ProjectsToPack)
{
Rmdir(Path.Combine(Dirs.NuGetPackages, packageName));
}
return c.Success();
}
public static BuildTargetResult CleanTestPackages(BuildTargetContext c)
{
foreach (var packageProject in TestPackageProjects.Projects.Where(p => p.IsApplicable && p.Clean))
{
Rmdir(Path.Combine(Dirs.NuGetPackages, packageProject.Name));
if (packageProject.IsTool)
{
Rmdir(Path.Combine(Dirs.NuGetPackages, ".tools", packageProject.Name));
}
}
return c.Success();
}
public static BuildTargetResult BuildTestAssetProjects(BuildTargetContext c)
{
var testAssetsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects");
var dotnet = DotNetCli.Stage2;
var framework = "netcoreapp1.0";
return BuildTestAssets(c, testAssetsRoot, dotnet, framework);
}
public static BuildTargetResult BuildDesktopTestAssetProjects(BuildTargetContext c)
{
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows))
{
var testAssetsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "DesktopTestProjects");
var dotnet = DotNetCli.Stage2;
var framework = "net451";
return BuildTestAssets(c, testAssetsRoot, dotnet, framework);
}
return c.Success();
}
public static BuildTargetResult RestoreTests(BuildTargetContext c)
{
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
CleanNuGetTempCache();
DotNetCli.Stage2.Restore("--verbosity", "verbose",
"--fallbacksource", Dirs.TestPackages)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test"))
.Execute()
.EnsureSuccessful();
return c.Success();
}
public static BuildTargetResult BuildTests(BuildTargetContext c)
{
var dotnet = DotNetCli.Stage2;
var configuration = c.BuildContext.Get<string>("Configuration");
foreach (var testProject in GetTestProjects())
{
c.Info($"Building tests: {testProject}");
dotnet.Build("--configuration", configuration)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test", testProject))
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
public static BuildTargetResult RunTests(BuildTargetContext c)
{
RunXUnitTests(c);
return c.Success();
}
public static BuildTargetResult RunXUnitTests(BuildTargetContext c)
{
// Need to load up the VS Vars
var dotnet = DotNetCli.Stage2;
var vsvars = LoadVsVars(c);
var configuration = c.BuildContext.Get<string>("Configuration");
// Copy the test projects
var testProjectsDir = Path.Combine(Dirs.TestOutput, "TestProjects");
Rmdir(testProjectsDir);
Mkdirp(testProjectsDir);
CopyRecursive(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"), testProjectsDir);
// Run the tests and set the VS vars in the environment when running them
var failingTests = new List<string>();
foreach (var project in GetTestProjects())
{
c.Info($"Running tests in: {project}");
var result = dotnet.Test("--configuration", configuration, "-xml", $"{project}-testResults.xml", "-notrait", "category=failing")
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test", project))
.Environment(vsvars)
.EnvironmentVariable("PATH", $"{DotNetCli.Stage2.BinPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}")
.EnvironmentVariable("TEST_ARTIFACTS", Dirs.TestArtifacts)
.Execute();
if (result.ExitCode != 0)
{
failingTests.Add(project);
}
}
if (failingTests.Any())
{
foreach (var project in failingTests)
{
c.Error($"{project} failed");
}
return c.Failed("Tests failed!");
}
return c.Success();
}
private static IEnumerable<string> GetTestProjects()
{
List<string> testProjects = new List<string>();
testProjects.AddRange(TestProjects);
if (CurrentPlatform.IsWindows)
{
testProjects.AddRange(WindowsTestProjects);
}
return testProjects;
}
private static BuildTargetResult BuildTestAssets(BuildTargetContext c, string testAssetsRoot, DotNetCli dotnet, string framework)
{
CleanBinObj(c, testAssetsRoot);
var nobuildFileName = ".noautobuild";
var projects = Directory.GetFiles(testAssetsRoot, "project.json", SearchOption.AllDirectories)
.Where(p => !ConditionalTestAssets.Where(s => !s.Skip() && p.EndsWith(Path.Combine(s.Path, "project.json"))).Any())
.Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), nobuildFileName)));
foreach (var project in projects)
{
c.Info($"Building: {project}");
dotnet.Build("--framework", framework)
.WorkingDirectory(Path.GetDirectoryName(project))
.Execute()
.EnsureSuccessful();
}
return c.Success();
}
private static Dictionary<string, string> LoadVsVars(BuildTargetContext c)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return new Dictionary<string, string>();
}
c.Verbose("Start Collecting Visual Studio Environment Variables");
var vsvarsPath = Path.GetFullPath(Path.Combine(Environment.GetEnvironmentVariable("VS140COMNTOOLS"), "..", "..", "VC"));
// Write a temp batch file because that seems to be the easiest way to do this (argument parsing is hard)
var temp = Path.Combine(Path.GetTempPath(), $"{Path.GetRandomFileName()}.cmd");
File.WriteAllText(temp, $@"@echo off
cd {vsvarsPath}
call vcvarsall.bat x64
set");
CommandResult result;
try
{
result = Cmd(Environment.GetEnvironmentVariable("COMSPEC"), "/c", temp)
.WorkingDirectory(vsvarsPath)
.CaptureStdOut()
.Execute();
}
finally
{
if (File.Exists(temp))
{
File.Delete(temp);
}
}
result.EnsureSuccessful();
var vars = new Dictionary<string, string>();
foreach (var line in result.StdOut.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
{
var splat = line.Split(new[] { '=' }, 2);
if (splat.Length == 2)
{
c.Verbose($"Adding variable '{line}'");
vars[splat[0]] = splat[1];
}
else
{
c.Info($"Skipping VS Env Variable. Unknown format: '{line}'");
}
}
c.Verbose("Finish Collecting Visual Studio Environment Variables");
return vars;
}
}
}

View file

@ -2,7 +2,6 @@
"version": "1.0.0-*",
"description": "Build scripts for dotnet-cli",
"buildOptions": {
"emitEntryPoint": true,
"allowUnsafe": true,
"compile": [
"../Microsoft.DotNet.Cli.Build.Framework/**/*.cs",