diff --git a/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs b/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs index e28496247..7132633e4 100644 --- a/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs +++ b/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs @@ -23,6 +23,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common public static void MakeCompilationOutputRunnable(this ProjectContext context, string outputPath, string configuration) { + // REVIEW: This shouldn't be copied on compile context .ProjectFile .Files @@ -34,21 +35,28 @@ namespace Microsoft.DotNet.Cli.Compiler.Common if (context.TargetFramework.IsDesktop()) { + // On full framework, copy all dependencies to the output path exporter .GetDependencies() .SelectMany(e => e.RuntimeAssets()) .CopyTo(outputPath); + + // Generate binding redirects + var outputName = context.GetOutputPathCalculator(outputPath).GetAssemblyPath(configuration); + context.GenerateBindingRedirects(exporter, outputName); } else { exporter .GetDependencies(LibraryType.Package) .WriteDepsTo(Path.Combine(outputPath, context.ProjectFile.Name + FileNameSuffixes.Deps)); - + + // On core clr, only copy project references exporter.GetDependencies(LibraryType.Project) .SelectMany(e => e.RuntimeAssets()) .CopyTo(outputPath); + // TODO: Pick a host based on the RID CoreHost.CopyTo(outputPath, context.ProjectFile.Name + Constants.ExeSuffix); } } diff --git a/src/dotnet-build/CompileContext.cs b/src/dotnet-build/CompileContext.cs index 519a0d012..3eba3d4ef 100644 --- a/src/dotnet-build/CompileContext.cs +++ b/src/dotnet-build/CompileContext.cs @@ -274,15 +274,17 @@ namespace Microsoft.DotNet.Tools.Build args.Add("--framework"); args.Add($"{projectDependency.Framework}"); + + if (!string.IsNullOrEmpty(_args.RuntimeValue)) + { + args.Add("--runtime"); + args.Add(_args.RuntimeValue); + } + args.Add("--configuration"); args.Add(_args.ConfigValue); args.Add(projectDependency.Project.ProjectDirectory); - - if (_args.NoHostValue) - { - args.Add("--no-host"); - } - + var compileResult = Command.Create("dotnet-compile", args) .ForwardStdOut() .ForwardStdErr() @@ -297,6 +299,11 @@ namespace Microsoft.DotNet.Tools.Build var args = new List(); args.Add("--framework"); args.Add(_rootProject.TargetFramework.ToString()); + if (!string.IsNullOrEmpty(_args.RuntimeValue)) + { + args.Add("--runtime"); + args.Add(_args.RuntimeValue); + } args.Add("--configuration"); args.Add(_args.ConfigValue); args.Add("--output"); @@ -304,11 +311,6 @@ namespace Microsoft.DotNet.Tools.Build args.Add("--temp-output"); args.Add(_args.IntermediateValue); - if (_args.NoHostValue) - { - args.Add("--no-host"); - } - //native args if (_args.IsNativeValue) { diff --git a/src/dotnet-compile/CompilerCommandApp.cs b/src/dotnet-compile/CompilerCommandApp.cs index 5fde9c822..a181a8bce 100644 --- a/src/dotnet-compile/CompilerCommandApp.cs +++ b/src/dotnet-compile/CompilerCommandApp.cs @@ -23,8 +23,8 @@ namespace Microsoft.DotNet.Tools.Compiler private CommandOption _outputOption; private CommandOption _intermediateOutputOption; private CommandOption _frameworkOption; + private CommandOption _runtimeOption; private CommandOption _configurationOption; - private CommandOption _noHostOption; private CommandArgument _projectArgument; private CommandOption _nativeOption; private CommandOption _archOption; @@ -39,8 +39,8 @@ namespace Microsoft.DotNet.Tools.Compiler public string ProjectPathValue { get; set; } public string OutputValue { get; set; } public string IntermediateValue { get; set; } + public string RuntimeValue{ get; set; } public string ConfigValue { get; set; } - public bool NoHostValue { get; set; } public bool IsNativeValue { get; set; } public string ArchValue { get; set; } public string IlcArgsValue { get; set; } @@ -75,7 +75,7 @@ namespace Microsoft.DotNet.Tools.Compiler _intermediateOutputOption = _app.Option("-t|--temp-output ", "Directory in which to place temporary outputs", CommandOptionType.SingleValue); _frameworkOption = _app.Option("-f|--framework ", "Compile a specific framework", CommandOptionType.MultipleValue); _configurationOption = _app.Option("-c|--configuration ", "Configuration under which to build", CommandOptionType.SingleValue); - _noHostOption = _app.Option("--no-host", "Set this to skip publishing a runtime host when building for CoreCLR", CommandOptionType.NoValue); + _runtimeOption = _app.Option("-r|--runtime ", "Target runtime to publish for", CommandOptionType.SingleValue); _projectArgument = _app.Argument("", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory"); // Native Args @@ -103,7 +103,7 @@ namespace Microsoft.DotNet.Tools.Compiler OutputValue = _outputOption.Value(); IntermediateValue = _intermediateOutputOption.Value(); ConfigValue = _configurationOption.Value() ?? Constants.DefaultConfiguration; - NoHostValue = _noHostOption.HasValue(); + RuntimeValue = _runtimeOption.Value(); IsNativeValue = _nativeOption.HasValue(); ArchValue = _archOption.Value(); diff --git a/src/dotnet-compile/Program.cs b/src/dotnet-compile/Program.cs index cdbd9ec57..41cb9699f 100644 --- a/src/dotnet-compile/Program.cs +++ b/src/dotnet-compile/Program.cs @@ -10,9 +10,7 @@ using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Utilities; -using NuGet.Frameworks; using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.PlatformAbstractions; @@ -318,35 +316,28 @@ namespace Microsoft.DotNet.Tools.Compiler success &= GenerateCultureResourceAssemblies(context.ProjectFile, dependencies, outputPath); } - bool generateBindingRedirects = false; - if (success && !args.NoHostValue && compilationOptions.EmitEntryPoint.GetValueOrDefault()) + if (success) { - generateBindingRedirects = true; - var rids = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers(); - var runtimeContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, rids); - runtimeContext - .MakeCompilationOutputRunnable(outputPath, args.ConfigValue); - } - else if (!string.IsNullOrEmpty(context.ProjectFile.TestRunner)) - { - generateBindingRedirects = true; - var projectContext = - ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, - new[] { PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier() }); + // TODO: Make this opt in via another mechanism + var makeRunnable = compilationOptions.EmitEntryPoint.GetValueOrDefault() || + !string.IsNullOrEmpty(context.ProjectFile.TestRunner); - // Don't generate a deps file if we're on desktop - if (!context.TargetFramework.IsDesktop()) + if (makeRunnable) { - projectContext - .CreateExporter(args.ConfigValue) - .GetDependencies(LibraryType.Package) - .WriteDepsTo(Path.Combine(outputPath, projectContext.ProjectFile.Name + FileNameSuffixes.Deps)); - } - } + var rids = new List(); + if (string.IsNullOrEmpty(args.RuntimeValue)) + { + rids.AddRange(PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers()); + } + else + { + rids.Add(args.RuntimeValue); + } - if (generateBindingRedirects && context.TargetFramework.IsDesktop()) - { - context.GenerateBindingRedirects(exporter, outputName); + var runtimeContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, rids); + runtimeContext + .MakeCompilationOutputRunnable(outputPath, args.ConfigValue); + } } return PrintSummary(diagnostics, sw, success); diff --git a/src/dotnet-publish/Program.cs b/src/dotnet-publish/Program.cs index 219371cce..72aabd21a 100644 --- a/src/dotnet-publish/Program.cs +++ b/src/dotnet-publish/Program.cs @@ -3,10 +3,8 @@ using Microsoft.Dnx.Runtime.Common.CommandLine; using Microsoft.DotNet.Cli.Utils; -using Microsoft.DotNet.ProjectModel; using System; using System.IO; -using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.DotNet.Tools.Publish { diff --git a/src/dotnet-publish/PublishCommand.cs b/src/dotnet-publish/PublishCommand.cs index e2d2f0d67..562f4c11e 100644 --- a/src/dotnet-publish/PublishCommand.cs +++ b/src/dotnet-publish/PublishCommand.cs @@ -109,10 +109,11 @@ namespace Microsoft.DotNet.Tools.Publish new string[] { "--framework", $"{context.TargetFramework.DotNetFrameworkName}", + "--runtime", + context.RuntimeIdentifier, "--configuration", - $"{configuration}", - "--no-host", - $"{context.ProjectFile.ProjectDirectory}" + configuration, + context.ProjectFile.ProjectDirectory }) .ForwardStdErr() .ForwardStdOut()