Merge pull request #1920 from dotnet/cli-sdk-stages
Incorporate the new CLI layout in builds scripts and add Portable Project Tool commands
This commit is contained in:
commit
d5f118273b
41 changed files with 982 additions and 707 deletions
12
TestAssets/TestPackages/dotnet-portable/Program.cs
Normal file
12
TestAssets/TestPackages/dotnet-portable/Program.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ConsoleApplication
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello Portable World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
TestAssets/TestPackages/dotnet-portable/project.json
Normal file
18
TestAssets/TestPackages/dotnet-portable/project.json
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"compilationOptions": {
|
||||||
|
"emitEntryPoint": true
|
||||||
|
},
|
||||||
|
|
||||||
|
"frameworks": {
|
||||||
|
"netstandard1.5": {
|
||||||
|
"imports": [
|
||||||
|
"dnxcore50",
|
||||||
|
"portable-net45+win8"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.NETCore.App": "1.0.0-rc2-23911"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,8 +17,8 @@
|
||||||
},
|
},
|
||||||
"testRunner": "must-be-specified-to-generate-deps",
|
"testRunner": "must-be-specified-to-generate-deps",
|
||||||
"tools": {
|
"tools": {
|
||||||
"dotnet-hello": {
|
"dotnet-portable": {
|
||||||
"version": "2.0.0",
|
"version": "1.0.0",
|
||||||
"target": "package"
|
"target": "package"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tools": {
|
"tools": {
|
||||||
"dotnet-hello": {
|
"dotnet-portable": {
|
||||||
"version": "2.0.0",
|
"version": "1.0.0",
|
||||||
"target": "package"
|
"target": "package"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
||||||
<installer-gui-script minSpecVersion="1">
|
|
||||||
<title>.NET CLI {VERSION}</title>
|
|
||||||
<license file="eula.rtf" mime-type="application/rtf" />
|
|
||||||
<background file="dotnetbackground.png" mime-type="image/png"/>
|
|
||||||
<options customize="never" require-scripts="false" />
|
|
||||||
<welcome file="welcome.html" mime-type="text/html" />
|
|
||||||
<conclusion file="conclusion.html" mime-type="text/html" />
|
|
||||||
<volume-check>
|
|
||||||
<allowed-os-version>
|
|
||||||
<os-version min="10.10" />
|
|
||||||
</allowed-os-version>
|
|
||||||
</volume-check>
|
|
||||||
<choices-outline>
|
|
||||||
<line choice="com.microsoft.dotnet.cli.pkg.dotnet-osx-x64"/>
|
|
||||||
</choices-outline>
|
|
||||||
|
|
||||||
<choice id="com.microsoft.dotnet.cli.pkg.dotnet-osx-x64" visible="true" title=".NET CLI (x64)" description=".NET CLI">
|
|
||||||
<pkg-ref id="com.microsoft.dotnet.cli.pkg.dotnet-osx-x64"/>
|
|
||||||
</choice>
|
|
||||||
<pkg-ref id="com.microsoft.dotnet.cli.pkg.dotnet-osx-x64">dotnet-osx-x64.{VERSION}.pkg</pkg-ref>
|
|
||||||
</installer-gui-script>
|
|
33
packaging/osx/clisdk/Distribution-Template
Normal file
33
packaging/osx/clisdk/Distribution-Template
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<installer-gui-script minSpecVersion="1">
|
||||||
|
<title>.NET CLI {VERSION}</title>
|
||||||
|
<license file="eula.rtf" mime-type="application/rtf" />
|
||||||
|
<background file="dotnetbackground.png" mime-type="image/png"/>
|
||||||
|
<options customize="never" require-scripts="false" />
|
||||||
|
<welcome file="welcome.html" mime-type="text/html" />
|
||||||
|
<conclusion file="conclusion.html" mime-type="text/html" />
|
||||||
|
<volume-check>
|
||||||
|
<allowed-os-version>
|
||||||
|
<os-version min="10.10" />
|
||||||
|
</allowed-os-version>
|
||||||
|
</volume-check>
|
||||||
|
|
||||||
|
|
||||||
|
<choices-outline>
|
||||||
|
<line choice="com.microsoft.dotnet.sharedframework.{SharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.component.osx.x64.pkg" />
|
||||||
|
<line choice="com.microsoft.dotnet.sharedhost.osx.x64" />
|
||||||
|
<line choice="com.microsoft.dotnet.sdk.osx.x64"/>
|
||||||
|
</choices-outline>
|
||||||
|
<choice id="com.microsoft.dotnet.sharedframework.{SharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.component.osx.x64.pkg" visible="true" title=".NET Core Shared Framework (x64)" description="The .NET Core Shared Framework">
|
||||||
|
<pkg-ref id="com.microsoft.dotnet.sharedframework.{SharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.component.osx.x64.pkg" />
|
||||||
|
</choice>
|
||||||
|
<choice id="com.microsoft.dotnet.sharedhost.osx.x64" visible="true" title=".NET Core Shared Host (x64)" description="The .NET Core Shared Host." >
|
||||||
|
<pkg-ref id="com.microsoft.dotnet.sharedhost.osx.x64" />
|
||||||
|
</choice>
|
||||||
|
<choice id="com.microsoft.dotnet.sdk.osx.x64" visible="true" title=".NET CLI (x64)" description=".NET CLI">
|
||||||
|
<pkg-ref id="com.microsoft.dotnet.sdk.osx.x64"/>
|
||||||
|
</choice>
|
||||||
|
<pkg-ref id="com.microsoft.dotnet.sharedframework.{SharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.component.osx.x64.pkg">com.microsoft.dotnet.sharedframework.{SharedFrameworkNugetName}.{SharedFrameworkNugetVersion}.component.osx.x64.pkg</pkg-ref>
|
||||||
|
<pkg-ref id="com.microsoft.dotnet.sharedhost.osx.x64">com.microsoft.dotnet.sharedhost.osx.x64.pkg</pkg-ref>
|
||||||
|
<pkg-ref id="com.microsoft.dotnet.sdk.osx.x64">com.microsoft.dotnet.sdk.osx.x64.pkg</pkg-ref>
|
||||||
|
</installer-gui-script>
|
|
@ -12,7 +12,7 @@ INSTALL_DESTINATION=$2
|
||||||
chmod -R 755 $INSTALL_DESTINATION
|
chmod -R 755 $INSTALL_DESTINATION
|
||||||
|
|
||||||
# Add the installation bin directory to the system-wide paths
|
# Add the installation bin directory to the system-wide paths
|
||||||
echo $INSTALL_DESTINATION/bin | tee -a /etc/paths.d/dotnet
|
echo $INSTALL_DESTINATION | tee -a /etc/paths.d/dotnet
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
|
@ -1,86 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
|
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
|
||||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
||||||
SOURCE="$(readlink "$SOURCE")"
|
|
||||||
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
|
||||||
done
|
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
||||||
|
|
||||||
help(){
|
|
||||||
echo "Usage: $0 [--version <pkg version>] [--input <input directory>] [--output <output pkg>] [--help]"
|
|
||||||
echo ""
|
|
||||||
echo "Options:"
|
|
||||||
echo " --version <pkg version> Specify a version for the package. Version format is 4 '.' separated numbers - <major>.<minor>.<patch>.<revision>"
|
|
||||||
echo " --input <input directory> Package the entire contents of the directory tree."
|
|
||||||
echo " --output <output pkg> The path to where the package will be written."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
while [[ $# > 0 ]]; do
|
|
||||||
lowerI="$(echo $1 | awk '{print tolower($0)}')"
|
|
||||||
case $lowerI in
|
|
||||||
-v|--version)
|
|
||||||
DOTNET_CLI_VERSION=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-o|--output)
|
|
||||||
OUTPUT_PKG=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-i|--input)
|
|
||||||
INPUT_DIR=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--help)
|
|
||||||
help
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "$DOTNET_CLI_VERSION" ]; then
|
|
||||||
echo "Provide a version number. Missing option '--version'" && help
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$OUTPUT_PKG" ]; then
|
|
||||||
echo "Provide an output pkg. Missing option '--output'" && help
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$INPUT_DIR" ]; then
|
|
||||||
echo "Provide an input directory. Missing option '--input'" && help
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d "$INPUT_DIR" ]; then
|
|
||||||
echo "'$INPUT_DIR' - is either missing or not a directory" 1>&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PACKAGE_DIR=$(dirname "${OUTPUT_PKG}")
|
|
||||||
[ -d "$PACKAGE_DIR" ] || mkdir -p $PACKAGE_DIR
|
|
||||||
|
|
||||||
PACKAGE_ID=$(basename "${OUTPUT_PKG}")
|
|
||||||
|
|
||||||
#chmod -R 755 $INPUT_DIR
|
|
||||||
pkgbuild --root $INPUT_DIR \
|
|
||||||
--version $DOTNET_CLI_VERSION \
|
|
||||||
--scripts $DIR/scripts \
|
|
||||||
--identifier com.microsoft.dotnet.cli.pkg.dotnet-osx-x64 \
|
|
||||||
--install-location /usr/local/share/dotnet \
|
|
||||||
$DIR/$PACKAGE_ID
|
|
||||||
|
|
||||||
cat $DIR/Distribution-Template | sed "/{VERSION}/s//$DOTNET_CLI_VERSION/g" > $DIR/Dist
|
|
||||||
|
|
||||||
productbuild --version $DOTNET_CLI_VERSION --identifier com.microsoft.dotnet.cli --package-path $DIR --resources $DIR/resources --distribution $DIR/Dist $OUTPUT_PKG
|
|
||||||
|
|
||||||
#Clean temp files
|
|
||||||
rm $DIR/$PACKAGE_ID
|
|
||||||
rm $DIR/Dist
|
|
|
@ -7,6 +7,8 @@ using Microsoft.Extensions.PlatformAbstractions;
|
||||||
|
|
||||||
using static Microsoft.DotNet.Cli.Build.FS;
|
using static Microsoft.DotNet.Cli.Build.FS;
|
||||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Reflection.PortableExecutable;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
|
@ -45,6 +47,12 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
"Microsoft.Extensions.Testing.Abstractions"
|
"Microsoft.Extensions.Testing.Abstractions"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public const string SharedFrameworkName = "Microsoft.NETCore.App";
|
||||||
|
|
||||||
|
private static string CoreHostBaseName => $"corehost{Constants.ExeSuffix}";
|
||||||
|
private static string DotnetHostFxrBaseName => $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}";
|
||||||
|
private static string HostPolicyBaseName => $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}";
|
||||||
|
|
||||||
// Updates the stage 2 with recent changes.
|
// Updates the stage 2 with recent changes.
|
||||||
[Target(nameof(PrepareTargets.Init), nameof(CompileStage2))]
|
[Target(nameof(PrepareTargets.Init), nameof(CompileStage2))]
|
||||||
public static BuildTargetResult UpdateBuild(BuildTargetContext c)
|
public static BuildTargetResult UpdateBuild(BuildTargetContext c)
|
||||||
|
@ -118,9 +126,9 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
rid);
|
rid);
|
||||||
|
|
||||||
// Copy the output out
|
// Copy the output out
|
||||||
File.Copy(Path.Combine(cmakeOut, "cli", "corehost"), Path.Combine(Dirs.Corehost, "corehost"), overwrite: true);
|
File.Copy(Path.Combine(cmakeOut, "cli", "corehost"), Path.Combine(Dirs.Corehost, CoreHostBaseName), overwrite: true);
|
||||||
File.Copy(Path.Combine(cmakeOut, "cli", "dll", $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), overwrite: true);
|
File.Copy(Path.Combine(cmakeOut, "cli", "dll", HostPolicyBaseName), Path.Combine(Dirs.Corehost, HostPolicyBaseName), overwrite: true);
|
||||||
File.Copy(Path.Combine(cmakeOut, "cli", "fxr", $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), overwrite: true);
|
File.Copy(Path.Combine(cmakeOut, "cli", "fxr", DotnetHostFxrBaseName), Path.Combine(Dirs.Corehost, DotnetHostFxrBaseName), overwrite: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.Success();
|
return c.Success();
|
||||||
|
@ -131,7 +139,16 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
|
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
|
||||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
|
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
|
||||||
return CompileStage(c,
|
|
||||||
|
if (Directory.Exists(Dirs.Stage1))
|
||||||
|
{
|
||||||
|
Utils.DeleteDirectory(Dirs.Stage1);
|
||||||
|
}
|
||||||
|
Directory.CreateDirectory(Dirs.Stage1);
|
||||||
|
|
||||||
|
CopySharedHost(Dirs.Stage1);
|
||||||
|
PublishSharedFramework(c, Dirs.Stage1, DotNetCli.Stage0);
|
||||||
|
return CompileCliSdk(c,
|
||||||
dotnet: DotNetCli.Stage0,
|
dotnet: DotNetCli.Stage0,
|
||||||
outputDir: Dirs.Stage1);
|
outputDir: Dirs.Stage1);
|
||||||
}
|
}
|
||||||
|
@ -143,7 +160,16 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
|
|
||||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
|
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "src"));
|
||||||
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
|
CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "test"));
|
||||||
var result = CompileStage(c,
|
|
||||||
|
if (Directory.Exists(Dirs.Stage2))
|
||||||
|
{
|
||||||
|
Utils.DeleteDirectory(Dirs.Stage2);
|
||||||
|
}
|
||||||
|
Directory.CreateDirectory(Dirs.Stage2);
|
||||||
|
|
||||||
|
PublishSharedFramework(c, Dirs.Stage2, DotNetCli.Stage1);
|
||||||
|
CopySharedHost(Dirs.Stage2);
|
||||||
|
var result = CompileCliSdk(c,
|
||||||
dotnet: DotNetCli.Stage1,
|
dotnet: DotNetCli.Stage1,
|
||||||
outputDir: Dirs.Stage2);
|
outputDir: Dirs.Stage2);
|
||||||
|
|
||||||
|
@ -174,15 +200,117 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BuildTargetResult CompileStage(BuildTargetContext c, DotNetCli dotnet, string outputDir)
|
private static void CopySharedHost(string outputDir)
|
||||||
{
|
{
|
||||||
Rmdir(outputDir);
|
// corehost will be renamed to dotnet at some point and then this can be removed.
|
||||||
|
File.Copy(
|
||||||
|
Path.Combine(Dirs.Corehost, CoreHostBaseName),
|
||||||
|
Path.Combine(outputDir, $"dotnet{Constants.ExeSuffix}"), true);
|
||||||
|
File.Copy(
|
||||||
|
Path.Combine(Dirs.Corehost, DotnetHostFxrBaseName),
|
||||||
|
Path.Combine(outputDir, DotnetHostFxrBaseName), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PublishSharedFramework(BuildTargetContext c, string outputDir, DotNetCli dotnetCli)
|
||||||
|
{
|
||||||
|
string SharedFrameworkSourceRoot = Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework");
|
||||||
|
string SharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
if (Directory.Exists(SharedFrameworkNameAndVersionRoot))
|
||||||
|
{
|
||||||
|
Utils.DeleteDirectory(SharedFrameworkNameAndVersionRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
"-f", publishFramework,
|
||||||
|
SharedFrameworkSourceRoot).Execute().EnsureSuccessful();
|
||||||
|
|
||||||
|
// Clean up artifacts that dotnet-publish generates which we don't need
|
||||||
|
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, $"framework{Constants.ExeSuffix}"));
|
||||||
|
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.dll"));
|
||||||
|
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.pdb"));
|
||||||
|
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.runtimeconfig.json"));
|
||||||
|
|
||||||
|
// Rename the .deps file
|
||||||
|
var destinationDeps = Path.Combine(SharedFrameworkNameAndVersionRoot, $"{SharedFrameworkName}.deps.json");
|
||||||
|
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.deps"), Path.Combine(SharedFrameworkNameAndVersionRoot, $"{SharedFrameworkName}.deps"));
|
||||||
|
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.deps.json"), destinationDeps);
|
||||||
|
|
||||||
|
// Generate RID fallback graph
|
||||||
|
string runtimeGraphGeneratorRuntime = null;
|
||||||
|
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
|
||||||
|
{
|
||||||
|
case Platform.Windows:
|
||||||
|
runtimeGraphGeneratorRuntime = "win";
|
||||||
|
break;
|
||||||
|
case Platform.Linux:
|
||||||
|
runtimeGraphGeneratorRuntime = "linux";
|
||||||
|
break;
|
||||||
|
case Platform.Darwin:
|
||||||
|
runtimeGraphGeneratorRuntime = "osx";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(runtimeGraphGeneratorRuntime))
|
||||||
|
{
|
||||||
|
var runtimeGraphGeneratorName = "RuntimeGraphGenerator";
|
||||||
|
var runtimeGraphGeneratorProject = Path.Combine(Dirs.RepoRoot, "tools", runtimeGraphGeneratorName);
|
||||||
|
var runtimeGraphGeneratorOutput = Path.Combine(Dirs.Output, "tools", runtimeGraphGeneratorName);
|
||||||
|
|
||||||
|
dotnetCli.Publish(
|
||||||
|
"--output", runtimeGraphGeneratorOutput,
|
||||||
|
runtimeGraphGeneratorProject).Execute().EnsureSuccessful();
|
||||||
|
var runtimeGraphGeneratorExe = Path.Combine(runtimeGraphGeneratorOutput, $"{runtimeGraphGeneratorName}{Constants.ExeSuffix}");
|
||||||
|
|
||||||
|
Cmd(runtimeGraphGeneratorExe, "--project", SharedFrameworkSourceRoot, "--deps", destinationDeps, runtimeGraphGeneratorRuntime)
|
||||||
|
.Execute();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c.Error($"Could not determine rid graph generation runtime for platform {PlatformServices.Default.Runtime.OperatingSystemPlatform}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// corehost will be renamed to dotnet at some point and then we will not need to rename it here.
|
||||||
|
File.Copy(
|
||||||
|
Path.Combine(Dirs.Corehost, CoreHostBaseName),
|
||||||
|
Path.Combine(SharedFrameworkNameAndVersionRoot, $"dotnet{Constants.ExeSuffix}"));
|
||||||
|
File.Copy(
|
||||||
|
Path.Combine(Dirs.Corehost, HostPolicyBaseName),
|
||||||
|
Path.Combine(SharedFrameworkNameAndVersionRoot, HostPolicyBaseName), true);
|
||||||
|
|
||||||
|
if (File.Exists(Path.Combine(SharedFrameworkNameAndVersionRoot, "mscorlib.ni.dll")))
|
||||||
|
{
|
||||||
|
// Publish already places the crossgen'd version of mscorlib into the output, so we can
|
||||||
|
// remove the IL version
|
||||||
|
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "mscorlib.dll"));
|
||||||
|
}
|
||||||
|
|
||||||
|
CrossgenSharedFx(c, SharedFrameworkNameAndVersionRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BuildTargetResult CompileCliSdk(BuildTargetContext c, DotNetCli dotnet, string outputDir)
|
||||||
|
{
|
||||||
var configuration = c.BuildContext.Get<string>("Configuration");
|
var configuration = c.BuildContext.Get<string>("Configuration");
|
||||||
var binDir = Path.Combine(outputDir, "bin");
|
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
|
||||||
var buildVesion = c.BuildContext.Get<BuildVersion>("BuildVersion");
|
outputDir = Path.Combine(outputDir, "sdk", buildVersion.NuGetVersion);
|
||||||
|
|
||||||
Mkdirp(binDir);
|
Rmdir(outputDir);
|
||||||
|
Mkdirp(outputDir);
|
||||||
|
|
||||||
foreach (var project in ProjectsToPublish)
|
foreach (var project in ProjectsToPublish)
|
||||||
{
|
{
|
||||||
|
@ -191,11 +319,11 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
dotnet.Publish(
|
dotnet.Publish(
|
||||||
"--native-subdirectory",
|
"--native-subdirectory",
|
||||||
"--output",
|
"--output",
|
||||||
binDir,
|
outputDir,
|
||||||
"--configuration",
|
"--configuration",
|
||||||
configuration,
|
configuration,
|
||||||
Path.Combine(c.BuildContext.BuildDirectory, "src", project))
|
Path.Combine(c.BuildContext.BuildDirectory, "src", project))
|
||||||
.Environment("DOTNET_BUILD_VERSION", buildVesion.VersionSuffix)
|
.Environment("DOTNET_BUILD_VERSION", buildVersion.VersionSuffix)
|
||||||
.Execute()
|
.Execute()
|
||||||
.EnsureSuccessful();
|
.EnsureSuccessful();
|
||||||
}
|
}
|
||||||
|
@ -203,9 +331,9 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
FixModeFlags(outputDir);
|
FixModeFlags(outputDir);
|
||||||
|
|
||||||
// Copy corehost
|
// Copy corehost
|
||||||
File.Copy(Path.Combine(Dirs.Corehost, $"corehost{Constants.ExeSuffix}"), Path.Combine(binDir, $"corehost{Constants.ExeSuffix}"), overwrite: true);
|
File.Copy(Path.Combine(Dirs.Corehost, $"corehost{Constants.ExeSuffix}"), Path.Combine(outputDir, $"corehost{Constants.ExeSuffix}"), overwrite: true);
|
||||||
File.Copy(Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), Path.Combine(binDir, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), overwrite: true);
|
File.Copy(Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), Path.Combine(outputDir, $"{Constants.DynamicLibPrefix}hostpolicy{Constants.DynamicLibSuffix}"), overwrite: true);
|
||||||
File.Copy(Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), Path.Combine(binDir, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), overwrite: true);
|
File.Copy(Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), Path.Combine(outputDir, $"{Constants.DynamicLibPrefix}hostfxr{Constants.DynamicLibSuffix}"), overwrite: true);
|
||||||
|
|
||||||
// Corehostify binaries
|
// Corehostify binaries
|
||||||
foreach (var binaryToCorehostify in BinariesForCoreHost)
|
foreach (var binaryToCorehostify in BinariesForCoreHost)
|
||||||
|
@ -213,9 +341,9 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Yes, it is .exe even on Linux. This is the managed exe we're working with
|
// Yes, it is .exe even on Linux. This is the managed exe we're working with
|
||||||
File.Copy(Path.Combine(binDir, $"{binaryToCorehostify}.exe"), Path.Combine(binDir, $"{binaryToCorehostify}.dll"));
|
File.Copy(Path.Combine(outputDir, $"{binaryToCorehostify}.exe"), Path.Combine(outputDir, $"{binaryToCorehostify}.dll"));
|
||||||
File.Delete(Path.Combine(binDir, $"{binaryToCorehostify}.exe"));
|
File.Delete(Path.Combine(outputDir, $"{binaryToCorehostify}.exe"));
|
||||||
File.Copy(Path.Combine(binDir, $"corehost{Constants.ExeSuffix}"), Path.Combine(binDir, binaryToCorehostify + Constants.ExeSuffix));
|
File.Copy(Path.Combine(outputDir, $"corehost{Constants.ExeSuffix}"), Path.Combine(outputDir, binaryToCorehostify + Constants.ExeSuffix));
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -224,25 +352,25 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
}
|
}
|
||||||
|
|
||||||
// dotnet.exe is from stage0. But we must be using the newly built corehost in stage1
|
// dotnet.exe is from stage0. But we must be using the newly built corehost in stage1
|
||||||
File.Delete(Path.Combine(binDir, $"dotnet{Constants.ExeSuffix}"));
|
File.Delete(Path.Combine(outputDir, $"dotnet{Constants.ExeSuffix}"));
|
||||||
File.Copy(Path.Combine(binDir, $"corehost{Constants.ExeSuffix}"), Path.Combine(binDir, $"dotnet{Constants.ExeSuffix}"));
|
File.Copy(Path.Combine(outputDir, $"corehost{Constants.ExeSuffix}"), Path.Combine(outputDir, $"dotnet{Constants.ExeSuffix}"));
|
||||||
|
|
||||||
// Crossgen Roslyn
|
// Crossgen Roslyn
|
||||||
var result = Crossgen(c, binDir);
|
var result = CrossgenCliSdk(c, outputDir);
|
||||||
if (!result.Success)
|
if (!result.Success)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy AppDeps
|
// Copy AppDeps
|
||||||
result = CopyAppDeps(c, binDir);
|
result = CopyAppDeps(c, outputDir);
|
||||||
if (!result.Success)
|
if (!result.Success)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate .version file
|
// Generate .version file
|
||||||
var version = buildVesion.SimpleVersion;
|
var version = buildVersion.SimpleVersion;
|
||||||
var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}";
|
var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}";
|
||||||
File.WriteAllText(Path.Combine(outputDir, ".version"), content);
|
File.WriteAllText(Path.Combine(outputDir, ".version"), content);
|
||||||
|
|
||||||
|
@ -296,12 +424,12 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BuildTargetResult Crossgen(BuildTargetContext c, string outputDir)
|
private static BuildTargetResult CrossgenCliSdk(BuildTargetContext c, string outputDir)
|
||||||
{
|
{
|
||||||
// Check if we need to skip crossgen
|
// Check if we need to skip crossgen
|
||||||
if (string.Equals(Environment.GetEnvironmentVariable("DOTNET_BUILD_SKIP_CROSSGEN"), "1"))
|
if (string.Equals(Environment.GetEnvironmentVariable("DOTNET_BUILD_SKIP_CROSSGEN"), "1"))
|
||||||
{
|
{
|
||||||
c.Warn("Skipping crossgen because DOTNET_BUILD_SKIP_CROSSGEN is set");
|
c.Warn("Skipping crossgen for Cli Sdk because DOTNET_BUILD_SKIP_CROSSGEN is set");
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,6 +474,58 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BuildTargetResult CrossgenSharedFx(BuildTargetContext c, string pathToAssemblies)
|
||||||
|
{
|
||||||
|
// Check if we need to skip crossgen
|
||||||
|
if (!string.Equals(Environment.GetEnvironmentVariable("CROSSGEN_SHAREDFRAMEWORK"), "1"))
|
||||||
|
{
|
||||||
|
c.Warn("Skipping crossgen for SharedFx because CROSSGEN_SHAREDFRAMEWORK is not set to 1");
|
||||||
|
return c.Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var file in Directory.GetFiles(pathToAssemblies))
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileName(file);
|
||||||
|
|
||||||
|
if (fileName == "mscorlib.dll" || fileName == "mscorlib.ni.dll" || !HasMetadata(file))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string tempPathName = Path.ChangeExtension(file, "readytorun");
|
||||||
|
|
||||||
|
// This is not always correct. The version of crossgen we need to pick up is whatever one was restored as part
|
||||||
|
// of the Microsoft.NETCore.Runtime.CoreCLR package that is part of the shared library. For now, the version hardcoded
|
||||||
|
// in CompileTargets and the one in the shared library project.json match and are updated in lock step, but long term
|
||||||
|
// we need to be able to look at the project.lock.json file and figure out what version of Microsoft.NETCore.Runtime.CoreCLR
|
||||||
|
// was used, and then select that version.
|
||||||
|
ExecSilent(Crossgen.GetCrossgenPathForVersion(CompileTargets.CoreCLRVersion),
|
||||||
|
"-readytorun", "-in", file, "-out", tempPathName, "-platform_assemblies_paths", pathToAssemblies);
|
||||||
|
|
||||||
|
File.Delete(file);
|
||||||
|
File.Move(tempPathName, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HasMetadata(string pathToFile)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var inStream = File.OpenRead(pathToFile))
|
||||||
|
{
|
||||||
|
using (var peReader = new PEReader(inStream))
|
||||||
|
{
|
||||||
|
return peReader.HasMetadata;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (BadImageFormatException) { }
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<string> GetAssembliesToCrossGen()
|
private static List<string> GetAssembliesToCrossGen()
|
||||||
{
|
{
|
||||||
return new List<string>
|
return new List<string>
|
||||||
|
|
|
@ -37,7 +37,8 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
var channel = c.BuildContext.Get<string>("Channel").ToLower();
|
var channel = c.BuildContext.Get<string>("Channel").ToLower();
|
||||||
var packageName = Monikers.GetDebianPackageName(c);
|
var packageName = Monikers.GetDebianPackageName(c);
|
||||||
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||||
var debFile = c.BuildContext.Get<string>("SdkInstallerFile");
|
var debFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile");
|
||||||
|
var input = c.BuildContext.Get<string>("CLISDKRoot");
|
||||||
var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages");
|
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 previousVersionURL = $"https://dotnetcli.blob.core.windows.net/dotnet/{channel}/Installers/Latest/dotnet-ubuntu-x64.latest.deb";
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
Directory.CreateDirectory(objRoot);
|
Directory.CreateDirectory(objRoot);
|
||||||
|
|
||||||
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"),
|
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"),
|
||||||
"-v", version, "-i", Dirs.Stage2, "-o", debFile, "-p", packageName, "-m", manPagesDir, "--previous-version-url", previousVersionURL, "--obj-root", objRoot)
|
"-v", version, "-i", input, "-o", debFile, "-p", packageName, "-m", manPagesDir, "--previous-version-url", previousVersionURL, "--obj-root", objRoot)
|
||||||
.Execute()
|
.Execute()
|
||||||
.EnsureSuccessful();
|
.EnsureSuccessful();
|
||||||
return c.Success();
|
return c.Success();
|
||||||
|
@ -99,7 +100,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
|
|
||||||
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-sharedframework-debian.sh"),
|
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-sharedframework-debian.sh"),
|
||||||
"--input", inputRoot, "--output", debFile, "--package-name", packageName,
|
"--input", inputRoot, "--output", debFile, "--package-name", packageName,
|
||||||
"--framework-nuget-name", SharedFrameworkTargets.SharedFrameworkName,
|
"--framework-nuget-name", Monikers.SharedFrameworkName,
|
||||||
"--framework-nuget-version", c.BuildContext.Get<string>("SharedFrameworkNugetVersion"),
|
"--framework-nuget-version", c.BuildContext.Get<string>("SharedFrameworkNugetVersion"),
|
||||||
"--obj-root", objRoot, "--version", version)
|
"--obj-root", objRoot, "--version", version)
|
||||||
.Execute()
|
.Execute()
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[BuildPlatforms(BuildPlatform.Windows)]
|
[BuildPlatforms(BuildPlatform.Windows)]
|
||||||
public static BuildTargetResult InitMsi(BuildTargetContext c)
|
public static BuildTargetResult InitMsi(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
SdkBundle = c.BuildContext.Get<string>("SdkInstallerFile");
|
SdkBundle = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile");
|
||||||
SdkMsi = Path.ChangeExtension(SdkBundle, "msi");
|
SdkMsi = Path.ChangeExtension(SdkBundle, "msi");
|
||||||
Engine = Path.Combine(Path.GetDirectoryName(SdkBundle), ENGINE);
|
Engine = Path.Combine(Path.GetDirectoryName(SdkBundle), ENGINE);
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
public static BuildTargetResult GenerateDotnetSharedFrameworkMsi(BuildTargetContext c)
|
public static BuildTargetResult GenerateDotnetSharedFrameworkMsi(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
var inputDir = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
|
var inputDir = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
|
||||||
var sharedFrameworkNuGetName = SharedFrameworkTargets.SharedFrameworkName;
|
var sharedFrameworkNuGetName = Monikers.SharedFrameworkName;
|
||||||
var sharedFrameworkNuGetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
var sharedFrameworkNuGetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
||||||
var upgradeCode = Utils.GenerateGuidFromName($"{sharedFrameworkNuGetName}-{sharedFrameworkNuGetVersion}-{Arch}").ToString().ToUpper();
|
var upgradeCode = Utils.GenerateGuidFromName($"{sharedFrameworkNuGetName}-{sharedFrameworkNuGetVersion}-{Arch}").ToString().ToUpper();
|
||||||
var wixObjRoot = Path.Combine(Dirs.Output, "obj", "wix", "sharedframework");
|
var wixObjRoot = Path.Combine(Dirs.Output, "obj", "wix", "sharedframework");
|
||||||
|
|
|
@ -13,8 +13,8 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
public static class PackageTargets
|
public static class PackageTargets
|
||||||
{
|
{
|
||||||
[Target(nameof(PackageTargets.CopyCLISDKLayout),
|
[Target(nameof(PackageTargets.CopyCLISDKLayout),
|
||||||
nameof(SharedFrameworkTargets.PublishSharedHost),
|
nameof(PackageTargets.CopySharedHostLayout),
|
||||||
nameof(SharedFrameworkTargets.PublishSharedFramework),
|
nameof(PackageTargets.CopySharedFxLayout),
|
||||||
nameof(PackageTargets.CopyCombinedFrameworkSDKHostLayout),
|
nameof(PackageTargets.CopyCombinedFrameworkSDKHostLayout),
|
||||||
nameof(PackageTargets.CopyCombinedFrameworkHostLayout))]
|
nameof(PackageTargets.CopyCombinedFrameworkHostLayout))]
|
||||||
public static BuildTargetResult InitPackage(BuildTargetContext c)
|
public static BuildTargetResult InitPackage(BuildTargetContext c)
|
||||||
|
@ -52,45 +52,62 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[Target]
|
[Target]
|
||||||
public static BuildTargetResult CopyCLISDKLayout(BuildTargetContext c)
|
public static BuildTargetResult CopyCLISDKLayout(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
var nugetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
|
|
||||||
var cliSdkRoot = Path.Combine(Dirs.Output, "obj", "clisdk");
|
var cliSdkRoot = Path.Combine(Dirs.Output, "obj", "clisdk");
|
||||||
var cliSdk = Path.Combine(cliSdkRoot, "sdk", nugetVersion);
|
|
||||||
|
|
||||||
if (Directory.Exists(cliSdkRoot))
|
if (Directory.Exists(cliSdkRoot))
|
||||||
{
|
{
|
||||||
Utils.DeleteDirectory(cliSdkRoot);
|
Utils.DeleteDirectory(cliSdkRoot);
|
||||||
}
|
}
|
||||||
Directory.CreateDirectory(cliSdk);
|
|
||||||
|
|
||||||
var binPath = Path.Combine(Dirs.Stage2, "bin");
|
|
||||||
foreach (var file in Directory.GetFiles(binPath, "*", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
string destFile = file.Replace(binPath, cliSdk);
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(destFile));
|
|
||||||
File.Copy(file, destFile, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
File.Copy(Path.Combine(Dirs.Stage2, ".version"), Path.Combine(cliSdk, ".version"), true);
|
|
||||||
|
|
||||||
// copy stage2 to "cliSdkRoot\bin".
|
|
||||||
// this is a temp hack until we fix the build scripts to use the new shared fx and shared host
|
|
||||||
// the current build scripts need the CLI sdk to be in the bin folder.
|
|
||||||
|
|
||||||
foreach (var file in Directory.GetFiles(Dirs.Stage2, "*", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
string destFile = file.Replace(Dirs.Stage2, cliSdkRoot);
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(destFile));
|
|
||||||
File.Copy(file, destFile, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Directory.CreateDirectory(cliSdkRoot);
|
||||||
|
Utils.CopyDirectoryRecursively(Path.Combine(Dirs.Stage2, "sdk"), cliSdkRoot, true);
|
||||||
c.BuildContext["CLISDKRoot"] = cliSdkRoot;
|
c.BuildContext["CLISDKRoot"] = cliSdkRoot;
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Target]
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.BuildContext["SharedHostPublishRoot"] = sharedHostRoot;
|
||||||
|
return c.Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Target]
|
||||||
|
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);
|
||||||
|
c.BuildContext["SharedFrameworkPublishRoot"] = sharedFxRoot;
|
||||||
|
return c.Success();
|
||||||
|
}
|
||||||
|
|
||||||
[Target]
|
[Target]
|
||||||
public static BuildTargetResult CopyCombinedFrameworkSDKHostLayout(BuildTargetContext c)
|
public static BuildTargetResult CopyCombinedFrameworkSDKHostLayout(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
var combinedRoot = Path.Combine(Dirs.Output, "obj", "combined-framework-sdk-host");
|
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");
|
string sdkPublishRoot = c.BuildContext.Get<string>("CLISDKRoot");
|
||||||
Utils.CopyDirectoryRecursively(sdkPublishRoot, combinedRoot);
|
Utils.CopyDirectoryRecursively(sdkPublishRoot, combinedRoot);
|
||||||
|
@ -109,6 +126,11 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
public static BuildTargetResult CopyCombinedFrameworkHostLayout(BuildTargetContext c)
|
public static BuildTargetResult CopyCombinedFrameworkHostLayout(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
var combinedRoot = Path.Combine(Dirs.Output, "obj", "combined-framework-host");
|
var combinedRoot = Path.Combine(Dirs.Output, "obj", "combined-framework-host");
|
||||||
|
if (Directory.Exists(combinedRoot))
|
||||||
|
{
|
||||||
|
Utils.DeleteDirectory(combinedRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
string sharedFrameworkPublishRoot = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
|
string sharedFrameworkPublishRoot = c.BuildContext.Get<string>("SharedFrameworkPublishRoot");
|
||||||
Utils.CopyDirectoryRecursively(sharedFrameworkPublishRoot, combinedRoot);
|
Utils.CopyDirectoryRecursively(sharedFrameworkPublishRoot, combinedRoot);
|
||||||
|
@ -130,9 +152,6 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[BuildPlatforms(BuildPlatform.Windows)]
|
[BuildPlatforms(BuildPlatform.Windows)]
|
||||||
public static BuildTargetResult GenerateZip(BuildTargetContext c)
|
public static BuildTargetResult GenerateZip(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
CreateZipFromDirectory(c.BuildContext.Get<string>("SharedHostPublishRoot"), c.BuildContext.Get<string>("SharedHostCompressedFile"));
|
|
||||||
CreateZipFromDirectory(c.BuildContext.Get<string>("SharedFrameworkPublishRoot"), c.BuildContext.Get<string>("SharedFrameworkCompressedFile"));
|
|
||||||
CreateZipFromDirectory(c.BuildContext.Get<string>("CLISDKRoot"), c.BuildContext.Get<string>("SdkCompressedFile"));
|
|
||||||
CreateZipFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"));
|
CreateZipFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"));
|
||||||
CreateZipFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile"));
|
CreateZipFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile"));
|
||||||
|
|
||||||
|
@ -143,9 +162,6 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[BuildPlatforms(BuildPlatform.Unix)]
|
[BuildPlatforms(BuildPlatform.Unix)]
|
||||||
public static BuildTargetResult GenerateTarBall(BuildTargetContext c)
|
public static BuildTargetResult GenerateTarBall(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
CreateTarBallFromDirectory(c.BuildContext.Get<string>("SharedHostPublishRoot"), c.BuildContext.Get<string>("SharedHostCompressedFile"));
|
|
||||||
CreateTarBallFromDirectory(c.BuildContext.Get<string>("SharedFrameworkPublishRoot"), c.BuildContext.Get<string>("SharedFrameworkCompressedFile"));
|
|
||||||
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CLISDKRoot"), c.BuildContext.Get<string>("SdkCompressedFile"));
|
|
||||||
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"));
|
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkSDKHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile"));
|
||||||
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile"));
|
CreateTarBallFromDirectory(c.BuildContext.Get<string>("CombinedFrameworkHostRoot"), c.BuildContext.Get<string>("CombinedFrameworkHostCompressedFile"));
|
||||||
|
|
||||||
|
@ -159,7 +175,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
var versionSuffix = c.BuildContext.Get<BuildVersion>("BuildVersion").VersionSuffix;
|
var versionSuffix = c.BuildContext.Get<BuildVersion>("BuildVersion").VersionSuffix;
|
||||||
var env = GetCommonEnvVars(c);
|
var env = GetCommonEnvVars(c);
|
||||||
Cmd("powershell", "-NoProfile", "-NoLogo",
|
Cmd("powershell", "-NoProfile", "-NoLogo",
|
||||||
Path.Combine(Dirs.RepoRoot, "packaging", "nuget", "package.ps1"), Path.Combine(Dirs.Stage2, "bin"), versionSuffix)
|
Path.Combine(Dirs.RepoRoot, "packaging", "nuget", "package.ps1"), Dirs.Stage2, versionSuffix)
|
||||||
.Environment(env)
|
.Environment(env)
|
||||||
.Execute()
|
.Execute()
|
||||||
.EnsureSuccessful();
|
.EnsureSuccessful();
|
||||||
|
|
|
@ -12,24 +12,80 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
public class PkgTargets
|
public class PkgTargets
|
||||||
{
|
{
|
||||||
[Target(nameof(GenerateSdkProductArchive), nameof(GenerateSharedFrameworkProductArchive))]
|
public static string PkgsIntermediateDir { get; set; }
|
||||||
|
[Target]
|
||||||
|
[BuildPlatforms(BuildPlatform.OSX)]
|
||||||
|
public static BuildTargetResult InitPkg(BuildTargetContext c)
|
||||||
|
{
|
||||||
|
PkgsIntermediateDir = Path.Combine(Dirs.Packages, "intermediate");
|
||||||
|
Directory.CreateDirectory(PkgsIntermediateDir);
|
||||||
|
return c.Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Target(nameof(InitPkg), nameof(GenerateSharedFrameworkProductArchive), nameof(GenerateCLISdkProductArchive))]
|
||||||
[BuildPlatforms(BuildPlatform.OSX)]
|
[BuildPlatforms(BuildPlatform.OSX)]
|
||||||
public static BuildTargetResult GeneratePkgs(BuildTargetContext c)
|
public static BuildTargetResult GeneratePkgs(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Target(nameof(GenerateCLISdkPkg))]
|
||||||
|
[BuildPlatforms(BuildPlatform.OSX)]
|
||||||
|
public static BuildTargetResult GenerateCLISdkProductArchive(BuildTargetContext c)
|
||||||
|
{
|
||||||
|
string sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
||||||
|
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||||
|
string id = $"com.microsoft.dotnet.dev.{version}.osx.x64";
|
||||||
|
string resourcePath = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "resources");
|
||||||
|
string outFilePath = Path.Combine(Dirs.Packages, c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile"));
|
||||||
|
|
||||||
|
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("{SharedFrameworkNugetVersion}", sharedFrameworkNugetVersion)
|
||||||
|
.Replace("{SharedFrameworkNugetName}", Monikers.SharedFrameworkName)
|
||||||
|
.Replace("{VERSION}", version);
|
||||||
|
File.WriteAllText(distributionPath, formattedDistContents);
|
||||||
|
|
||||||
|
Cmd("productbuild",
|
||||||
|
"--version", version,
|
||||||
|
"--identifier", id,
|
||||||
|
"--package-path", PkgsIntermediateDir,
|
||||||
|
"--resources", resourcePath,
|
||||||
|
"--distribution", distributionPath,
|
||||||
|
outFilePath)
|
||||||
|
.Execute()
|
||||||
|
.EnsureSuccessful();
|
||||||
|
|
||||||
|
return c.Success();
|
||||||
|
}
|
||||||
|
|
||||||
[Target]
|
[Target]
|
||||||
[BuildPlatforms(BuildPlatform.OSX)]
|
[BuildPlatforms(BuildPlatform.OSX)]
|
||||||
public static BuildTargetResult GenerateSdkProductArchive(BuildTargetContext c)
|
public static BuildTargetResult GenerateCLISdkPkg(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||||
var pkg = c.BuildContext.Get<string>("SdkInstallerFile");
|
string id = $"com.microsoft.dotnet.sdk.osx.x64";
|
||||||
|
string outFilePath = Path.Combine(PkgsIntermediateDir, id + ".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", id,
|
||||||
|
"--version", version,
|
||||||
|
"--install-location", installLocation,
|
||||||
|
"--scripts", scriptsLocation,
|
||||||
|
outFilePath)
|
||||||
|
.Execute()
|
||||||
|
.EnsureSuccessful();
|
||||||
|
|
||||||
Cmd(Path.Combine(Dirs.RepoRoot, "packaging", "osx", "package-osx.sh"),
|
|
||||||
"-v", version, "-i", Dirs.Stage2, "-o", pkg)
|
|
||||||
.Execute()
|
|
||||||
.EnsureSuccessful();
|
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,13 +93,12 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[BuildPlatforms(BuildPlatform.OSX)]
|
[BuildPlatforms(BuildPlatform.OSX)]
|
||||||
public static BuildTargetResult GenerateSharedFrameworkProductArchive(BuildTargetContext c)
|
public static BuildTargetResult GenerateSharedFrameworkProductArchive(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
string sharedFrameworkNugetName = SharedFrameworkTargets.SharedFrameworkName;
|
string sharedFrameworkNugetName = Monikers.SharedFrameworkName;
|
||||||
string sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
string sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
||||||
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||||
string id = $"com.microsoft.dotnet.sharedframework.{sharedFrameworkNugetName}.{sharedFrameworkNugetVersion}.osx.x64";
|
string id = $"com.microsoft.dotnet.{sharedFrameworkNugetName}.{sharedFrameworkNugetVersion}.osx.x64";
|
||||||
string packageIntermediatesPath = Path.Combine(Dirs.Output, "obj", "pkg");
|
|
||||||
string resourcePath = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "resources");
|
string resourcePath = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "resources");
|
||||||
string outFilePath = Path.Combine(packageIntermediatesPath, id + ".pkg");
|
string outFilePath = Path.Combine(PkgsIntermediateDir, c.BuildContext.Get<string>("CombinedFrameworkHostInstallerFile"));
|
||||||
|
|
||||||
string inputDistTemplatePath = Path.Combine(
|
string inputDistTemplatePath = Path.Combine(
|
||||||
Dirs.RepoRoot,
|
Dirs.RepoRoot,
|
||||||
|
@ -52,18 +107,18 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
"sharedframework",
|
"sharedframework",
|
||||||
"shared-framework-distribution-template.xml");
|
"shared-framework-distribution-template.xml");
|
||||||
string distTemplate = File.ReadAllText(inputDistTemplatePath);
|
string distTemplate = File.ReadAllText(inputDistTemplatePath);
|
||||||
string distributionPath = Path.Combine(packageIntermediatesPath, "shared-framework-formatted-distribution.xml");
|
string distributionPath = Path.Combine(PkgsIntermediateDir, "shared-framework-formatted-distribution.xml");
|
||||||
string formattedDistContents =
|
string formattedDistContents =
|
||||||
distTemplate.Replace("{SharedFrameworkNugetVersion}", sharedFrameworkNugetVersion)
|
distTemplate.Replace("{SharedFrameworkNugetVersion}", sharedFrameworkNugetVersion)
|
||||||
.Replace("{SharedFrameworkNugetName}", SharedFrameworkTargets.SharedFrameworkName)
|
.Replace("{SharedFrameworkNugetName}", Monikers.SharedFrameworkName)
|
||||||
.Replace("{VERSION}", version);
|
.Replace("{VERSION}", version);
|
||||||
File.WriteAllText(distributionPath, formattedDistContents);
|
File.WriteAllText(distributionPath, formattedDistContents);
|
||||||
|
|
||||||
Cmd("productbuild",
|
Cmd("productbuild",
|
||||||
"--version", version,
|
"--version", version,
|
||||||
"--identifier", id,
|
"--identifier", id,
|
||||||
"--package-path", packageIntermediatesPath,
|
"--package-path", PkgsIntermediateDir,
|
||||||
"--resources", resourcePath,
|
"--resources", resourcePath,
|
||||||
"--distribution", distributionPath,
|
"--distribution", distributionPath,
|
||||||
outFilePath)
|
outFilePath)
|
||||||
.Execute()
|
.Execute()
|
||||||
|
@ -76,12 +131,11 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[BuildPlatforms(BuildPlatform.OSX)]
|
[BuildPlatforms(BuildPlatform.OSX)]
|
||||||
public static BuildTargetResult GenerateSharedFrameworkPkg(BuildTargetContext c)
|
public static BuildTargetResult GenerateSharedFrameworkPkg(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
string sharedFrameworkNugetName = SharedFrameworkTargets.SharedFrameworkName;
|
string sharedFrameworkNugetName = Monikers.SharedFrameworkName;
|
||||||
string sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
string sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
||||||
Directory.CreateDirectory(Path.Combine(Dirs.Output, "obj", "pkg"));
|
|
||||||
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||||
string id = $"com.microsoft.dotnet.sharedframework.{sharedFrameworkNugetName}.{sharedFrameworkNugetVersion}.component.osx.x64";
|
string id = $"com.microsoft.dotnet.sharedframework.{sharedFrameworkNugetName}.{sharedFrameworkNugetVersion}.component.osx.x64";
|
||||||
string outFilePath = Path.Combine(Dirs.Output, "obj", "pkg", id + ".pkg");
|
string outFilePath = Path.Combine(PkgsIntermediateDir, id + ".pkg");
|
||||||
string installLocation = "/usr/local/share/dotnet";
|
string installLocation = "/usr/local/share/dotnet";
|
||||||
string scriptsLocation = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "sharedframework", "scripts");
|
string scriptsLocation = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "sharedframework", "scripts");
|
||||||
|
|
||||||
|
@ -102,10 +156,9 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[BuildPlatforms(BuildPlatform.OSX)]
|
[BuildPlatforms(BuildPlatform.OSX)]
|
||||||
public static BuildTargetResult GenerateSharedHostPkg(BuildTargetContext c)
|
public static BuildTargetResult GenerateSharedHostPkg(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(Path.Combine(Dirs.Output, "obj", "pkg"));
|
|
||||||
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
string version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||||
string id = $"com.microsoft.dotnet.sharedhost.osx.x64";
|
string id = $"com.microsoft.dotnet.sharedhost.osx.x64";
|
||||||
string outFilePath = Path.Combine(Dirs.Output, "obj", "pkg", id + ".pkg");
|
string outFilePath = Path.Combine(PkgsIntermediateDir, id + ".pkg");
|
||||||
string installLocation = "/usr/local/share/dotnet";
|
string installLocation = "/usr/local/share/dotnet";
|
||||||
string scriptsLocation = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "sharedhost", "scripts");
|
string scriptsLocation = Path.Combine(Dirs.RepoRoot, "packaging", "osx", "sharedhost", "scripts");
|
||||||
|
|
||||||
|
@ -122,4 +175,4 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ using System.Text;
|
||||||
using static Microsoft.DotNet.Cli.Build.FS;
|
using static Microsoft.DotNet.Cli.Build.FS;
|
||||||
using static Microsoft.DotNet.Cli.Build.Utils;
|
using static Microsoft.DotNet.Cli.Build.Utils;
|
||||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
|
@ -45,6 +46,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
|
|
||||||
c.BuildContext["Configuration"] = configEnv;
|
c.BuildContext["Configuration"] = configEnv;
|
||||||
c.BuildContext["Channel"] = Environment.GetEnvironmentVariable("CHANNEL");
|
c.BuildContext["Channel"] = Environment.GetEnvironmentVariable("CHANNEL");
|
||||||
|
c.BuildContext["SharedFrameworkNugetVersion"] = GetVersionFromProjectJson(Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework", "project.json"));
|
||||||
|
|
||||||
c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}");
|
c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}");
|
||||||
c.Info("Build Environment:");
|
c.Info("Build Environment:");
|
||||||
|
@ -112,11 +114,11 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
var versionBadgeName = $"{CurrentPlatform.Current}_{CurrentArchitecture.Current}_{config}_version_badge.svg";
|
var versionBadgeName = $"{CurrentPlatform.Current}_{CurrentArchitecture.Current}_{config}_version_badge.svg";
|
||||||
c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName);
|
c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName);
|
||||||
|
|
||||||
AddInstallerArtifactToContext(c, "dotnet", "Sdk");
|
AddInstallerArtifactToContext(c, "dotnet-sdk", "Sdk");
|
||||||
AddInstallerArtifactToContext(c, "dotnet-host", "SharedHost");
|
AddInstallerArtifactToContext(c, "dotnet-host", "SharedHost");
|
||||||
AddInstallerArtifactToContext(c, "dotnet-sharedframework", "SharedFramework");
|
AddInstallerArtifactToContext(c, "dotnet-sharedframework", "SharedFramework");
|
||||||
AddInstallerArtifactToContext(c, "dotnet-combined-framework-sdk-host", "CombinedFrameworkSDKHost");
|
AddInstallerArtifactToContext(c, "dotnet-dev", "CombinedFrameworkSDKHost");
|
||||||
AddInstallerArtifactToContext(c, "dotnet-combined-framework-host", "CombinedFrameworkHost");
|
AddInstallerArtifactToContext(c, "dotnet", "CombinedFrameworkHost");
|
||||||
|
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
@ -315,6 +317,23 @@ cmake is required to build the native host 'corehost'";
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetVersionFromProjectJson(string pathToProjectJson)
|
||||||
|
{
|
||||||
|
Regex r = new Regex($"\"{Regex.Escape(Monikers.SharedFrameworkName)}\"\\s*:\\s*\"(?'version'[^\"]*)\"");
|
||||||
|
|
||||||
|
foreach (var line in File.ReadAllLines(pathToProjectJson))
|
||||||
|
{
|
||||||
|
var m = r.Match(line);
|
||||||
|
|
||||||
|
if (m.Success)
|
||||||
|
{
|
||||||
|
return m.Groups["version"].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidOperationException("Unable to match the version name from " + pathToProjectJson);
|
||||||
|
}
|
||||||
|
|
||||||
private static bool AptPackageIsInstalled(string packageName)
|
private static bool AptPackageIsInstalled(string packageName)
|
||||||
{
|
{
|
||||||
var result = Command.Create("dpkg", "-s", packageName)
|
var result = Command.Create("dpkg", "-s", packageName)
|
||||||
|
|
|
@ -42,11 +42,8 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
}
|
}
|
||||||
|
|
||||||
[Target(nameof(PublishTargets.PublishVersionBadge),
|
[Target(nameof(PublishTargets.PublishVersionBadge),
|
||||||
nameof(PublishTargets.PublishCompressedFile),
|
|
||||||
nameof(PublishTargets.PublishSdkInstallerFile),
|
nameof(PublishTargets.PublishSdkInstallerFile),
|
||||||
nameof(PublishTargets.PublishDebFileToDebianRepo),
|
nameof(PublishTargets.PublishDebFileToDebianRepo),
|
||||||
nameof(PublishTargets.PublishSharedFrameworkCompressedFile),
|
|
||||||
nameof(PublishTargets.PublishSharedHostCompressedFile),
|
|
||||||
nameof(PublishTargets.PublishCombinedFrameworkSDKHostFile),
|
nameof(PublishTargets.PublishCombinedFrameworkSDKHostFile),
|
||||||
nameof(PublishTargets.PublishCombinedFrameworkHostFile),
|
nameof(PublishTargets.PublishCombinedFrameworkHostFile),
|
||||||
nameof(PublishTargets.PublishLatestVersionTextFile))]
|
nameof(PublishTargets.PublishLatestVersionTextFile))]
|
||||||
|
@ -67,24 +64,11 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Target]
|
|
||||||
public static BuildTargetResult PublishCompressedFile(BuildTargetContext c)
|
|
||||||
{
|
|
||||||
var compressedFile = c.BuildContext.Get<string>("SdkCompressedFile");
|
|
||||||
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
|
||||||
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
|
||||||
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
|
||||||
|
|
||||||
PublishFileAzure(compressedFileBlob, compressedFile);
|
|
||||||
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
|
||||||
return c.Success();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Target]
|
[Target]
|
||||||
[BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX, BuildPlatform.Ubuntu)]
|
[BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX, BuildPlatform.Ubuntu)]
|
||||||
public static BuildTargetResult PublishSdkInstallerFile(BuildTargetContext c)
|
public static BuildTargetResult PublishSdkInstallerFile(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
var installerFile = c.BuildContext.Get<string>("SdkInstallerFile");
|
var installerFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostInstallerFile");
|
||||||
var installerFileBlob = $"{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}";
|
var installerFileBlob = $"{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}";
|
||||||
var latestInstallerFile = installerFile.Replace(Version, "latest");
|
var latestInstallerFile = installerFile.Replace(Version, "latest");
|
||||||
var latestInstallerFileBlob = $"{Channel}/Installers/Latest/{Path.GetFileName(latestInstallerFile)}";
|
var latestInstallerFileBlob = $"{Channel}/Installers/Latest/{Path.GetFileName(latestInstallerFile)}";
|
||||||
|
@ -182,32 +166,6 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return uploadJson;
|
return uploadJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Target]
|
|
||||||
public static BuildTargetResult PublishSharedFrameworkCompressedFile(BuildTargetContext c)
|
|
||||||
{
|
|
||||||
var compressedFile = c.BuildContext.Get<string>("SharedFrameworkCompressedFile");
|
|
||||||
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
|
||||||
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
|
||||||
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
|
||||||
|
|
||||||
PublishFileAzure(compressedFileBlob, compressedFile);
|
|
||||||
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
|
||||||
return c.Success();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Target]
|
|
||||||
public static BuildTargetResult PublishSharedHostCompressedFile(BuildTargetContext c)
|
|
||||||
{
|
|
||||||
var compressedFile = c.BuildContext.Get<string>("SharedHostCompressedFile");
|
|
||||||
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
|
||||||
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
|
||||||
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
|
||||||
|
|
||||||
PublishFileAzure(compressedFileBlob, compressedFile);
|
|
||||||
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
|
||||||
return c.Success();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Target]
|
[Target]
|
||||||
public static BuildTargetResult PublishCombinedFrameworkSDKHostFile(BuildTargetContext c)
|
public static BuildTargetResult PublishCombinedFrameworkSDKHostFile(BuildTargetContext c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,218 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.IO.Compression;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Reflection.PortableExecutable;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using Microsoft.DotNet.Cli.Build.Framework;
|
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
|
|
||||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
|
||||||
{
|
|
||||||
public class SharedFrameworkTargets
|
|
||||||
{
|
|
||||||
public const string SharedFrameworkName = "Microsoft.NETCore.App";
|
|
||||||
|
|
||||||
private const string CoreHostBaseName = "corehost";
|
|
||||||
private const string DotnetHostFxrBaseName = "hostfxr";
|
|
||||||
private const string HostPolicyBaseName = "hostpolicy";
|
|
||||||
|
|
||||||
[Target(nameof(PackageSharedFramework), nameof(CrossGenAllManagedAssemblies))]
|
|
||||||
public static BuildTargetResult PublishSharedFramework(BuildTargetContext c)
|
|
||||||
{
|
|
||||||
return c.Success();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Target]
|
|
||||||
public static BuildTargetResult PackageSharedFramework(BuildTargetContext c)
|
|
||||||
{
|
|
||||||
string SharedFrameworkPublishRoot = Path.Combine(Dirs.Output, "obj", "sharedframework");
|
|
||||||
string SharedFrameworkSourceRoot = Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework");
|
|
||||||
string SharedFrameworkNugetVersion = GetVersionFromProjectJson(Path.Combine(Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework"), "project.json"));
|
|
||||||
|
|
||||||
if (Directory.Exists(SharedFrameworkPublishRoot))
|
|
||||||
{
|
|
||||||
Utils.DeleteDirectory(SharedFrameworkPublishRoot);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We publish to a sub folder of the PublishRoot so tools like heat and zip can generate folder structures easier.
|
|
||||||
string SharedFrameworkNameAndVersionRoot = Path.Combine(SharedFrameworkPublishRoot, "shared", SharedFrameworkName, SharedFrameworkNugetVersion);
|
|
||||||
|
|
||||||
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.Stage2.Publish(
|
|
||||||
"--output", SharedFrameworkNameAndVersionRoot,
|
|
||||||
"-r", publishRuntime,
|
|
||||||
"-f", publishFramework,
|
|
||||||
SharedFrameworkSourceRoot).Execute().EnsureSuccessful();
|
|
||||||
|
|
||||||
c.BuildContext["SharedFrameworkPublishRoot"] = SharedFrameworkPublishRoot;
|
|
||||||
c.BuildContext["SharedFrameworkNugetVersion"] = SharedFrameworkNugetVersion;
|
|
||||||
|
|
||||||
// Clean up artifacts that dotnet-publish generates which we don't need
|
|
||||||
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, $"framework{Constants.ExeSuffix}"));
|
|
||||||
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.dll"));
|
|
||||||
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.pdb"));
|
|
||||||
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.runtimeconfig.json"));
|
|
||||||
|
|
||||||
// Rename the .deps file
|
|
||||||
var destinationDeps = Path.Combine(SharedFrameworkNameAndVersionRoot, $"{SharedFrameworkName}.deps.json");
|
|
||||||
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.deps"), Path.Combine(SharedFrameworkNameAndVersionRoot, $"{SharedFrameworkName}.deps"));
|
|
||||||
File.Move(Path.Combine(SharedFrameworkNameAndVersionRoot, "framework.deps.json"), destinationDeps);
|
|
||||||
|
|
||||||
// Generate RID fallback graph
|
|
||||||
string runtimeGraphGeneratorRuntime = null;
|
|
||||||
switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
|
|
||||||
{
|
|
||||||
case Platform.Windows:
|
|
||||||
runtimeGraphGeneratorRuntime = "win";
|
|
||||||
break;
|
|
||||||
case Platform.Linux:
|
|
||||||
runtimeGraphGeneratorRuntime = "linux";
|
|
||||||
break;
|
|
||||||
case Platform.Darwin:
|
|
||||||
runtimeGraphGeneratorRuntime = "osx";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!string.IsNullOrEmpty(runtimeGraphGeneratorRuntime))
|
|
||||||
{
|
|
||||||
var runtimeGraphGeneratorName = "RuntimeGraphGenerator";
|
|
||||||
var runtimeGraphGeneratorProject = Path.Combine(c.BuildContext.BuildDirectory, "tools", runtimeGraphGeneratorName);
|
|
||||||
var runtimeGraphGeneratorOutput = Path.Combine(Dirs.Output, "tools", runtimeGraphGeneratorName);
|
|
||||||
|
|
||||||
DotNetCli.Stage2.Publish(
|
|
||||||
"--output", runtimeGraphGeneratorOutput,
|
|
||||||
runtimeGraphGeneratorProject).Execute().EnsureSuccessful();
|
|
||||||
var runtimeGraphGeneratorExe = Path.Combine(runtimeGraphGeneratorOutput, $"{runtimeGraphGeneratorName}{Constants.ExeSuffix}");
|
|
||||||
|
|
||||||
Cmd(runtimeGraphGeneratorExe, "--project", SharedFrameworkSourceRoot, "--deps", destinationDeps, runtimeGraphGeneratorRuntime)
|
|
||||||
.Execute();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
c.Error($"Could not determine rid graph generation runtime for platform {PlatformServices.Default.Runtime.OperatingSystemPlatform}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// corehost will be renamed to dotnet at some point and then we will not need to rename it here.
|
|
||||||
File.Copy(
|
|
||||||
Path.Combine(Dirs.Corehost, $"{CoreHostBaseName}{Constants.ExeSuffix}"),
|
|
||||||
Path.Combine(SharedFrameworkNameAndVersionRoot, $"dotnet{Constants.ExeSuffix}"));
|
|
||||||
File.Copy(
|
|
||||||
Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}{HostPolicyBaseName}{Constants.DynamicLibSuffix}"),
|
|
||||||
Path.Combine(SharedFrameworkNameAndVersionRoot, $"{Constants.DynamicLibPrefix}{HostPolicyBaseName}{Constants.DynamicLibSuffix}"), true);
|
|
||||||
|
|
||||||
if (File.Exists(Path.Combine(SharedFrameworkNameAndVersionRoot, "mscorlib.ni.dll")))
|
|
||||||
{
|
|
||||||
// Publish already places the crossgen'd version of mscorlib into the output, so we can
|
|
||||||
// remove the IL version
|
|
||||||
File.Delete(Path.Combine(SharedFrameworkNameAndVersionRoot, "mscorlib.dll"));
|
|
||||||
c.BuildContext["SharedFrameworkNameAndVersionRoot"] = SharedFrameworkNameAndVersionRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Success();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Target]
|
|
||||||
public static BuildTargetResult PublishSharedHost(BuildTargetContext c)
|
|
||||||
{
|
|
||||||
string SharedHostPublishRoot = Path.Combine(Dirs.Output, "obj", "sharedhost");
|
|
||||||
|
|
||||||
if (Directory.Exists(SharedHostPublishRoot))
|
|
||||||
{
|
|
||||||
Utils.DeleteDirectory(SharedHostPublishRoot);
|
|
||||||
}
|
|
||||||
Directory.CreateDirectory(SharedHostPublishRoot);
|
|
||||||
|
|
||||||
// corehost will be renamed to dotnet at some point and then this can be removed.
|
|
||||||
File.Copy(
|
|
||||||
Path.Combine(Dirs.Corehost, $"{CoreHostBaseName}{Constants.ExeSuffix}"),
|
|
||||||
Path.Combine(SharedHostPublishRoot, $"dotnet{Constants.ExeSuffix}"));
|
|
||||||
File.Copy(
|
|
||||||
Path.Combine(Dirs.Corehost, $"{Constants.DynamicLibPrefix}{DotnetHostFxrBaseName}{Constants.DynamicLibSuffix}"),
|
|
||||||
Path.Combine(SharedHostPublishRoot, $"{Constants.DynamicLibPrefix}{DotnetHostFxrBaseName}{Constants.DynamicLibSuffix}"));
|
|
||||||
|
|
||||||
c.BuildContext["SharedHostPublishRoot"] = SharedHostPublishRoot;
|
|
||||||
|
|
||||||
return c.Success();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetVersionFromProjectJson(string pathToProjectJson)
|
|
||||||
{
|
|
||||||
Regex r = new Regex($"\"{Regex.Escape(SharedFrameworkName)}\"\\s*:\\s*\"(?'version'[^\"]*)\"");
|
|
||||||
|
|
||||||
foreach(var line in File.ReadAllLines(pathToProjectJson))
|
|
||||||
{
|
|
||||||
var m = r.Match(line);
|
|
||||||
|
|
||||||
if (m.Success)
|
|
||||||
{
|
|
||||||
return m.Groups["version"].Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidOperationException("Unable to match the version name from " + pathToProjectJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Target]
|
|
||||||
[Environment("CROSSGEN_SHAREDFRAMEWORK", "1", "true")]
|
|
||||||
public static BuildTargetResult CrossGenAllManagedAssemblies(BuildTargetContext c)
|
|
||||||
{
|
|
||||||
string pathToAssemblies = c.BuildContext.Get<string>("SharedFrameworkNameAndVersionRoot");
|
|
||||||
|
|
||||||
foreach (var file in Directory.GetFiles(pathToAssemblies))
|
|
||||||
{
|
|
||||||
string fileName = Path.GetFileName(file);
|
|
||||||
|
|
||||||
if (fileName == "mscorlib.dll" || fileName == "mscorlib.ni.dll" || !HasMetadata(file))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
string tempPathName = Path.ChangeExtension(file, "readytorun");
|
|
||||||
|
|
||||||
// This is not always correct. The version of crossgen we need to pick up is whatever one was restored as part
|
|
||||||
// of the Microsoft.NETCore.Runtime.CoreCLR package that is part of the shared library. For now, the version hardcoded
|
|
||||||
// in CompileTargets and the one in the shared library project.json match and are updated in lock step, but long term
|
|
||||||
// we need to be able to look at the project.lock.json file and figure out what version of Microsoft.NETCore.Runtime.CoreCLR
|
|
||||||
// was used, and then select that version.
|
|
||||||
ExecSilent(Crossgen.GetCrossgenPathForVersion(CompileTargets.CoreCLRVersion),
|
|
||||||
"-readytorun", "-in", file, "-out", tempPathName, "-platform_assemblies_paths", pathToAssemblies);
|
|
||||||
|
|
||||||
File.Delete(file);
|
|
||||||
File.Move(tempPathName, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.Success();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool HasMetadata(string pathToFile)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using (var inStream = File.OpenRead(pathToFile))
|
|
||||||
{
|
|
||||||
using (var peReader = new PEReader(inStream))
|
|
||||||
{
|
|
||||||
return peReader.HasMetadata;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (BadImageFormatException) { }
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,7 +16,8 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
public static readonly string[] TestPackageProjects = new[]
|
public static readonly string[] TestPackageProjects = new[]
|
||||||
{
|
{
|
||||||
"dotnet-hello/v1/dotnet-hello",
|
"dotnet-hello/v1/dotnet-hello",
|
||||||
"dotnet-hello/v2/dotnet-hello"
|
"dotnet-hello/v2/dotnet-hello",
|
||||||
|
"dotnet-portable"
|
||||||
};
|
};
|
||||||
|
|
||||||
public static readonly string[] TestProjects = new[]
|
public static readonly string[] TestProjects = new[]
|
||||||
|
|
|
@ -7,11 +7,11 @@ using Microsoft.Extensions.PlatformAbstractions;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
internal class DotNetCli
|
public class DotNetCli
|
||||||
{
|
{
|
||||||
public static readonly DotNetCli Stage0 = new DotNetCli(GetStage0Path());
|
public static readonly DotNetCli Stage0 = new DotNetCli(GetStage0Path());
|
||||||
public static readonly DotNetCli Stage1 = new DotNetCli(Path.Combine(Dirs.Stage1, "bin"));
|
public static readonly DotNetCli Stage1 = new DotNetCli(Dirs.Stage1);
|
||||||
public static readonly DotNetCli Stage2 = new DotNetCli(Path.Combine(Dirs.Stage2, "bin"));
|
public static readonly DotNetCli Stage2 = new DotNetCli(Dirs.Stage2);
|
||||||
|
|
||||||
public string BinPath { get; }
|
public string BinPath { get; }
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
public class Monikers
|
public class Monikers
|
||||||
{
|
{
|
||||||
|
public const string SharedFrameworkName = "Microsoft.NETCore.App";
|
||||||
|
|
||||||
public static string GetProductMoniker(BuildTargetContext c, string artifactPrefix)
|
public static string GetProductMoniker(BuildTargetContext c, string artifactPrefix)
|
||||||
{
|
{
|
||||||
string osname = GetOSShortName();
|
string osname = GetOSShortName();
|
||||||
|
@ -31,7 +33,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
case "rtm":
|
case "rtm":
|
||||||
packageName = "dotnet";
|
packageName = "dotnet";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception($"Unknown channel - {channel}");
|
throw new Exception($"Unknown channel - {channel}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +44,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
var sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
var sharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
||||||
|
|
||||||
return $"dotnet-sharedframework-{SharedFrameworkTargets.SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower();
|
return $"dotnet-sharedframework-{SharedFrameworkName}-{sharedFrameworkNugetVersion}".ToLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetOSShortName()
|
public static string GetOSShortName()
|
||||||
|
|
|
@ -101,8 +101,15 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CopyDirectoryRecursively(string path, string destination)
|
public static void CopyDirectoryRecursively(string path, string destination, bool keepParentDir = false)
|
||||||
{
|
{
|
||||||
|
if (keepParentDir)
|
||||||
|
{
|
||||||
|
path = path.TrimEnd(Path.DirectorySeparatorChar);
|
||||||
|
destination = Path.Combine(destination, Path.GetFileName(path));
|
||||||
|
Directory.CreateDirectory(destination);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
|
foreach (var file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
string destFile = file.Replace(path, destination);
|
string destFile = file.Replace(path, destination);
|
||||||
|
|
|
@ -2,7 +2,9 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.DotNet.ProjectModel;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
|
using Microsoft.DotNet.ProjectModel.Compilation;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Utils
|
namespace Microsoft.DotNet.Cli.Utils
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
|
using Microsoft.DotNet.ProjectModel.Compilation;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
using NuGet.Packaging;
|
using NuGet.Packaging;
|
||||||
|
@ -38,11 +39,15 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
|
|
||||||
var commandPath = Path.Combine(packageDirectory, commandFile);
|
var commandPath = Path.Combine(packageDirectory, commandFile);
|
||||||
|
|
||||||
|
var isPortable = DetermineIfPortableApp(commandPath);
|
||||||
|
|
||||||
return CreateCommandSpecWrappingWithCorehostfDll(
|
return CreateCommandSpecWrappingWithCorehostfDll(
|
||||||
commandPath,
|
commandPath,
|
||||||
commandArguments,
|
commandArguments,
|
||||||
depsFilePath,
|
depsFilePath,
|
||||||
commandResolutionStrategy);
|
commandResolutionStrategy,
|
||||||
|
nugetPackagesRoot,
|
||||||
|
isPortable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetPackageDirectoryFullPath(LockFilePackageLibrary library, string nugetPackagesRoot)
|
private string GetPackageDirectoryFullPath(LockFilePackageLibrary library, string nugetPackagesRoot)
|
||||||
|
@ -69,7 +74,9 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
string commandPath,
|
string commandPath,
|
||||||
IEnumerable<string> commandArguments,
|
IEnumerable<string> commandArguments,
|
||||||
string depsFilePath,
|
string depsFilePath,
|
||||||
CommandResolutionStrategy commandResolutionStrategy)
|
CommandResolutionStrategy commandResolutionStrategy,
|
||||||
|
string nugetPackagesRoot,
|
||||||
|
bool isPortable)
|
||||||
{
|
{
|
||||||
var commandExtension = Path.GetExtension(commandPath);
|
var commandExtension = Path.GetExtension(commandPath);
|
||||||
|
|
||||||
|
@ -79,7 +86,9 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
commandPath,
|
commandPath,
|
||||||
commandArguments,
|
commandArguments,
|
||||||
depsFilePath,
|
depsFilePath,
|
||||||
commandResolutionStrategy);
|
commandResolutionStrategy,
|
||||||
|
nugetPackagesRoot,
|
||||||
|
isPortable);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy);
|
return CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy);
|
||||||
|
@ -89,11 +98,30 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
string commandPath,
|
string commandPath,
|
||||||
IEnumerable<string> commandArguments,
|
IEnumerable<string> commandArguments,
|
||||||
string depsFilePath,
|
string depsFilePath,
|
||||||
CommandResolutionStrategy commandResolutionStrategy)
|
CommandResolutionStrategy commandResolutionStrategy,
|
||||||
|
string nugetPackagesRoot,
|
||||||
|
bool isPortable)
|
||||||
{
|
{
|
||||||
var corehost = CoreHost.HostExePath;
|
string host = string.Empty;
|
||||||
|
|
||||||
var arguments = new List<string>();
|
var arguments = new List<string>();
|
||||||
|
|
||||||
|
if (isPortable)
|
||||||
|
{
|
||||||
|
var muxer = new Muxer();
|
||||||
|
|
||||||
|
host = muxer.MuxerPath;
|
||||||
|
if (host == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Unable to locate dotnet multiplexer");
|
||||||
|
}
|
||||||
|
|
||||||
|
arguments.Add("exec");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
host = CoreHost.LocalHostExePath;
|
||||||
|
}
|
||||||
|
|
||||||
arguments.Add(commandPath);
|
arguments.Add(commandPath);
|
||||||
|
|
||||||
if (depsFilePath != null)
|
if (depsFilePath != null)
|
||||||
|
@ -102,9 +130,12 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
arguments.Add(depsFilePath);
|
arguments.Add(depsFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arguments.Add("--additionalprobingpath");
|
||||||
|
arguments.Add(nugetPackagesRoot);
|
||||||
|
|
||||||
arguments.AddRange(commandArguments);
|
arguments.AddRange(commandArguments);
|
||||||
|
|
||||||
return CreateCommandSpec(corehost, arguments, commandResolutionStrategy);
|
return CreateCommandSpec(host, arguments, commandResolutionStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandSpec CreateCommandSpec(
|
private CommandSpec CreateCommandSpec(
|
||||||
|
@ -115,6 +146,23 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(commandArguments);
|
var escapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(commandArguments);
|
||||||
|
|
||||||
return new CommandSpec(commandPath, escapedArgs, commandResolutionStrategy);
|
return new CommandSpec(commandPath, escapedArgs, commandResolutionStrategy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool DetermineIfPortableApp(string commandPath)
|
||||||
|
{
|
||||||
|
var commandDir = Path.GetDirectoryName(commandPath);
|
||||||
|
|
||||||
|
var runtimeConfigPath = Directory.EnumerateFiles(commandDir)
|
||||||
|
.FirstOrDefault(x => x.EndsWith("runtimeconfig.json"));
|
||||||
|
|
||||||
|
if (runtimeConfigPath == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var runtimeConfig = new RuntimeConfig(runtimeConfigPath);
|
||||||
|
|
||||||
|
return runtimeConfig.IsPortable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,18 +5,28 @@ using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
|
using Microsoft.DotNet.ProjectModel.Compilation;
|
||||||
|
using Microsoft.Extensions.DependencyModel;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
using NuGet.Packaging;
|
using NuGet.Packaging;
|
||||||
|
using NuGet.ProjectModel;
|
||||||
|
|
||||||
|
using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile;
|
||||||
|
using FileFormatException = Microsoft.DotNet.ProjectModel.FileFormatException;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Utils
|
namespace Microsoft.DotNet.Cli.Utils
|
||||||
{
|
{
|
||||||
public class ProjectToolsCommandResolver : ICommandResolver
|
public class ProjectToolsCommandResolver : ICommandResolver
|
||||||
{
|
{
|
||||||
private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetStandardApp15;
|
private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetStandardApp15;
|
||||||
|
|
||||||
private static readonly CommandResolutionStrategy s_commandResolutionStrategy =
|
private static readonly CommandResolutionStrategy s_commandResolutionStrategy =
|
||||||
CommandResolutionStrategy.ProjectToolsPackage;
|
CommandResolutionStrategy.ProjectToolsPackage;
|
||||||
|
|
||||||
|
private static readonly string s_currentRuntimeIdentifier = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier();
|
||||||
|
|
||||||
|
|
||||||
private List<string> _allowedCommandExtensions;
|
private List<string> _allowedCommandExtensions;
|
||||||
private IPackagedCommandSpecFactory _packagedCommandSpecFactory;
|
private IPackagedCommandSpecFactory _packagedCommandSpecFactory;
|
||||||
|
|
||||||
|
@ -90,23 +100,21 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
IEnumerable<string> args,
|
IEnumerable<string> args,
|
||||||
ProjectContext projectContext)
|
ProjectContext projectContext)
|
||||||
{
|
{
|
||||||
//todo: change this for new resolution strategy
|
|
||||||
var lockFilePath = Path.Combine(
|
|
||||||
projectContext.ProjectDirectory,
|
|
||||||
"artifacts", "Tools", toolLibrary.Name,
|
|
||||||
"project.lock.json");
|
|
||||||
|
|
||||||
if (!File.Exists(lockFilePath))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var lockFile = LockFileReader.Read(lockFilePath);
|
|
||||||
|
|
||||||
var lockFilePackageLibrary = lockFile.PackageLibraries.FirstOrDefault(l => l.Name == toolLibrary.Name);
|
|
||||||
|
|
||||||
var nugetPackagesRoot = projectContext.PackagesDirectory;
|
var nugetPackagesRoot = projectContext.PackagesDirectory;
|
||||||
|
|
||||||
|
var lockFile = GetToolLockFile(toolLibrary, nugetPackagesRoot);
|
||||||
|
var lockFilePackageLibrary = lockFile.PackageLibraries.FirstOrDefault(l => l.Name == toolLibrary.Name);
|
||||||
|
|
||||||
|
var depsFileRoot = Path.GetDirectoryName(lockFile.LockFilePath);
|
||||||
|
var depsFilePath = GetToolDepsFilePath(toolLibrary, lockFile, depsFileRoot);
|
||||||
|
|
||||||
|
var toolProjectContext = new ProjectContextBuilder()
|
||||||
|
.WithLockFile(lockFile)
|
||||||
|
.WithTargetFramework(s_toolPackageFramework.ToString())
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var exporter = toolProjectContext.CreateExporter(Constants.DefaultConfiguration);
|
||||||
|
|
||||||
return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
|
return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
|
||||||
lockFilePackageLibrary,
|
lockFilePackageLibrary,
|
||||||
commandName,
|
commandName,
|
||||||
|
@ -114,7 +122,44 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
_allowedCommandExtensions,
|
_allowedCommandExtensions,
|
||||||
projectContext.PackagesDirectory,
|
projectContext.PackagesDirectory,
|
||||||
s_commandResolutionStrategy,
|
s_commandResolutionStrategy,
|
||||||
null);
|
depsFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private LockFile GetToolLockFile(
|
||||||
|
LibraryRange toolLibrary,
|
||||||
|
string nugetPackagesRoot)
|
||||||
|
{
|
||||||
|
var lockFilePath = GetToolLockFilePath(toolLibrary, nugetPackagesRoot);
|
||||||
|
|
||||||
|
if (!File.Exists(lockFilePath))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
LockFile lockFile = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lockFile = LockFileReader.Read(lockFilePath);
|
||||||
|
}
|
||||||
|
catch (FileFormatException ex)
|
||||||
|
{
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lockFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetToolLockFilePath(
|
||||||
|
LibraryRange toolLibrary,
|
||||||
|
string nugetPackagesRoot)
|
||||||
|
{
|
||||||
|
var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);
|
||||||
|
|
||||||
|
return toolPathCalculator.GetBestLockFilePath(
|
||||||
|
toolLibrary.Name,
|
||||||
|
toolLibrary.VersionRange,
|
||||||
|
s_toolPackageFramework);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProjectContext GetProjectContextFromDirectory(string directory, NuGetFramework framework)
|
private ProjectContext GetProjectContextFromDirectory(string directory, NuGetFramework framework)
|
||||||
|
@ -143,5 +188,50 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
|
|
||||||
return projectContext;
|
return projectContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetToolDepsFilePath(
|
||||||
|
LibraryRange toolLibrary,
|
||||||
|
LockFile toolLockFile,
|
||||||
|
string depsPathRoot)
|
||||||
|
{
|
||||||
|
var depsJsonPath = Path.Combine(
|
||||||
|
depsPathRoot,
|
||||||
|
toolLibrary.Name + FileNameSuffixes.DepsJson);
|
||||||
|
|
||||||
|
EnsureToolJsonDepsFileExists(toolLibrary, toolLockFile, depsJsonPath);
|
||||||
|
|
||||||
|
return depsJsonPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EnsureToolJsonDepsFileExists(
|
||||||
|
LibraryRange toolLibrary,
|
||||||
|
LockFile toolLockFile,
|
||||||
|
string depsPath)
|
||||||
|
{
|
||||||
|
if (!File.Exists(depsPath))
|
||||||
|
{
|
||||||
|
var projectContext = new ProjectContextBuilder()
|
||||||
|
.WithLockFile(toolLockFile)
|
||||||
|
.WithTargetFramework(s_toolPackageFramework.ToString())
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var exporter = projectContext.CreateExporter(Constants.DefaultConfiguration);
|
||||||
|
|
||||||
|
var dependencyContext = new DependencyContextBuilder()
|
||||||
|
.Build(null,
|
||||||
|
null,
|
||||||
|
exporter.GetAllExports(),
|
||||||
|
true,
|
||||||
|
s_toolPackageFramework,
|
||||||
|
string.Empty);
|
||||||
|
|
||||||
|
using (var fileStream = File.Create(depsPath))
|
||||||
|
{
|
||||||
|
var dependencyContextWriter = new DependencyContextWriter();
|
||||||
|
|
||||||
|
dependencyContextWriter.Write(dependencyContext, fileStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
// 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.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NuGet.Frameworks;
|
||||||
|
using NuGet.Versioning;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Cli.Utils
|
||||||
|
{
|
||||||
|
public class ToolPathCalculator
|
||||||
|
{
|
||||||
|
private readonly string _packagesDirectory;
|
||||||
|
|
||||||
|
public ToolPathCalculator(string packagesDirectory)
|
||||||
|
{
|
||||||
|
_packagesDirectory = packagesDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetBestLockFilePath(string packageId, VersionRange versionRange, NuGetFramework framework)
|
||||||
|
{
|
||||||
|
var availableToolVersions = GetAvailableToolVersions(packageId);
|
||||||
|
|
||||||
|
var bestVersion = versionRange.FindBestMatch(availableToolVersions);
|
||||||
|
|
||||||
|
return GetLockFilePath(packageId, bestVersion, framework);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetLockFilePath(string packageId, NuGetVersion version, NuGetFramework framework)
|
||||||
|
{
|
||||||
|
return Path.Combine(
|
||||||
|
GetBaseToolPath(packageId),
|
||||||
|
version.ToNormalizedString(),
|
||||||
|
framework.GetShortFolderName(),
|
||||||
|
"project.lock.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetBaseToolPath(string packageId)
|
||||||
|
{
|
||||||
|
return Path.Combine(
|
||||||
|
_packagesDirectory,
|
||||||
|
".tools",
|
||||||
|
packageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<NuGetVersion> GetAvailableToolVersions(string packageId)
|
||||||
|
{
|
||||||
|
var availableVersions = new List<NuGetVersion>();
|
||||||
|
|
||||||
|
var toolBase = GetBaseToolPath(packageId);
|
||||||
|
var versionDirectories = Directory.EnumerateDirectories(toolBase);
|
||||||
|
|
||||||
|
foreach (var versionDirectory in versionDirectories)
|
||||||
|
{
|
||||||
|
var version = Path.GetFileName(versionDirectory);
|
||||||
|
|
||||||
|
NuGetVersion nugetVersion = null;
|
||||||
|
NuGetVersion.TryParse(version, out nugetVersion);
|
||||||
|
|
||||||
|
if (nugetVersion != null)
|
||||||
|
{
|
||||||
|
availableVersions.Add(nugetVersion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return availableVersions;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
65
src/Microsoft.DotNet.Cli.Utils/Muxer.cs
Normal file
65
src/Microsoft.DotNet.Cli.Utils/Muxer.cs
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Cli.Utils
|
||||||
|
{
|
||||||
|
public class Muxer
|
||||||
|
{
|
||||||
|
private static readonly string s_muxerName = "dotnet";
|
||||||
|
private static readonly string s_muxerFileName = s_muxerName + Constants.ExeSuffix;
|
||||||
|
|
||||||
|
private string _muxerPath;
|
||||||
|
|
||||||
|
public string MuxerPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _muxerPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Muxer()
|
||||||
|
{
|
||||||
|
if (!TryResolveMuxerFromParentDirectories())
|
||||||
|
{
|
||||||
|
TryResolverMuxerFromPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryResolveMuxerFromParentDirectories()
|
||||||
|
{
|
||||||
|
var appBase = new DirectoryInfo(PlatformServices.Default.Application.ApplicationBasePath);
|
||||||
|
var muxerDir = appBase.Parent?.Parent;
|
||||||
|
|
||||||
|
if (muxerDir == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var muxerCandidate = Path.Combine(muxerDir.FullName, s_muxerFileName);
|
||||||
|
|
||||||
|
if (!File.Exists(muxerCandidate))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_muxerPath = muxerCandidate;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool TryResolverMuxerFromPath()
|
||||||
|
{
|
||||||
|
var muxerPath = Env.GetCommandPath(s_muxerName, Constants.ExeSuffix);
|
||||||
|
|
||||||
|
if (muxerPath == null || !File.Exists(muxerPath))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_muxerPath = muxerPath;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,11 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537"
|
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537",
|
||||||
|
"NuGet.Versioning": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.Packaging": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.Frameworks": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.ProjectModel": "3.4.0-rtm-0763"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net451": {
|
"net451": {
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
public string RuntimeIdentifier { get; }
|
public string RuntimeIdentifier { get; }
|
||||||
|
|
||||||
public Project ProjectFile => RootProject.Project;
|
public Project ProjectFile => RootProject?.Project;
|
||||||
|
|
||||||
public LockFile LockFile { get; }
|
public LockFile LockFile { get; }
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
{
|
{
|
||||||
ProjectDirectory = Project?.ProjectDirectory ?? ProjectDirectory;
|
ProjectDirectory = Project?.ProjectDirectory ?? ProjectDirectory;
|
||||||
|
|
||||||
if (GlobalSettings == null)
|
if (GlobalSettings == null && ProjectDirectory != null)
|
||||||
{
|
{
|
||||||
RootDirectory = ProjectRootResolver.ResolveRootDirectory(ProjectDirectory);
|
RootDirectory = ProjectRootResolver.ResolveRootDirectory(ProjectDirectory);
|
||||||
|
|
||||||
|
@ -157,7 +157,6 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
var frameworkReferenceResolver = new FrameworkReferenceResolver(ReferenceAssembliesPath);
|
var frameworkReferenceResolver = new FrameworkReferenceResolver(ReferenceAssembliesPath);
|
||||||
|
|
||||||
LockFileLookup lockFileLookup = null;
|
LockFileLookup lockFileLookup = null;
|
||||||
|
|
||||||
EnsureProjectLoaded();
|
EnsureProjectLoaded();
|
||||||
|
|
||||||
LockFile = LockFile ?? LockFileResolver(ProjectDirectory);
|
LockFile = LockFile ?? LockFileResolver(ProjectDirectory);
|
||||||
|
@ -167,7 +166,10 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
if (LockFile != null)
|
if (LockFile != null)
|
||||||
{
|
{
|
||||||
validLockFile = LockFile.IsValidForProject(Project, out lockFileValidationMessage);
|
if (Project != null)
|
||||||
|
{
|
||||||
|
validLockFile = LockFile.IsValidForProject(Project, out lockFileValidationMessage);
|
||||||
|
}
|
||||||
|
|
||||||
lockFileLookup = new LockFileLookup(LockFile);
|
lockFileLookup = new LockFileLookup(LockFile);
|
||||||
}
|
}
|
||||||
|
@ -175,10 +177,14 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
var libraries = new Dictionary<LibraryKey, LibraryDescription>();
|
var libraries = new Dictionary<LibraryKey, LibraryDescription>();
|
||||||
var projectResolver = new ProjectDependencyProvider(ProjectResolver);
|
var projectResolver = new ProjectDependencyProvider(ProjectResolver);
|
||||||
|
|
||||||
var mainProject = projectResolver.GetDescription(TargetFramework, Project, targetLibrary: null);
|
ProjectDescription mainProject = null;
|
||||||
|
if (Project != null)
|
||||||
|
{
|
||||||
|
mainProject = projectResolver.GetDescription(TargetFramework, Project, targetLibrary: null);
|
||||||
|
|
||||||
// Add the main project
|
// Add the main project
|
||||||
libraries.Add(new LibraryKey(mainProject.Identity.Name), mainProject);
|
libraries.Add(new LibraryKey(mainProject.Identity.Name), mainProject);
|
||||||
|
}
|
||||||
|
|
||||||
LockFileTarget target = null;
|
LockFileTarget target = null;
|
||||||
if (lockFileLookup != null)
|
if (lockFileLookup != null)
|
||||||
|
@ -251,7 +257,7 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a library manager
|
// Create a library manager
|
||||||
var libraryManager = new LibraryManager(libraries.Values.ToList(), diagnostics, Project.ProjectFilePath);
|
var libraryManager = new LibraryManager(libraries.Values.ToList(), diagnostics, Project?.ProjectFilePath);
|
||||||
|
|
||||||
return new ProjectContext(
|
return new ProjectContext(
|
||||||
GlobalSettings,
|
GlobalSettings,
|
||||||
|
@ -375,13 +381,9 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
private void EnsureProjectLoaded()
|
private void EnsureProjectLoaded()
|
||||||
{
|
{
|
||||||
if (Project == null)
|
if (Project == null && ProjectDirectory != null)
|
||||||
{
|
{
|
||||||
Project = ProjectResolver(ProjectDirectory);
|
Project = ProjectResolver(ProjectDirectory);
|
||||||
if (Project == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"Unable to resolve project from {ProjectDirectory}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
// 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.Linq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.ProjectModel
|
||||||
|
{
|
||||||
|
public class RuntimeConfig
|
||||||
|
{
|
||||||
|
public bool IsPortable { get; }
|
||||||
|
public RuntimeConfigFramework Framework { get; }
|
||||||
|
|
||||||
|
public RuntimeConfig(string runtimeConfigPath)
|
||||||
|
{
|
||||||
|
var runtimeConfigJson = OpenRuntimeConfig(runtimeConfigPath);
|
||||||
|
|
||||||
|
Framework = ParseFramework(runtimeConfigJson);
|
||||||
|
|
||||||
|
IsPortable = Framework != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JObject OpenRuntimeConfig(string runtimeConfigPath)
|
||||||
|
{
|
||||||
|
return JObject.Parse(File.ReadAllText(runtimeConfigPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
private RuntimeConfigFramework ParseFramework(JObject runtimeConfigRoot)
|
||||||
|
{
|
||||||
|
var runtimeOptionsRoot = runtimeConfigRoot["runtimeOptions"];
|
||||||
|
if (runtimeOptionsRoot == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var framework = (JObject) runtimeOptionsRoot["framework"];
|
||||||
|
if (framework == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RuntimeConfigFramework.ParseFromFrameworkRoot(framework);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
// 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.Linq;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.ProjectModel
|
||||||
|
{
|
||||||
|
public class RuntimeConfigFramework
|
||||||
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Version { get; set; }
|
||||||
|
|
||||||
|
public static RuntimeConfigFramework ParseFromFrameworkRoot(JObject framework)
|
||||||
|
{
|
||||||
|
var properties = framework.Properties();
|
||||||
|
|
||||||
|
var name = properties.FirstOrDefault(p => p.Name.Equals("name", StringComparison.OrdinalIgnoreCase));
|
||||||
|
var version = properties.FirstOrDefault(p => p.Name.Equals("version", StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
if (name == null || version == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RuntimeConfigFramework
|
||||||
|
{
|
||||||
|
Name = name.Value.ToString(),
|
||||||
|
Version = version.Value.ToString()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -255,27 +255,33 @@ namespace Microsoft.DotNet.Tools.Build
|
||||||
|
|
||||||
private void CollectCompilerNamePreconditions(ProjectContext project, IncrementalPreconditions preconditions)
|
private void CollectCompilerNamePreconditions(ProjectContext project, IncrementalPreconditions preconditions)
|
||||||
{
|
{
|
||||||
var projectCompiler = project.ProjectFile.CompilerName;
|
if (project.ProjectFile != null)
|
||||||
|
|
||||||
if (!KnownCompilers.Any(knownCompiler => knownCompiler.Equals(projectCompiler, StringComparison.Ordinal)))
|
|
||||||
{
|
{
|
||||||
preconditions.AddUnknownCompilerPrecondition(project.ProjectName(), projectCompiler);
|
var projectCompiler = project.ProjectFile.CompilerName;
|
||||||
|
|
||||||
|
if (!KnownCompilers.Any(knownCompiler => knownCompiler.Equals(projectCompiler, StringComparison.Ordinal)))
|
||||||
|
{
|
||||||
|
preconditions.AddUnknownCompilerPrecondition(project.ProjectName(), projectCompiler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CollectScriptPreconditions(ProjectContext project, IncrementalPreconditions preconditions)
|
private void CollectScriptPreconditions(ProjectContext project, IncrementalPreconditions preconditions)
|
||||||
{
|
{
|
||||||
var preCompileScripts = project.ProjectFile.Scripts.GetOrEmpty(ScriptNames.PreCompile);
|
if (project.ProjectFile != null)
|
||||||
var postCompileScripts = project.ProjectFile.Scripts.GetOrEmpty(ScriptNames.PostCompile);
|
|
||||||
|
|
||||||
if (preCompileScripts.Any())
|
|
||||||
{
|
{
|
||||||
preconditions.AddPrePostScriptPrecondition(project.ProjectName(), ScriptNames.PreCompile);
|
var preCompileScripts = project.ProjectFile.Scripts.GetOrEmpty(ScriptNames.PreCompile);
|
||||||
}
|
var postCompileScripts = project.ProjectFile.Scripts.GetOrEmpty(ScriptNames.PostCompile);
|
||||||
|
|
||||||
if (postCompileScripts.Any())
|
if (preCompileScripts.Any())
|
||||||
{
|
{
|
||||||
preconditions.AddPrePostScriptPrecondition(project.ProjectName(), ScriptNames.PostCompile);
|
preconditions.AddPrePostScriptPrecondition(project.ProjectName(), ScriptNames.PreCompile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (postCompileScripts.Any())
|
||||||
|
{
|
||||||
|
preconditions.AddPrePostScriptPrecondition(project.ProjectName(), ScriptNames.PostCompile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
//used in incremental precondition checks
|
//used in incremental precondition checks
|
||||||
public static IEnumerable<string> GetCommandsInvokedByCompile(ProjectContext project)
|
public static IEnumerable<string> GetCommandsInvokedByCompile(ProjectContext project)
|
||||||
{
|
{
|
||||||
return new List<string> {project.ProjectFile.CompilerName, "compile"};
|
return new List<string> {project.ProjectFile?.CompilerName, "compile"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -94,6 +94,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
|
||||||
TryAddOutputFile(context, inputFolder, outputName);
|
TryAddOutputFile(context, inputFolder, outputName);
|
||||||
TryAddOutputFile(context, inputFolder, $"{Project.Name}.xml");
|
TryAddOutputFile(context, inputFolder, $"{Project.Name}.xml");
|
||||||
|
TryAddOutputFile(context, inputFolder, $"{Project.Name}.runtimeconfig.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual bool GeneratePackage(string nupkg, List<DiagnosticMessage> packDiagnostics)
|
protected virtual bool GeneratePackage(string nupkg, List<DiagnosticMessage> packDiagnostics)
|
||||||
|
|
|
@ -40,18 +40,7 @@ namespace Microsoft.DotNet.Tools.Restore
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var projectRestoreResult = NuGet3.Restore(args, quiet);
|
return NuGet3.Restore(args, quiet);
|
||||||
|
|
||||||
var restoreTasks = GetRestoreTasks(args);
|
|
||||||
|
|
||||||
foreach (var restoreTask in restoreTasks)
|
|
||||||
{
|
|
||||||
var project = ProjectReader.GetProject(restoreTask.ProjectPath);
|
|
||||||
|
|
||||||
RestoreTools(project, restoreTask, quiet);
|
|
||||||
}
|
|
||||||
|
|
||||||
return projectRestoreResult;
|
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException e)
|
catch (InvalidOperationException e)
|
||||||
{
|
{
|
||||||
|
@ -69,147 +58,5 @@ namespace Microsoft.DotNet.Tools.Restore
|
||||||
|
|
||||||
return app.Execute(args);
|
return app.Execute(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<RestoreTask> GetRestoreTasks(IEnumerable<string> args)
|
|
||||||
{
|
|
||||||
var directory = Directory.GetCurrentDirectory();
|
|
||||||
|
|
||||||
if (args.Any())
|
|
||||||
{
|
|
||||||
var firstArg = args.First();
|
|
||||||
|
|
||||||
if (IsProjectFile(firstArg))
|
|
||||||
{
|
|
||||||
return new [] {new RestoreTask { ProjectPath = firstArg, Arguments = args.Skip(1)} };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Directory.Exists(firstArg))
|
|
||||||
{
|
|
||||||
directory = firstArg;
|
|
||||||
|
|
||||||
args = args.Skip(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetAllProjectFiles(directory)
|
|
||||||
.Select(p => new RestoreTask {ProjectPath = p, Arguments = args});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string[] GetAllProjectFiles(string directory)
|
|
||||||
{
|
|
||||||
return Directory.GetFiles(directory, Project.FileName, SearchOption.AllDirectories);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsProjectFile(string firstArg)
|
|
||||||
{
|
|
||||||
return firstArg.EndsWith(Project.FileName) && File.Exists(firstArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RestoreTools(Project project, RestoreTask restoreTask, bool quiet)
|
|
||||||
{
|
|
||||||
foreach (var tooldep in project.Tools)
|
|
||||||
{
|
|
||||||
RestoreTool(tooldep, restoreTask, quiet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RestoreTool(LibraryRange tooldep, RestoreTask restoreTask, bool quiet)
|
|
||||||
{
|
|
||||||
var tempRoot = Path.Combine(restoreTask.ProjectDirectory, "obj");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var tempPath = Path.Combine(tempRoot, Guid.NewGuid().ToString(), "bin");
|
|
||||||
|
|
||||||
var restoreSucceded = RestoreToolToPath(tooldep, restoreTask.Arguments, tempPath, quiet);
|
|
||||||
if (restoreSucceded)
|
|
||||||
{
|
|
||||||
CreateDepsInPackageCache(tooldep, tempPath);
|
|
||||||
PersistLockFile(tooldep, tempPath, restoreTask.ProjectDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Directory.Delete(tempRoot, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void PersistLockFile(LibraryRange tooldep, string tempPath, string projectPath)
|
|
||||||
{
|
|
||||||
var sourcePath = Path.Combine(tempPath, "project.lock.json");
|
|
||||||
var targetDir = Path.Combine(projectPath, "artifacts", "Tools", tooldep.Name);
|
|
||||||
var targetPath = Path.Combine(targetDir, "project.lock.json");
|
|
||||||
|
|
||||||
if (Directory.Exists(targetDir)) Directory.Delete(targetDir, true);
|
|
||||||
Directory.CreateDirectory(targetDir);
|
|
||||||
|
|
||||||
Console.WriteLine($"Writing '{sourcePath}' to '{targetPath}'");
|
|
||||||
|
|
||||||
File.Move(sourcePath, targetPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CreateDepsInPackageCache(LibraryRange toolLibrary, string projectPath)
|
|
||||||
{
|
|
||||||
var context = ProjectContext.Create(projectPath,
|
|
||||||
FrameworkConstants.CommonFrameworks.NetStandardApp15, new[] { DefaultRid });
|
|
||||||
|
|
||||||
var toolDescription = context.LibraryManager.GetLibraries()
|
|
||||||
.Select(l => l as PackageDescription)
|
|
||||||
.Where(l => l != null)
|
|
||||||
.FirstOrDefault(l => l.Identity.Name == toolLibrary.Name);
|
|
||||||
|
|
||||||
var depsPath = Path.Combine(
|
|
||||||
toolDescription.Path,
|
|
||||||
Path.GetDirectoryName(toolDescription.RuntimeAssemblies.First().Path),
|
|
||||||
toolDescription.Identity.Name + FileNameSuffixes.Deps);
|
|
||||||
|
|
||||||
var depsJsonPath = Path.Combine(
|
|
||||||
toolDescription.Path,
|
|
||||||
Path.GetDirectoryName(toolDescription.RuntimeAssemblies.First().Path),
|
|
||||||
toolDescription.Identity.Name + FileNameSuffixes.DepsJson);
|
|
||||||
|
|
||||||
var calculator = context.GetOutputPaths(Constants.DefaultConfiguration, buidBasePath: null, outputPath: context.ProjectDirectory);
|
|
||||||
var executable = new Executable(context, calculator, context.CreateExporter(Constants.DefaultConfiguration), null);
|
|
||||||
|
|
||||||
executable.MakeCompilationOutputRunnable();
|
|
||||||
|
|
||||||
if (File.Exists(depsPath)) File.Delete(depsPath);
|
|
||||||
if (File.Exists(depsJsonPath)) File.Delete(depsJsonPath);
|
|
||||||
|
|
||||||
File.Move(Path.Combine(calculator.RuntimeOutputPath, "bin" + FileNameSuffixes.Deps), depsPath);
|
|
||||||
File.Move(Path.Combine(calculator.RuntimeOutputPath, "bin" + FileNameSuffixes.DepsJson), depsJsonPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool RestoreToolToPath(LibraryRange tooldep, IEnumerable<string> args, string tempPath, bool quiet)
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(tempPath);
|
|
||||||
var projectPath = Path.Combine(tempPath, Project.FileName);
|
|
||||||
|
|
||||||
Console.WriteLine($"Restoring Tool '{tooldep.Name}' for '{projectPath}' in '{tempPath}'");
|
|
||||||
|
|
||||||
File.WriteAllText(projectPath, GenerateProjectJsonContents(new[] {"netstandardapp1.5"}, tooldep));
|
|
||||||
return NuGet3.Restore(new[] { $"{projectPath}" }.Concat(args), quiet) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GenerateProjectJsonContents(IEnumerable<string> frameworks, LibraryRange tooldep)
|
|
||||||
{
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.AppendLine("{");
|
|
||||||
sb.AppendLine(" \"dependencies\": {");
|
|
||||||
sb.AppendLine($" \"{tooldep.Name}\": \"{tooldep.VersionRange.OriginalString}\"");
|
|
||||||
sb.AppendLine(" },");
|
|
||||||
sb.AppendLine(" \"frameworks\": {");
|
|
||||||
foreach (var framework in frameworks)
|
|
||||||
{
|
|
||||||
var importsStatement = "\"imports\": [ \"dnxcore50\", \"portable-net452+win81\" ]";
|
|
||||||
sb.AppendLine($" \"{framework}\": {{ {importsStatement} }}");
|
|
||||||
}
|
|
||||||
sb.AppendLine(" },");
|
|
||||||
sb.AppendLine(" \"runtimes\": { ");
|
|
||||||
sb.AppendLine($" \"{DefaultRid}\": {{}}");
|
|
||||||
sb.AppendLine(" }");
|
|
||||||
sb.AppendLine("}");
|
|
||||||
var pjContents = sb.ToString();
|
|
||||||
return pjContents;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.DotNet.ProjectModel;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Restore
|
|
||||||
{
|
|
||||||
public struct RestoreTask
|
|
||||||
{
|
|
||||||
public string ProjectPath { get; set; }
|
|
||||||
|
|
||||||
public IEnumerable<string> Arguments { get; set; }
|
|
||||||
|
|
||||||
public string ProjectDirectory => ProjectPath.EndsWith(Project.FileName, StringComparison.OrdinalIgnoreCase)
|
|
||||||
? Path.GetDirectoryName(ProjectPath)
|
|
||||||
: ProjectPath;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -38,7 +38,7 @@ $testName = "Microsoft.DotNet.Cli.Msi.Tests"
|
||||||
$testDir="$PSScriptRoot\$testName"
|
$testDir="$PSScriptRoot\$testName"
|
||||||
$testBin="$RepoRoot\artifacts\tests\$testName"
|
$testBin="$RepoRoot\artifacts\tests\$testName"
|
||||||
|
|
||||||
pushd "$Stage2Dir\bin"
|
pushd "$Stage2Dir"
|
||||||
|
|
||||||
try {
|
try {
|
||||||
.\dotnet restore `
|
.\dotnet restore `
|
||||||
|
|
|
@ -16,11 +16,14 @@ using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
|
using NuGet.Versioning;
|
||||||
|
using NuGet.ProjectModel;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Utils.Tests
|
namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
{
|
{
|
||||||
public class GivenAProjectToolsCommandResolver
|
public class GivenAProjectToolsCommandResolver
|
||||||
{
|
{
|
||||||
|
private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetStandardApp15;
|
||||||
|
|
||||||
private static readonly string s_liveProjectDirectory =
|
private static readonly string s_liveProjectDirectory =
|
||||||
Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithToolDependency");
|
Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithToolDependency");
|
||||||
|
@ -77,13 +80,13 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_returns_a_CommandSpec_with_CoreHost_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectTools()
|
public void It_returns_a_CommandSpec_with_DOTNET_as_FileName_and_CommandName_in_Args_when_CommandName_exists_in_ProjectTools()
|
||||||
{
|
{
|
||||||
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
||||||
|
|
||||||
var commandResolverArguments = new CommandResolverArguments()
|
var commandResolverArguments = new CommandResolverArguments()
|
||||||
{
|
{
|
||||||
CommandName = "dotnet-hello",
|
CommandName = "dotnet-portable",
|
||||||
CommandArguments = null,
|
CommandArguments = null,
|
||||||
ProjectDirectory = s_liveProjectDirectory
|
ProjectDirectory = s_liveProjectDirectory
|
||||||
};
|
};
|
||||||
|
@ -94,7 +97,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
|
|
||||||
var commandFile = Path.GetFileNameWithoutExtension(result.Path);
|
var commandFile = Path.GetFileNameWithoutExtension(result.Path);
|
||||||
|
|
||||||
commandFile.Should().Be("corehost");
|
commandFile.Should().Be("dotnet");
|
||||||
|
|
||||||
result.Args.Should().Contain(commandResolverArguments.CommandName);
|
result.Args.Should().Contain(commandResolverArguments.CommandName);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +109,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
|
|
||||||
var commandResolverArguments = new CommandResolverArguments()
|
var commandResolverArguments = new CommandResolverArguments()
|
||||||
{
|
{
|
||||||
CommandName = "dotnet-hello",
|
CommandName = "dotnet-portable",
|
||||||
CommandArguments = new [] { "arg with space"},
|
CommandArguments = new [] { "arg with space"},
|
||||||
ProjectDirectory = s_liveProjectDirectory
|
ProjectDirectory = s_liveProjectDirectory
|
||||||
};
|
};
|
||||||
|
@ -118,13 +121,13 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_returns_a_CommandSpec_with_Args_as_CommandPath_when_returning_a_CommandSpec_and_CommandArguments_are_null()
|
public void It_returns_a_CommandSpec_with_Args_containing_CommandPath_when_returning_a_CommandSpec_and_CommandArguments_are_null()
|
||||||
{
|
{
|
||||||
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
||||||
|
|
||||||
var commandResolverArguments = new CommandResolverArguments()
|
var commandResolverArguments = new CommandResolverArguments()
|
||||||
{
|
{
|
||||||
CommandName = "dotnet-hello",
|
CommandName = "dotnet-portable",
|
||||||
CommandArguments = null,
|
CommandArguments = null,
|
||||||
ProjectDirectory = s_liveProjectDirectory
|
ProjectDirectory = s_liveProjectDirectory
|
||||||
};
|
};
|
||||||
|
@ -134,9 +137,51 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
|
|
||||||
var commandPath = result.Args.Trim('"');
|
var commandPath = result.Args.Trim('"');
|
||||||
commandPath.Should().Contain("dotnet-hello");
|
commandPath.Should().Contain("dotnet-portable.dll");
|
||||||
|
}
|
||||||
|
|
||||||
File.Exists(commandPath).Should().BeTrue();
|
[Fact]
|
||||||
|
public void It_writes_a_deps_json_file_next_to_the_lockfile()
|
||||||
|
{
|
||||||
|
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
||||||
|
|
||||||
|
var commandResolverArguments = new CommandResolverArguments()
|
||||||
|
{
|
||||||
|
CommandName = "dotnet-portable",
|
||||||
|
CommandArguments = null,
|
||||||
|
ProjectDirectory = s_liveProjectDirectory
|
||||||
|
};
|
||||||
|
|
||||||
|
var context = ProjectContext.Create(Path.Combine(s_liveProjectDirectory, "project.json"), s_toolPackageFramework);
|
||||||
|
|
||||||
|
var nugetPackagesRoot = context.PackagesDirectory;
|
||||||
|
var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);
|
||||||
|
|
||||||
|
var lockFilePath = toolPathCalculator.GetLockFilePath(
|
||||||
|
"dotnet-portable",
|
||||||
|
new NuGetVersion("1.0.0"),
|
||||||
|
s_toolPackageFramework);
|
||||||
|
|
||||||
|
var directory = Path.GetDirectoryName(lockFilePath);
|
||||||
|
|
||||||
|
var depsJsonFile = Directory
|
||||||
|
.EnumerateFiles(directory)
|
||||||
|
.FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson));
|
||||||
|
|
||||||
|
if (depsJsonFile != null)
|
||||||
|
{
|
||||||
|
File.Delete(depsJsonFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
|
||||||
|
|
||||||
|
depsJsonFile = Directory
|
||||||
|
.EnumerateFiles(directory)
|
||||||
|
.FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson));
|
||||||
|
|
||||||
|
depsJsonFile.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProjectToolsCommandResolver SetupProjectToolsCommandResolver(
|
private ProjectToolsCommandResolver SetupProjectToolsCommandResolver(
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"NETStandard.Library": "1.5.0-rc2-23911",
|
"NETStandard.Library": "1.5.0-rc2-23911",
|
||||||
|
"NuGet.Versioning": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.Packaging": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.Frameworks": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.ProjectModel": "3.4.0-rtm-0763",
|
||||||
|
|
||||||
"Microsoft.DotNet.ProjectModel": {
|
"Microsoft.DotNet.ProjectModel": {
|
||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.TestFramework;
|
using Microsoft.DotNet.TestFramework;
|
||||||
|
using Microsoft.DotNet.ProjectModel;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
{
|
{
|
||||||
|
@ -107,10 +108,20 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
string expectedOutput)
|
string expectedOutput)
|
||||||
{
|
{
|
||||||
var executablePath = Path.Combine(outputDir, executableName);
|
var executablePath = Path.Combine(outputDir, executableName);
|
||||||
|
var args = new List<string>();
|
||||||
|
|
||||||
|
if (IsPortable(executablePath))
|
||||||
|
{
|
||||||
|
args.Add("exec");
|
||||||
|
args.Add(ArgumentEscaper.EscapeSingleArg(executablePath));
|
||||||
|
|
||||||
|
var muxer = new Muxer();
|
||||||
|
executablePath = muxer.MuxerPath;
|
||||||
|
}
|
||||||
|
|
||||||
var executableCommand = new TestCommand(executablePath);
|
var executableCommand = new TestCommand(executablePath);
|
||||||
|
|
||||||
var result = executableCommand.ExecuteWithCapturedOutput("");
|
var result = executableCommand.ExecuteWithCapturedOutput(string.Join(" ", args));
|
||||||
|
|
||||||
result.Should().HaveStdOut(expectedOutput);
|
result.Should().HaveStdOut(expectedOutput);
|
||||||
result.Should().NotHaveStdErr();
|
result.Should().NotHaveStdErr();
|
||||||
|
@ -141,5 +152,22 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
|
|
||||||
return executablePath;
|
return executablePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsPortable(string executablePath)
|
||||||
|
{
|
||||||
|
var commandDir = Path.GetDirectoryName(executablePath);
|
||||||
|
|
||||||
|
var runtimeConfigPath = Directory.EnumerateFiles(commandDir)
|
||||||
|
.FirstOrDefault(x => x.EndsWith("runtimeconfig.json"));
|
||||||
|
|
||||||
|
if (runtimeConfigPath == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var runtimeConfig = new RuntimeConfig(runtimeConfigPath);
|
||||||
|
Console.WriteLine(runtimeConfig.Framework);
|
||||||
|
return runtimeConfig.IsPortable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"dotnet-test-xunit": "1.0.0-dev-91790-12",
|
"dotnet-test-xunit": "1.0.0-dev-91790-12",
|
||||||
"Microsoft.DotNet.TestFramework": "1.0.0-*",
|
"Microsoft.DotNet.TestFramework": "1.0.0-*",
|
||||||
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
|
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
|
||||||
|
"Microsoft.DotNet.ProjectModel": "1.0.0-*",
|
||||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537",
|
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537",
|
||||||
"Microsoft.DotNet.InternalAbstractions": {
|
"Microsoft.DotNet.InternalAbstractions": {
|
||||||
"target": "project",
|
"target": "project",
|
||||||
|
|
|
@ -36,9 +36,9 @@ namespace Microsoft.DotNet.Tests
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();
|
CommandResult result = new PortableCommand().ExecuteWithCapturedOutput();
|
||||||
|
|
||||||
result.Should().HaveStdOut("Hello World!" + Environment.NewLine);
|
result.Should().HaveStdOut("Hello Portable World!" + Environment.NewLine);
|
||||||
result.Should().NotHaveStdErr();
|
result.Should().NotHaveStdErr();
|
||||||
result.Should().Pass();
|
result.Should().Pass();
|
||||||
}
|
}
|
||||||
|
@ -94,5 +94,25 @@ namespace Microsoft.DotNet.Tests
|
||||||
return base.ExecuteWithCapturedOutput(args);
|
return base.ExecuteWithCapturedOutput(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PortableCommand : TestCommand
|
||||||
|
{
|
||||||
|
public PortableCommand()
|
||||||
|
: base("dotnet")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override CommandResult Execute(string args = "")
|
||||||
|
{
|
||||||
|
args = $"portable {args}";
|
||||||
|
return base.Execute(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
||||||
|
{
|
||||||
|
args = $"portable {args}";
|
||||||
|
return base.ExecuteWithCapturedOutput(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue