add support for portable application layout

This commit is contained in:
Andrew Stanton-Nurse 2016-03-09 11:36:16 -08:00
parent cef64895c8
commit d08e83d5db
38 changed files with 371 additions and 192 deletions

View file

@ -29,7 +29,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private readonly bool _noIncremental;
private readonly bool _noDependencies;
private readonly string _runtime;
private readonly bool _forcePortable;
private string OutputOption
{
@ -41,16 +40,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
}
}
private string ForcePortableOption
{
get
{
return _forcePortable ?
"--portable" :
string.Empty;
}
}
private string BuildBasePathOption
{
get
@ -228,9 +217,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
string cppCompilerFlags="",
bool buildProfile=true,
bool noIncremental=false,
bool noDependencies=false,
bool forcePortable=false
)
bool noDependencies=false)
: base("dotnet")
{
_projectPath = projectPath;
@ -253,7 +240,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
_buildProfile = buildProfile;
_noIncremental = noIncremental;
_noDependencies = noDependencies;
_forcePortable = forcePortable;
}
public override CommandResult Execute(string args = "")
@ -277,7 +263,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string BuildArgs()
{
return $"{BuildProfile} {ForcePortableOption} {NoDependencies} {NoIncremental} \"{_projectPath}\" {OutputOption} {BuildBasePathOption} {ConfigurationOption} {FrameworkOption} {RuntimeOption} {VersionSuffixOption} {NoHostOption} {NativeOption} {ArchitectureOption} {IlcArgsOption} {IlcPathOption} {AppDepSDKPathOption} {NativeCppModeOption} {CppCompilerFlagsOption}";
return $"{BuildProfile} {NoDependencies} {NoIncremental} \"{_projectPath}\" {OutputOption} {BuildBasePathOption} {ConfigurationOption} {FrameworkOption} {RuntimeOption} {VersionSuffixOption} {NoHostOption} {NativeOption} {ArchitectureOption} {IlcArgsOption} {IlcPathOption} {AppDepSDKPathOption} {NativeCppModeOption} {CppCompilerFlagsOption}";
}
}
}

View file

@ -1,16 +1,12 @@
// 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 Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectModel;
using Microsoft.Extensions.PlatformAbstractions;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
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
{
@ -18,14 +14,14 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{
private const string PublishSubfolderName = "publish";
private Project _project;
private string _path;
private string _framework;
private string _runtime;
private string _config;
private string _output;
private readonly Project _project;
private readonly string _path;
private readonly string _framework;
private readonly string _runtime;
private readonly string _config;
private readonly string _output;
public PublishCommand(string projectPath, string framework="", string runtime="", string output="", string config="")
public PublishCommand(string projectPath, string framework = "", string runtime = "", string output = "", string config = "", bool forcePortable = false)
: base("dotnet")
{
_path = projectPath;
@ -36,7 +32,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
_config = config;
}
public override CommandResult Execute(string args="")
public override CommandResult Execute(string args = "")
{
args = $"publish {BuildArgs()} {args}";
return base.Execute(args);
@ -48,34 +44,33 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return base.ExecuteWithCapturedOutput(args);
}
public string ProjectName
{
get
{
return _project.Name;
}
}
public string ProjectName => _project.Name;
private string BuildRelativeOutputPath()
private string BuildRelativeOutputPath(bool portable)
{
// lets try to build an approximate output path
string config = string.IsNullOrEmpty(_config) ? "Debug" : _config;
string framework = string.IsNullOrEmpty(_framework) ?
_project.GetTargetFrameworks().First().FrameworkName.GetShortFolderName() : _framework;
string runtime = string.IsNullOrEmpty(_runtime) ? PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier() : _runtime;
string output = Path.Combine(config, framework, runtime, PublishSubfolderName);
return output;
if (!portable)
{
var runtime = string.IsNullOrEmpty(_runtime) ? PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier() : _runtime;
return Path.Combine(config, framework, runtime, PublishSubfolderName);
}
else
{
return Path.Combine(config, framework, PublishSubfolderName);
}
}
public DirectoryInfo GetOutputDirectory()
public DirectoryInfo GetOutputDirectory(bool portable = false)
{
if (!string.IsNullOrEmpty(_output))
{
return new DirectoryInfo(_output);
}
string output = Path.Combine(_project.ProjectDirectory, "bin", BuildRelativeOutputPath());
string output = Path.Combine(_project.ProjectDirectory, "bin", BuildRelativeOutputPath(portable));
return new DirectoryInfo(output);
}
@ -88,27 +83,12 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private string BuildArgs()
{
return $"{_path} {GetFrameworkOption()} {GetRuntimeOption()} {GetOutputOption()} {GetConfigOption()}";
return $"{_path} {FrameworkOption} {RuntimeOption} {OutputOption} {ConfigOption}";
}
private string GetFrameworkOption()
{
return string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
}
private string GetRuntimeOption()
{
return string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
}
private string GetOutputOption()
{
return string.IsNullOrEmpty(_output) ? "" : $"-o \"{_output}\"";
}
private string GetConfigOption()
{
return string.IsNullOrEmpty(_config) ? "" : $"-c {_output}";
}
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o \"{_output}\"";
private string ConfigOption => string.IsNullOrEmpty(_config) ? "" : $"-c {_output}";
}
}