diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 267d52e5c..346d856f5 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -70,6 +70,7 @@ EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.DependencyModel", "src\Microsoft.Extensions.DependencyModel\Microsoft.Extensions.DependencyModel.xproj", "{688870C8-9843-4F9E-8576-D39290AD0F25}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Tools.Compiler.Fsc", "src\Microsoft.DotNet.Tools.Compiler.Fsc\Microsoft.DotNet.Tools.Compiler.Fsc.xproj", "{74F25188-BF63-4BF3-879B-B6CDB11ED608}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "E2E", "test\E2E\E2E.xproj", "{65741CB1-8AEE-4C66-8198-10A7EA0E4258}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -547,6 +548,22 @@ Global {11C77123-E4DA-499F-8900-80C88C2C69F2}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {11C77123-E4DA-499F-8900-80C88C2C69F2}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {11C77123-E4DA-499F-8900-80C88C2C69F2}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.Debug|Any CPU.Build.0 = Debug|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.Debug|x64.ActiveCfg = Debug|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.Debug|x64.Build.0 = Debug|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.Release|Any CPU.ActiveCfg = Release|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.Release|Any CPU.Build.0 = Release|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.Release|x64.ActiveCfg = Release|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.Release|x64.Build.0 = Release|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {65741CB1-8AEE-4C66-8198-10A7EA0E4258}.RelWithDebInfo|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -581,5 +598,6 @@ Global {79620410-4EC7-4A38-A8C3-EE81243F818E} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {1EA9AF94-5494-40DD-A05B-9D564572CCFC} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {11C77123-E4DA-499F-8900-80C88C2C69F2} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} + {65741CB1-8AEE-4C66-8198-10A7EA0E4258} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} EndGlobalSection EndGlobal diff --git a/scripts/build/build.ps1 b/scripts/build/build.ps1 index bded1fa21..aab9ce34a 100644 --- a/scripts/build/build.ps1 +++ b/scripts/build/build.ps1 @@ -33,6 +33,10 @@ else { header "Compiling" _ "$RepoRoot\scripts\compile\compile.ps1" @("$Configuration") +# Put stage2 on the PATH now that we have a build +$env:PATH = "$Stage2Dir\bin;$env:PATH" +$env:DOTNET_HOME = "$Stage2Dir" + header "Running Tests" _ "$RepoRoot\scripts\test\runtests.ps1" @@ -46,4 +50,4 @@ header "Generating dotnet MSI" _ "$RepoRoot\packaging\windows\generatemsi.ps1" @("$Stage2Dir") header "Generating NuGet packages" -_ "$RepoRoot\packaging\nuget\package.ps1" @("$Stage2Dir\bin", "$VersionSuffix") \ No newline at end of file +_ "$RepoRoot\packaging\nuget\package.ps1" @("$Stage2Dir\bin", "$VersionSuffix") diff --git a/scripts/build/build.sh b/scripts/build/build.sh index e87abc6a8..c5aa57a2a 100755 --- a/scripts/build/build.sh +++ b/scripts/build/build.sh @@ -37,7 +37,10 @@ fi header "Compiling" $REPOROOT/scripts/compile/compile.sh -# Run tests on the stage2 output +# Put stage2 on the PATH now that we have a build +export DOTNET_TOOLS=$STAGE1_DIR +export PATH=$STAGE2_DIR/bin:$PATH + header "Testing stage2..." DOTNET_HOME=$STAGE2_DIR DOTNET_TOOLS=$STAGE2_DIR $REPOROOT/scripts/test/runtests.sh @@ -52,4 +55,4 @@ if [ ! -z "$NOPACKAGE" ]; then $REPOROOT/scripts/package/package-native.sh else header "Skipping packaging" -fi \ No newline at end of file +fi diff --git a/scripts/build/restore-packages.sh b/scripts/build/restore-packages.sh index 1a1125f30..585e9b6b1 100755 --- a/scripts/build/restore-packages.sh +++ b/scripts/build/restore-packages.sh @@ -17,9 +17,11 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" source "$DIR/../common/_common.sh" header "Restoring packages" -$DNX_ROOT/dnu restore "$REPOROOT/src" --quiet --runtime "$RID" "$NOCACHE" --parallel -$DNX_ROOT/dnu restore "$REPOROOT/test" --quiet --runtime "$RID" "$NOCACHE" --parallel -$DNX_ROOT/dnu restore "$REPOROOT/tools" --quiet --runtime "$RID" "$NOCACHE" --parallel + +#Temporarily restore for ALL THE RIDS! This solves a bootstrapping problem in this fix +$DNX_ROOT/dnu restore "$REPOROOT/src" --quiet --runtime win7-x64 --runtime ubuntu.14.04-x64 --runtime osx.10.10-x64 --runtime osx.10.11-x64 --runtime centos.7.1-x64 "$NOCACHE" --parallel +$DNX_ROOT/dnu restore "$REPOROOT/test" --quiet --runtime win7-x64 --runtime ubuntu.14.04-x64 --runtime osx.10.10-x64 --runtime osx.10.11-x64 --runtime centos.7.1-x64 "$NOCACHE" --parallel +$DNX_ROOT/dnu restore "$REPOROOT/tools" --quiet --runtime win7-x64 --runtime ubuntu.14.04-x64 --runtime osx.10.10-x64 --runtime osx.10.11-x64 --runtime centos.7.1-x64 "$NOCACHE" --parallel set +e -$DNX_ROOT/dnu restore "$REPOROOT/testapp" --quiet --runtime "$RID" "$NOCACHE" --parallel >/dev/null 2>&1 +$DNX_ROOT/dnu restore "$REPOROOT/testapp" --quiet --runtime win7-x64 --runtime ubuntu.14.04-x64 --runtime osx.10.10-x64 --runtime osx.10.11-x64 --runtime centos.7.1-x64 "$NOCACHE" --parallel >/dev/null 2>&1 set -e diff --git a/scripts/common/_rid.sh b/scripts/common/_rid.sh index fc331a82b..cabea0a73 100644 --- a/scripts/common/_rid.sh +++ b/scripts/common/_rid.sh @@ -12,7 +12,7 @@ if [ -z "$RID" ]; then if [ -n "$(sw_vers -productVersion | grep 10.10)" ]; then export RID=osx.10.10-x64 elif [ -n "$(sw_vers -productVersion | grep 10.11)" ]; then - export RID=osx.10.10-x64 + export RID=osx.10.11-x64 else error "unknown OS X: $(sw_vers -productVersion)" 1>&2 fi @@ -34,4 +34,4 @@ fi if [ -z "$RID" ]; then exit 1 -fi \ No newline at end of file +fi diff --git a/scripts/crossgen/crossgen_roslyn.sh b/scripts/crossgen/crossgen_roslyn.sh index 61880f44b..7c74c2fcb 100755 --- a/scripts/crossgen/crossgen_roslyn.sh +++ b/scripts/crossgen/crossgen_roslyn.sh @@ -10,15 +10,14 @@ BIN_DIR="$( cd $1 && pwd )" UNAME=`uname` -if [ -z "$RID" ]; then - if [ "$UNAME" == "Darwin" ]; then - RID=osx.10.10-x64 - elif [ "$UNAME" == "Linux" ]; then - RID=ubuntu.14.04-x64 - else - echo "Unknown OS: $UNAME" 1>&2 - exit 1 - fi +# Always recalculate the RID because the package always uses a specific RID, regardless of OS X version or Linux distro. +if [ "$UNAME" == "Darwin" ]; then + RID=osx.10.10-x64 +elif [ "$UNAME" == "Linux" ]; then + RID=ubuntu.14.04-x64 +else + echo "Unknown OS: $UNAME" 1>&2 + exit 1 fi # Replace with a robust method for finding the right crossgen.exe diff --git a/scripts/test/runtests.ps1 b/scripts/test/runtests.ps1 index 74a6e4b79..9eea6d83f 100644 --- a/scripts/test/runtests.ps1 +++ b/scripts/test/runtests.ps1 @@ -5,6 +5,8 @@ . "$PSScriptRoot\..\common\_common.ps1" +$failCount = 0 + $TestBinRoot = "$RepoRoot\artifacts\tests" $TestProjects = @( @@ -45,7 +47,7 @@ pushd "$TestBinRoot" # Run each test project $TestProjects | ForEach-Object { - & "corerun.exe" "xunit.console.netcore.exe" "$_.dll" -xml "$_-testResults.xml" -notrait category=failing + & ".\corerun" "xunit.console.netcore.exe" "$_.dll" -xml "$_-testResults.xml" -notrait category=failing $exitCode = $LastExitCode if ($exitCode -ne 0) { $failingTests += "$_" @@ -61,8 +63,7 @@ if ($failCount -ne 0) { $failingTests | ForEach-Object { Write-Host -ForegroundColor Red "$_.dll failed. Logs in '$TestBinRoot\$_-testResults.xml'" } -} -else { +} else { Write-Host -ForegroundColor Green "All the tests passed!" } diff --git a/scripts/test/runtests.sh b/scripts/test/runtests.sh index ed6a5970c..cb211f59a 100755 --- a/scripts/test/runtests.sh +++ b/scripts/test/runtests.sh @@ -24,7 +24,6 @@ TestProjects=( \ Microsoft.DotNet.Tools.Publish.Tests \ ) - for project in ${TestProjects[@]} do dotnet publish --framework "dnxcore50" --runtime "$RID" --output "$TestBinRoot" --configuration "$CONFIGURATION" "$REPOROOT/test/$project" @@ -43,7 +42,7 @@ failCount=0 for project in ${TestProjects[@]} do - ./corerun "xunit.console.netcore.exe" "$project.dll" -xml "${project}-testResults.xml" -notrait category=failing + ./corerun "xunit.console.netcore.exe" "$project.dll" -xml "${project}-testResults.xml" -notrait category=failing exitCode=$? failCount+=$exitCode if [ $exitCode -ne 0 ]; then diff --git a/src/Microsoft.DotNet.Cli.Utils/RuntimeEnvironmentRidExtensions.cs b/src/Microsoft.DotNet.Cli.Utils/RuntimeEnvironmentRidExtensions.cs new file mode 100644 index 000000000..b27738a15 --- /dev/null +++ b/src/Microsoft.DotNet.Cli.Utils/RuntimeEnvironmentRidExtensions.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; + +namespace Microsoft.Extensions.PlatformAbstractions +{ + // This is to support some legacy stuff. + // dnu restore (and thus dotnet restore) always uses win7-x64 as the Windows restore target, + // so, when picking targets out of the lock file, we need to do version fallback since the + // active RID might be higher than the RID in the lock file. + // + // We should clean this up. Filed #619 to track. + public static class RuntimeEnvironmentRidExtensions + { + // Gets the identfier that is used for restore by default (this is different from the actual RID, but only on Windows) + public static string GetLegacyRestoreRuntimeIdentifier(this IRuntimeEnvironment env) + { + if (env.OperatingSystemPlatform != Platform.Windows) + { + return env.GetRuntimeIdentifier(); + } + else + { + var arch = env.RuntimeArchitecture.ToLowerInvariant(); + return "win7-" + arch; + } + } + + public static IEnumerable GetAllCandidateRuntimeIdentifiers(this IRuntimeEnvironment env) + { + if (env.OperatingSystemPlatform != Platform.Windows) + { + yield return env.GetRuntimeIdentifier(); + } + else + { + var arch = env.RuntimeArchitecture.ToLowerInvariant(); + if (env.OperatingSystemVersion.StartsWith("6.1", StringComparison.Ordinal)) + { + yield return "win7-" + arch; + } + else if (env.OperatingSystemVersion.StartsWith("6.2", StringComparison.Ordinal)) + { + yield return "win8-" + arch; + yield return "win7-" + arch; + } + else if (env.OperatingSystemVersion.StartsWith("6.3", StringComparison.Ordinal)) + { + yield return "win81-" + arch; + yield return "win8-" + arch; + yield return "win7-" + arch; + } + else if (env.OperatingSystemVersion.StartsWith("10.0", StringComparison.Ordinal)) + { + yield return "win10-" + arch; + yield return "win81-" + arch; + yield return "win8-" + arch; + yield return "win7-" + arch; + } + } + } + } +} diff --git a/src/Microsoft.DotNet.Cli.Utils/project.json b/src/Microsoft.DotNet.Cli.Utils/project.json index 8f6325f17..0f5b0038e 100644 --- a/src/Microsoft.DotNet.Cli.Utils/project.json +++ b/src/Microsoft.DotNet.Cli.Utils/project.json @@ -1,13 +1,14 @@ { - "version": "1.0.0-*", - - "dependencies": { - "NETStandard.Library": "1.0.0-rc2-23704", - "Microsoft.DotNet.ProjectModel": "1.0.0", - "System.Reflection.Metadata": "1.1.0" - }, - - "frameworks": { - "dnxcore50": { } - } + "version": "1.0.0-*", + + "dependencies": { + "NETStandard.Library": "1.0.0-rc2-23704", + "Microsoft.DotNet.ProjectModel": "1.0.0", + "System.Reflection.Metadata": "1.1.0", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16530" + }, + + "frameworks": { + "dnxcore50": { } + } } diff --git a/src/Microsoft.DotNet.Cli/Program.cs b/src/Microsoft.DotNet.Cli/Program.cs index 3dbc33f53..b648af763 100644 --- a/src/Microsoft.DotNet.Cli/Program.cs +++ b/src/Microsoft.DotNet.Cli/Program.cs @@ -4,15 +4,17 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using Microsoft.DotNet.Cli.Utils; +using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace Microsoft.DotNet.Cli { public class Program { - private const string HelpText = @".NET Command Line Interface -Usage: dotnet [common-options] [command] [arguments] + private const string ProductLongName = ".NET Command Line Tools"; + private const string UsageText = @"Usage: dotnet [common-options] [command] [arguments] Arguments: [command] The command to execute @@ -20,6 +22,7 @@ Arguments: Common Options (passed before the command): -v|--verbose Enable verbose output + --version Display .NET CLI Version Info Common Commands: new Initialize a basic .NET project @@ -29,6 +32,13 @@ Common Commands: run Compiles and immediately executes a .NET project repl Launch an interactive session (read, eval, print, loop) pack Creates a NuGet package"; + private static readonly string ProductVersion = GetProductVersion(); + + private static string GetProductVersion() + { + var attr = typeof(Program).GetTypeInfo().Assembly.GetCustomAttribute(); + return attr?.InformationalVersion; + } public static int Main(string[] args) { @@ -45,6 +55,11 @@ Common Commands: { verbose = true; } + else if(IsArg(args[lastArg], "version")) + { + PrintVersionInfo(); + return 0; + } else if (IsArg(args[lastArg], "h", "help")) { PrintHelp(); @@ -102,12 +117,38 @@ Common Commands: private static void PrintHelp() { - Reporter.Output.WriteLine(HelpText); + PrintVersionHeader(); + Reporter.Output.WriteLine(UsageText); + } + + private static void PrintVersionHeader() + { + var versionString = string.IsNullOrEmpty(ProductVersion) ? + string.Empty : + $" ({ProductVersion})"; + Reporter.Output.WriteLine(ProductLongName + versionString); + } + + private static void PrintVersionInfo() + { + PrintVersionHeader(); + + var runtimeEnvironment = PlatformServices.Default.Runtime; + Reporter.Output.WriteLine("Runtime Environment:"); + Reporter.Output.WriteLine($" OS Name: {runtimeEnvironment.OperatingSystem}"); + Reporter.Output.WriteLine($" OS Version: {runtimeEnvironment.OperatingSystemVersion}"); + Reporter.Output.WriteLine($" OS Platform: {runtimeEnvironment.OperatingSystemPlatform}"); + Reporter.Output.WriteLine($" Runtime Id: {runtimeEnvironment.GetRuntimeIdentifier()}"); + } + + private static bool IsArg(string candidate, string longName) + { + return IsArg(candidate, shortName: null, longName: longName); } private static bool IsArg(string candidate, string shortName, string longName) { - return candidate.Equals("-" + shortName) || candidate.Equals("--" + longName); + return (shortName != null && candidate.Equals("-" + shortName)) || (longName != null && candidate.Equals("--" + longName)); } } } diff --git a/src/Microsoft.DotNet.ProjectModel/RuntimeIdentifier.cs b/src/Microsoft.DotNet.ProjectModel/RuntimeIdentifier.cs deleted file mode 100644 index ab49b2977..000000000 --- a/src/Microsoft.DotNet.ProjectModel/RuntimeIdentifier.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.IO; -using System.Runtime.InteropServices; - -namespace Microsoft.DotNet.ProjectModel -{ - public static class RuntimeIdentifier - { - public static string Current { get; } = DetermineRID(); - - private static string DetermineRID() - { - // TODO: Not this, obviously. Do proper RID detection - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return "win7-x64"; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - if(IsCentOS()) - { - return "centos.7-x64"; - } - else if(IsUbuntu()) - { - return "ubuntu.14.04-x64"; - } - else - { - // unknown distro. Lets fail fast - throw new InvalidOperationException("Current linux distro is not supported."); - } - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return "osx.10.10-x64"; - } - - throw new InvalidOperationException("Current operating system is not supported."); - } - - private static bool IsCentOS() - { - return IsLinuxDistro("centos"); - } - - private static bool IsUbuntu() - { - return IsLinuxDistro("ubuntu"); - } - - private static bool IsLinuxDistro(string distro) - { - // HACK - A file which can be found in most linux distros - // Did not test in non-en distros - const string OSIDFILE = "/etc/os-release"; - - if(!File.Exists(OSIDFILE)) - { - return false; - } - - return File.ReadAllText(OSIDFILE).ToLower().Contains(distro); - } - } -} diff --git a/src/Microsoft.DotNet.Tools.Compiler/Program.cs b/src/Microsoft.DotNet.Tools.Compiler/Program.cs index 42a56a51f..238f5839d 100644 --- a/src/Microsoft.DotNet.Tools.Compiler/Program.cs +++ b/src/Microsoft.DotNet.Tools.Compiler/Program.cs @@ -13,6 +13,7 @@ using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Utilities; using NuGet.Frameworks; using Microsoft.Extensions.DependencyModel; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Compiler { @@ -344,8 +345,9 @@ namespace Microsoft.DotNet.Tools.Compiler if (success && !args.NoHostValue && compilationOptions.EmitEntryPoint.GetValueOrDefault()) { - var projectContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, new[] { RuntimeIdentifier.Current }); - projectContext + var rids = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); + var runtimeContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, rids); + runtimeContext .MakeCompilationOutputRunnable(outputPath, args.ConfigValue); } diff --git a/src/Microsoft.DotNet.Tools.Compiler/project.json b/src/Microsoft.DotNet.Tools.Compiler/project.json index 8cc9e032d..5a6f19797 100644 --- a/src/Microsoft.DotNet.Tools.Compiler/project.json +++ b/src/Microsoft.DotNet.Tools.Compiler/project.json @@ -1,31 +1,33 @@ { - "name": "dotnet-compile", - "version": "1.0.0-*", - "compilationOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "NETStandard.Library": "1.0.0-rc2-23704", - "System.Reflection.Metadata": "1.1.0", - "Microsoft.DotNet.ProjectModel": "1.0.0-*", - "Microsoft.DotNet.Compiler.Common": "1.0.0-*", - "Microsoft.DotNet.Cli.Utils": "1.0.0-*", - "Microsoft.Extensions.CommandLineUtils.Sources": { - "type": "build", - "version": "1.0.0-*" + "name": "dotnet-compile", + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true }, - "Microsoft.Extensions.DependencyModel": { - "type": "build", - "version": "1.0.0-*" + "dependencies": { + "NETStandard.Library": "1.0.0-rc2-23704", + "System.Reflection.Metadata": "1.1.0", + "Microsoft.DotNet.ProjectModel": "1.0.0-*", + "Microsoft.DotNet.Compiler.Common": "1.0.0-*", + "Microsoft.DotNet.Cli.Utils": "1.0.0-*", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", + + "Microsoft.Extensions.CommandLineUtils.Sources": { + "type": "build", + "version": "1.0.0-*" + }, + "Microsoft.Extensions.DependencyModel": { + "type": "build", + "version": "1.0.0-*" + } + }, + "frameworks": { + "dnxcore50": { } + }, + "scripts": { + "postcompile": [ + "../../scripts/build/place-binary \"%compile:OutputDir%/%project:Name%.dll\"", + "../../scripts/build/place-binary \"%compile:OutputDir%/%project:Name%.pdb\"" + ] } - }, - "frameworks": { - "dnxcore50": { } - }, - "scripts": { - "postcompile": [ - "../../scripts/build/place-binary \"%compile:OutputDir%/%project:Name%.dll\"", - "../../scripts/build/place-binary \"%compile:OutputDir%/%project:Name%.pdb\"" - ] - } } diff --git a/src/Microsoft.DotNet.Tools.Publish/Program.cs b/src/Microsoft.DotNet.Tools.Publish/Program.cs index b6dd956d1..219371cce 100644 --- a/src/Microsoft.DotNet.Tools.Publish/Program.cs +++ b/src/Microsoft.DotNet.Tools.Publish/Program.cs @@ -6,6 +6,7 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using System; using System.IO; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Publish { @@ -33,8 +34,7 @@ namespace Microsoft.DotNet.Tools.Publish var publish = new PublishCommand(); publish.Framework = framework.Value(); - // TODO: Remove default once xplat publish is enabled. - publish.Runtime = runtime.Value() ?? RuntimeIdentifier.Current; + publish.Runtime = runtime.Value(); publish.OutputPath = output.Value(); publish.Configuration = configuration.Value() ?? Constants.DefaultConfiguration; publish.NativeSubdirectories = nativeSubdirectories.HasValue(); diff --git a/src/Microsoft.DotNet.Tools.Publish/PublishCommand.cs b/src/Microsoft.DotNet.Tools.Publish/PublishCommand.cs index 0ff7ff2c3..14784539d 100644 --- a/src/Microsoft.DotNet.Tools.Publish/PublishCommand.cs +++ b/src/Microsoft.DotNet.Tools.Publish/PublishCommand.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Publish { @@ -39,10 +40,8 @@ namespace Microsoft.DotNet.Tools.Publish } } - ProjectContexts = ProjectContext.CreateContextForEachTarget(ProjectPath); - ProjectContexts = GetMatchingProjectContexts(ProjectContexts, NugetFramework, Runtime); - - if (ProjectContexts.Count() == 0) + ProjectContexts = SelectContexts(ProjectPath, NugetFramework, Runtime); + if (!ProjectContexts.Any()) { string errMsg = $"'{ProjectPath}' cannot be published for '{Framework ?? ""}' '{Runtime ?? ""}'"; Reporter.Output.WriteLine(errMsg.Red()); @@ -67,29 +66,6 @@ namespace Microsoft.DotNet.Tools.Publish } } - /// - /// Return the matching framework/runtime ProjectContext. - /// If 'nugetframework' or 'runtime' is null or empty then it matches with any. - /// - private static IEnumerable GetMatchingProjectContexts(IEnumerable contexts, NuGetFramework framework, string runtimeIdentifier) - { - foreach (var context in contexts) - { - if (context.TargetFramework == null || string.IsNullOrEmpty(context.RuntimeIdentifier)) - { - continue; - } - - if (string.IsNullOrEmpty(runtimeIdentifier) || runtimeIdentifier.Equals(context.RuntimeIdentifier)) - { - if (framework == null || framework.Equals(context.TargetFramework)) - { - yield return context; - } - } - } - } - /// /// Publish the project for given 'framework (ex - dnxcore50)' and 'runtimeID (ex - win7-x64)' /// @@ -228,5 +204,51 @@ namespace Microsoft.DotNet.Tools.Publish return candidate; } + + private static IEnumerable SelectContexts(string projectPath, NuGetFramework framework, string runtime) + { + var allContexts = ProjectContext.CreateContextForEachTarget(projectPath); + if (string.IsNullOrEmpty(runtime)) + { + // Nothing was specified, so figure out what the candidate runtime identifiers are and try each of them + // Temporary until #619 is resolved + foreach (var candidate in PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()) + { + var contexts = GetMatchingProjectContexts(allContexts, framework, candidate); + if (contexts.Any()) + { + return contexts; + } + } + return Enumerable.Empty(); + } + else + { + return GetMatchingProjectContexts(allContexts, framework, runtime); + } + } + + /// + /// Return the matching framework/runtime ProjectContext. + /// If 'framework' or 'runtimeIdentifier' is null or empty then it matches with any. + /// + private static IEnumerable GetMatchingProjectContexts(IEnumerable contexts, NuGetFramework framework, string runtimeIdentifier) + { + foreach (var context in contexts) + { + if (context.TargetFramework == null || string.IsNullOrEmpty(context.RuntimeIdentifier)) + { + continue; + } + + if (string.IsNullOrEmpty(runtimeIdentifier) || string.Equals(runtimeIdentifier, context.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase)) + { + if (framework == null || framework.Equals(context.TargetFramework)) + { + yield return context; + } + } + } + } } } diff --git a/src/dotnet-restore/Program.cs b/src/dotnet-restore/Program.cs index 3bf3173fa..8e66812b7 100644 --- a/src/dotnet-restore/Program.cs +++ b/src/dotnet-restore/Program.cs @@ -12,11 +12,14 @@ using Microsoft.Dnx.Runtime.Common.CommandLine; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Restore { public class Program { + private static readonly string DefaultRid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + public static int Main(string[] args) { DebugHelper.HandleDebugSwitch(ref args); @@ -130,7 +133,7 @@ namespace Microsoft.DotNet.Tools.Restore private static void CreateDepsInPackageCache(LibraryRange toolLibrary, string projectPath) { var context = ProjectContext.Create(projectPath, - FrameworkConstants.CommonFrameworks.DnxCore50, new[] { RuntimeIdentifier.Current }); + FrameworkConstants.CommonFrameworks.DnxCore50, new[] { DefaultRid }); var toolDescription = context.LibraryManager.GetLibraries() .Select(l => l as PackageDescription) @@ -155,7 +158,7 @@ namespace Microsoft.DotNet.Tools.Restore var projectPath = Path.Combine(tempPath, Project.FileName); File.WriteAllText(projectPath, GenerateProjectJsonContents(new[] {"dnxcore50"})); Dnx.RunPackageInstall(tooldep, projectPath, args); - Dnx.RunRestore(new [] { $"\"{projectPath}\"", "--runtime", $"{RuntimeIdentifier.Current}"}.Concat(args)); + Dnx.RunRestore(new [] { $"\"{projectPath}\"", "--runtime", $"{DefaultRid}"}.Concat(args)); } private static string GenerateProjectJsonContents(IEnumerable frameworks = null) diff --git a/test/E2E/E2E.xproj b/test/E2E/E2E.xproj new file mode 100644 index 000000000..381c6d548 --- /dev/null +++ b/test/E2E/E2E.xproj @@ -0,0 +1,19 @@ + + + + 14.0.24720 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 65741cb1-8aee-4c66-8198-10a7ea0e4258 + E2E + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + \ No newline at end of file diff --git a/test/E2E/EndToEndTest.cs b/test/E2E/EndToEndTest.cs index 31abe2863..ad3addf7a 100644 --- a/test/E2E/EndToEndTest.cs +++ b/test/E2E/EndToEndTest.cs @@ -10,6 +10,7 @@ using Xunit; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tests.EndToEnd { @@ -33,7 +34,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd { TestSetup(); - Rid = RuntimeIdentifier.Current; + Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); } [Fact] diff --git a/test/E2E/project.json b/test/E2E/project.json index 2e21d6123..06ea2f81c 100644 --- a/test/E2E/project.json +++ b/test/E2E/project.json @@ -14,7 +14,6 @@ "Microsoft.DotNet.ProjectModel": { "target": "project" }, "Microsoft.DotNet.Cli.Utils": { "target": "project" }, - "Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" } }, diff --git a/test/LoadContextTest/Program.cs b/test/LoadContextTest/Program.cs index 586dd61f5..467c6ac1d 100644 --- a/test/LoadContextTest/Program.cs +++ b/test/LoadContextTest/Program.cs @@ -3,6 +3,7 @@ using System.IO; using System.Reflection; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Loader; +using Microsoft.Extensions.PlatformAbstractions; using NuGet.Frameworks; namespace LoadContextTest @@ -23,7 +24,8 @@ namespace LoadContextTest // Load the project load context Console.WriteLine($"Creating load context for {project}"); - var context = ProjectContext.Create(project, FrameworkConstants.CommonFrameworks.DnxCore50, new[] { RuntimeIdentifier.Current }); + var rid = PlatformServices.Default.Runtime.GetRuntimeIdentifier(); + var context = ProjectContext.Create(project, FrameworkConstants.CommonFrameworks.DnxCore50, new[] { rid }); var loadContext = context.CreateLoadContext(); // Load the project assembly diff --git a/test/LoadContextTest/project.json b/test/LoadContextTest/project.json index bc73c2255..6eb893e33 100644 --- a/test/LoadContextTest/project.json +++ b/test/LoadContextTest/project.json @@ -13,6 +13,8 @@ "System.Linq": "4.0.1-beta-23516", "System.Threading": "4.0.11-beta-23516", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*", + "Microsoft.DotNet.ProjectModel.Loader": { "target": "project" } }, diff --git a/test/Microsoft.DotNet.Tools.Publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs b/test/Microsoft.DotNet.Tools.Publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs index 22e8d5d25..79c20cb38 100644 --- a/test/Microsoft.DotNet.Tools.Publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs +++ b/test/Microsoft.DotNet.Tools.Publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs @@ -9,6 +9,7 @@ using Xunit; using System.Linq; using System.Collections.Generic; using Microsoft.DotNet.ProjectModel; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Publish.Tests { @@ -24,11 +25,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { new object[] { "", "", "", "" }, new object[] { "dnxcore50", "", "", "" }, - new object[] { "", RuntimeIdentifier.Current, "", "" }, + new object[] { "", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "", "" }, new object[] { "", "", "Release", "" }, new object[] { "", "", "", "some/dir"}, //new object[] { "", "", "", "\"some/dir/with spaces\"" }, // issue - https://github.com/dotnet/cli/issues/525 - new object[] { "dnxcore50", RuntimeIdentifier.Current, "Debug", "some/dir" }, + new object[] { "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" }, }; } } diff --git a/test/Microsoft.DotNet.Tools.Publish.Tests/project.json b/test/Microsoft.DotNet.Tools.Publish.Tests/project.json index 5e3551d4d..9e294c795 100644 --- a/test/Microsoft.DotNet.Tools.Publish.Tests/project.json +++ b/test/Microsoft.DotNet.Tools.Publish.Tests/project.json @@ -10,8 +10,11 @@ "xunit.netcore.extensions": "1.0.0-prerelease-*", "xunit.runner.utility": "2.1.0", - "Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" } - + "Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" }, + "Microsoft.DotNet.Cli.Utils": { + "target": "project", + "type": "build" + } }, "frameworks": { diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs index 089583a79..d5a7157ab 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PublishCommand.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; +using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Test.Utilities { @@ -55,7 +56,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities string config = string.IsNullOrEmpty(_config) ? "Debug" : _config; string framework = string.IsNullOrEmpty(_framework) ? _project.GetTargetFrameworks().First().FrameworkName.GetShortFolderName() : _framework; - string runtime = string.IsNullOrEmpty(_runtime) ? RuntimeIdentifier.Current : _runtime; + string runtime = string.IsNullOrEmpty(_runtime) ? PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier() : _runtime; string output = Path.Combine("bin", config, framework, runtime); return output;