Support publishing to .NET Framework

- Pick .exe or .dll based on emit entry point (true)
- Skip post publish fix up if the target application targets .NET Framework
This commit is contained in:
David Fowler 2015-10-20 04:35:40 -07:00
parent d42b38d8ff
commit 6da43b205d
3 changed files with 18 additions and 13 deletions

View file

@ -167,7 +167,7 @@ namespace Microsoft.DotNet.Tools.Compiler
// Get compilation options // Get compilation options
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration); var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
var outputName = Path.Combine(outputPath, context.ProjectFile.Name + ".dll"); var outputName = Path.Combine(outputPath, context.ProjectFile.Name + (compilationOptions.EmitEntryPoint.GetValueOrDefault() ? ".exe" : ".dll"));
var bootstrappingWithMono = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BOOTSTRAPPING_WITH_MONO")); var bootstrappingWithMono = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BOOTSTRAPPING_WITH_MONO"));

View file

@ -113,6 +113,10 @@ namespace Microsoft.DotNet.Tools.Publish
// Use a library exporter to collect publish assets // Use a library exporter to collect publish assets
var exporter = context.CreateExporter(configuration); var exporter = context.CreateExporter(configuration);
// Copy things marked as copy to output (which we don't have yet)
// so does copy too many things
CopyContents(context, outputPath);
foreach (var export in exporter.GetAllExports()) foreach (var export in exporter.GetAllExports())
{ {
Reporter.Output.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ..."); Reporter.Output.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
@ -123,7 +127,7 @@ namespace Microsoft.DotNet.Tools.Publish
// Publishing for windows, TODO(anurse): Publish for Mac/Linux/etc. // Publishing for windows, TODO(anurse): Publish for Mac/Linux/etc.
int exitCode; int exitCode;
if (context.RuntimeIdentifier.Equals("win7-x64")) if (context.RuntimeIdentifier.StartsWith("win"))
{ {
exitCode = PublishForWindows(context, outputPath); exitCode = PublishForWindows(context, outputPath);
} }
@ -132,8 +136,6 @@ namespace Microsoft.DotNet.Tools.Publish
exitCode = PublishForUnix(context, outputPath); exitCode = PublishForUnix(context, outputPath);
} }
CopyContents(context, outputPath);
Reporter.Output.WriteLine($"Published to {outputPath}".Green().Bold()); Reporter.Output.WriteLine($"Published to {outputPath}".Green().Bold());
return exitCode; return exitCode;
} }
@ -167,7 +169,6 @@ namespace Microsoft.DotNet.Tools.Publish
// Use the 'command' field to generate the name // Use the 'command' field to generate the name
var outputExe = Path.Combine(outputPath, context.ProjectFile.Name); var outputExe = Path.Combine(outputPath, context.ProjectFile.Name);
var outputDll = Path.Combine(outputPath, context.ProjectFile.Name + ".dll");
// Write a script that can be used to launch with CoreRun // Write a script that can be used to launch with CoreRun
var script = $@"#!/usr/bin/env bash var script = $@"#!/usr/bin/env bash
@ -189,14 +190,15 @@ exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*";
.GetAwaiter() .GetAwaiter()
.GetResult(); .GetResult();
File.Copy(outputDll, Path.ChangeExtension(outputDll, ".exe"), overwrite: true);
File.Delete(outputDll);
return 0; return 0;
} }
private static int PublishForWindows(ProjectContext context, string outputPath) private static int PublishForWindows(ProjectContext context, string outputPath)
{ {
if (context.TargetFramework.IsDesktop())
{
return 0;
}
// Locate Hosts // Locate Hosts
string hostsPath = Environment.GetEnvironmentVariable(Constants.HostsPathEnvironmentVariable); string hostsPath = Environment.GetEnvironmentVariable(Constants.HostsPathEnvironmentVariable);
if (string.IsNullOrEmpty(hostsPath)) if (string.IsNullOrEmpty(hostsPath))
@ -222,11 +224,13 @@ exec ""$DIR/corerun"" ""$DIR/{context.ProjectFile.Name}.exe"" $*";
File.Copy(coreConsole, Path.Combine(outputPath, Constants.CoreConsoleName), overwrite: true); File.Copy(coreConsole, Path.Combine(outputPath, Constants.CoreConsoleName), overwrite: true);
File.Copy(coreRun, Path.Combine(outputPath, Constants.CoreRunName), overwrite: true); File.Copy(coreRun, Path.Combine(outputPath, Constants.CoreRunName), overwrite: true);
// Use the 'command' field to generate the name
var outputExe = Path.Combine(outputPath, context.ProjectFile.Name + Constants.ExeSuffix); var outputExe = Path.Combine(outputPath, context.ProjectFile.Name + Constants.ExeSuffix);
// Rename the {app}.exe to {app}.dll
File.Copy(outputExe, Path.ChangeExtension(outputExe, ".dll"), overwrite: true);
// Change coreconsole.exe to the {app}.exe name
File.Copy(coreConsole, outputExe, overwrite: true); File.Copy(coreConsole, outputExe, overwrite: true);
return 0; return 0;
} }

View file

@ -166,12 +166,13 @@ namespace Microsoft.Extensions.ProjectModel.Compilation
private string GetOutputPath(ProjectDescription project) private string GetOutputPath(ProjectDescription project)
{ {
var compilationOptions = project.Project.GetCompilerOptions(project.Framework, _configuration);
return Path.Combine( return Path.Combine(
project.Project.ProjectDirectory, project.Project.ProjectDirectory,
"bin", // This can't access the Constant in Cli Utils. But the output path stuff is temporary right now anyway "bin", // This can't access the Constant in Cli Utils. But the output path stuff is temporary right now anyway
_configuration, _configuration,
project.Framework.GetTwoDigitShortFolderName(), project.Framework.GetTwoDigitShortFolderName(),
project.Project.Name + ".dll"); project.Project.Name + (compilationOptions.EmitEntryPoint.GetValueOrDefault() ? ".exe" : ".dll"));
} }
private static string ResolvePath(Project project, string configuration, string path) private static string ResolvePath(Project project, string configuration, string path)