PR feedback.

This commit is contained in:
Eric Erhardt 2016-07-21 18:17:20 -05:00
parent 72c59c4d05
commit 69619c0716
4 changed files with 93 additions and 84 deletions

View file

@ -101,8 +101,9 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
if (isRunnable && !_context.IsPortable)
{
// TODO: Pick a host based on the RID
VerifyCoreClrPresenceInPackageGraph();
RenamePublishedHost(_context, _runtimeOutputPath, _compilerOptions);
CoreHost.CopyTo(_runtimeOutputPath, _compilerOptions.OutputName + Constants.ExeSuffix);
}
}
@ -332,59 +333,5 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
exporter.GetAllExports().GenerateBindingRedirects(configFiles);
}
public static int RenamePublishedHost(ProjectContext context, string outputPath, CommonCompilerOptions compilationOptions)
{
if (context.TargetFramework.IsDesktop())
{
return 0;
}
var publishedHostFile = ResolvePublishedHostFile(outputPath);
if (publishedHostFile == null)
{
Reporter.Output.WriteLine($"publish: warning: host executable not available in dependencies, using host for current platform");
// TODO should this be an error?
CoreHost.CopyTo(outputPath, compilationOptions.OutputName + Constants.ExeSuffix);
return 0;
}
var publishedHostExtension = Path.GetExtension(publishedHostFile);
var renamedHostName = compilationOptions.OutputName + publishedHostExtension;
var renamedHostFile = Path.Combine(outputPath, renamedHostName);
try
{
Reporter.Verbose.WriteLine($"publish: renaming published host {publishedHostFile} to {renamedHostFile}");
File.Copy(publishedHostFile, renamedHostFile, true);
File.Delete(publishedHostFile);
}
catch (Exception e)
{
Reporter.Error.WriteLine($"publish: Failed to rename {publishedHostFile} to {renamedHostFile}: {e.Message}");
return 1;
}
return 0;
}
private static string ResolvePublishedHostFile(string outputPath)
{
var tryExtensions = new string[] { "", ".exe" };
foreach (var extension in tryExtensions)
{
var hostFile = Path.Combine(outputPath, Constants.PublishedHostExecutableName + extension);
if (File.Exists(hostFile))
{
Reporter.Verbose.WriteLine($"resolved published host: {hostFile}");
return hostFile;
}
}
Reporter.Verbose.WriteLine($"failed to resolve published host in: {outputPath}");
return null;
}
}
}

View file

@ -55,7 +55,7 @@
This will be set to false during "build", but set to true during "publish"
-->
<!--Setting PlatformTarget is needed when CopyNuGetImplementations is left on, or else you get 'Your project.json doesn't list 'win10' as a targeted runtime. You should add '"win10": { }' inside your "runtimes" section in your project.json, and then re-run NuGet restore' errors -->
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget Condition=" '$(PlatformTarget)' == '' ">x64</PlatformTarget>
<!-- Temp Hack: https://github.com/dotnet/roslyn/issues/12167 -->
<NoLogo>true</NoLogo>

View file

@ -69,33 +69,8 @@ namespace Microsoft.DotNet.Tools.New
archive.ExtractToDirectory(projectDirectory);
string projectJsonFile = Path.Combine(projectDirectory, "project.json");
File.Move(
Path.Combine(projectDirectory, "project.json.template"),
projectJsonFile);
string originalProjectJsonText = File.ReadAllText(projectJsonFile);
string replacedProjectJsonText = originalProjectJsonText
.Replace("$currentruntime$", RuntimeEnvironment.GetRuntimeIdentifier());
if (replacedProjectJsonText != originalProjectJsonText)
{
File.WriteAllText(projectJsonFile, replacedProjectJsonText);
}
string projectName = new DirectoryInfo(projectDirectory).Name;
foreach (string file in Directory.GetFiles(projectDirectory, "*", SearchOption.AllDirectories))
{
if (Path.GetFileNameWithoutExtension(file) == "$projectName$")
{
string extension = Path.GetExtension(file);
File.Move(
file,
Path.Combine(Path.GetDirectoryName(file), $"{projectName}{extension}"));
}
}
ReplaceProjectJsonTemplateValues(projectDirectory);
ReplaceFileTemplateNames(projectDirectory);
}
catch (IOException ex)
{
@ -116,6 +91,40 @@ namespace Microsoft.DotNet.Tools.New
return 0;
}
private static void ReplaceProjectJsonTemplateValues(string projectDirectory)
{
string projectJsonFile = Path.Combine(projectDirectory, "project.json");
File.Move(
Path.Combine(projectDirectory, "project.json.template"),
projectJsonFile);
string originalProjectJsonText = File.ReadAllText(projectJsonFile);
string replacedProjectJsonText = originalProjectJsonText
.Replace("$currentruntime$", RuntimeEnvironment.GetRuntimeIdentifier());
if (replacedProjectJsonText != originalProjectJsonText)
{
File.WriteAllText(projectJsonFile, replacedProjectJsonText);
}
}
private static void ReplaceFileTemplateNames(string projectDirectory)
{
string projectName = new DirectoryInfo(projectDirectory).Name;
foreach (string file in Directory.GetFiles(projectDirectory, "*", SearchOption.AllDirectories))
{
if (Path.GetFileNameWithoutExtension(file) == "$projectName$")
{
string extension = Path.GetExtension(file);
File.Move(
file,
Path.Combine(Path.GetDirectoryName(file), $"{projectName}{extension}"));
}
}
}
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);

View file

@ -199,7 +199,7 @@ namespace Microsoft.DotNet.Tools.Publish
if (options.EmitEntryPoint.GetValueOrDefault() && !string.IsNullOrEmpty(context.RuntimeIdentifier))
{
Reporter.Verbose.WriteLine($"publish: Renaming native host in output to create fully standalone output.");
Executable.RenamePublishedHost(context, outputPath, options);
RenamePublishedHost(context, outputPath, options);
}
RunScripts(context, ScriptNames.PostPublish, contextVariables);
@ -287,6 +287,59 @@ namespace Microsoft.DotNet.Tools.Publish
}
}
private static int RenamePublishedHost(ProjectContext context, string outputPath, CommonCompilerOptions compilationOptions)
{
if (context.TargetFramework.IsDesktop())
{
return 0;
}
var publishedHostFile = ResolvePublishedHostFile(outputPath);
if (publishedHostFile == null)
{
Reporter.Output.WriteLine($"publish: warning: host executable not available in dependencies, using host for current platform");
// TODO should this be an error?
CoreHost.CopyTo(outputPath, compilationOptions.OutputName + Constants.ExeSuffix);
return 0;
}
var publishedHostExtension = Path.GetExtension(publishedHostFile);
var renamedHostName = compilationOptions.OutputName + publishedHostExtension;
var renamedHostFile = Path.Combine(outputPath, renamedHostName);
try
{
Reporter.Verbose.WriteLine($"publish: renaming published host {publishedHostFile} to {renamedHostFile}");
File.Copy(publishedHostFile, renamedHostFile, true);
File.Delete(publishedHostFile);
}
catch (Exception e)
{
Reporter.Error.WriteLine($"publish: Failed to rename {publishedHostFile} to {renamedHostFile}: {e.Message}");
return 1;
}
return 0;
}
private static string ResolvePublishedHostFile(string outputPath)
{
var tryExtensions = new string[] { "", ".exe" };
foreach (var extension in tryExtensions)
{
var hostFile = Path.Combine(outputPath, Constants.PublishedHostExecutableName + extension);
if (File.Exists(hostFile))
{
Reporter.Verbose.WriteLine($"resolved published host: {hostFile}");
return hostFile;
}
}
Reporter.Verbose.WriteLine($"failed to resolve published host in: {outputPath}");
return null;
}
private void PublishAssetGroups(IEnumerable<LibraryAssetGroup> groups, string outputPath, bool nativeSubdirectories, bool includeRuntimeGroups)
{
foreach (var group in groups.Where(g => includeRuntimeGroups || string.IsNullOrEmpty(g.Runtime)))