Add --runtimeconfig to the hostfxr, and use this option for the xunit scenario.

This commit is contained in:
Bryan Thornbury 2016-04-07 16:20:51 -07:00 committed by Eric Erhardt
parent 6fa859a354
commit 34d2445916
8 changed files with 51 additions and 39 deletions

View file

@ -17,7 +17,8 @@ namespace Microsoft.DotNet.Cli.Utils
IEnumerable<string> allowedExtensions,
string nugetPackagesRoot,
CommandResolutionStrategy commandResolutionStrategy,
string depsFilePath);
string depsFilePath,
string runtimeConfigPath);
}
}

View file

@ -17,7 +17,8 @@ namespace Microsoft.DotNet.Cli.Utils
IEnumerable<string> allowedExtensions,
string nugetPackagesRoot,
CommandResolutionStrategy commandResolutionStrategy,
string depsFilePath)
string depsFilePath,
string runtimeConfigPath)
{
var toolAssembly = toolLibrary?.RuntimeAssemblies
@ -35,7 +36,7 @@ namespace Microsoft.DotNet.Cli.Utils
return null;
}
var isPortable = IsPortableApp(commandPath);
var isPortable = IsPortableApp(commandPath, runtimeConfigPath);
return CreateCommandSpecWrappingWithCorehostIfDll(
commandPath,
@ -43,7 +44,8 @@ namespace Microsoft.DotNet.Cli.Utils
depsFilePath,
commandResolutionStrategy,
nugetPackagesRoot,
isPortable);
isPortable,
runtimeConfigPath);
}
private string GetCommandFilePath(string nugetPackagesRoot, LockFileTargetLibrary toolLibrary, LockFileItem runtimeAssembly)
@ -62,7 +64,8 @@ namespace Microsoft.DotNet.Cli.Utils
string depsFilePath,
CommandResolutionStrategy commandResolutionStrategy,
string nugetPackagesRoot,
bool isPortable)
bool isPortable,
string runtimeConfigPath)
{
var commandExtension = Path.GetExtension(commandPath);
@ -74,7 +77,8 @@ namespace Microsoft.DotNet.Cli.Utils
depsFilePath,
commandResolutionStrategy,
nugetPackagesRoot,
isPortable);
isPortable,
runtimeConfigPath);
}
return CreateCommandSpec(commandPath, commandArguments, commandResolutionStrategy);
@ -86,7 +90,8 @@ namespace Microsoft.DotNet.Cli.Utils
string depsFilePath,
CommandResolutionStrategy commandResolutionStrategy,
string nugetPackagesRoot,
bool isPortable)
bool isPortable,
string runtimeConfigPath)
{
var host = string.Empty;
var arguments = new List<string>();
@ -110,6 +115,12 @@ namespace Microsoft.DotNet.Cli.Utils
arguments.Add(commandPath);
if (runtimeConfigPath != null)
{
arguments.Add("--runtimeconfig");
arguments.Add(runtimeConfigPath);
}
if (depsFilePath != null)
{
arguments.Add("--depsfile");
@ -134,13 +145,14 @@ namespace Microsoft.DotNet.Cli.Utils
return new CommandSpec(commandPath, escapedArgs, commandResolutionStrategy);
}
private bool IsPortableApp(string commandPath)
private bool IsPortableApp(string commandPath, string runtimeConfigPath)
{
var commandDir = Path.GetDirectoryName(commandPath);
var runtimeConfigPath = Directory.EnumerateFiles(commandDir)
.FirstOrDefault(x => x.EndsWith("runtimeconfig.json"));
runtimeConfigPath = string.IsNullOrEmpty(runtimeConfigPath)
? Directory.EnumerateFiles(commandDir).FirstOrDefault(x => x.EndsWith("runtimeconfig.json"))
: runtimeConfigPath;
if (runtimeConfigPath == null)
{
return false;

View file

@ -78,25 +78,11 @@ namespace Microsoft.DotNet.Cli.Utils
var depsFilePath =
projectContext.GetOutputPaths(configuration, buildBasePath, outputPath).RuntimeFiles.DepsJson;
var runtimeConfigPath =
projectContext.GetOutputPaths(configuration, buildBasePath, outputPath).RuntimeFiles.RuntimeConfigJson;
var toolLibrary = GetToolLibraryForContext(projectContext, commandName);
return ResolveFromDependencyLibrary(
toolLibrary,
depsFilePath,
commandName,
allowedExtensions,
commandArguments,
projectContext);
}
private CommandSpec ResolveFromDependencyLibrary(
LockFileTargetLibrary toolLibrary,
string depsFilePath,
string commandName,
IEnumerable<string> allowedExtensions,
IEnumerable<string> commandArguments,
ProjectContext projectContext)
{
return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary(
toolLibrary,
commandName,
@ -104,7 +90,8 @@ namespace Microsoft.DotNet.Cli.Utils
allowedExtensions,
projectContext.PackagesDirectory,
s_commandResolutionStrategy,
depsFilePath);
depsFilePath,
runtimeConfigPath);
}
private LockFileTargetLibrary GetToolLibraryForContext(

View file

@ -123,7 +123,8 @@ namespace Microsoft.DotNet.Cli.Utils
_allowedCommandExtensions,
projectContext.PackagesDirectory,
s_commandResolutionStrategy,
depsFilePath);
depsFilePath,
null);
}
private LockFile GetToolLockFile(

View file

@ -304,15 +304,21 @@ int fx_muxer_t::parse_args_and_execute(const pal::string_t& own_dir, int argoff,
pal::string_t opts_deps_file = _X("--depsfile");
pal::string_t opts_probe_path = _X("--additionalprobingpath");
pal::string_t opts_runtime_config = _X("--runtimeconfig");
pal::string_t deps_file = get_last_known_arg(opts, opts_deps_file, _X(""));
pal::string_t runtime_config = get_last_known_arg(opts, opts_runtime_config, _X(""));
std::vector<pal::string_t> probe_paths = opts.count(opts_probe_path) ? opts[opts_probe_path] : std::vector<pal::string_t>();
trace::verbose(_X("Current argv is %s"), app_candidate.c_str());
pal::string_t app_or_deps = deps_file.empty() ? app_candidate : deps_file;
pal::string_t no_json = app_candidate;
pal::string_t dev_config_file;
auto config_file = get_runtime_config_from_file(no_json, &dev_config_file);
pal::string_t app_or_runtime_config = runtime_config.empty() ? app_candidate : runtime_config;
pal::string_t config_file, dev_config_file;
trace::error(_X("Finding runtimeconfig.json from [%s]"), app_or_runtime_config.c_str());
get_runtime_config_paths_from_file(app_or_runtime_config, &config_file, &dev_config_file);
runtime_config_t config(config_file, dev_config_file);
for (const auto& path : config.get_probe_paths())
{

View file

@ -246,9 +246,11 @@ SHARED_API int corehost_main(const int argc, const pal::char_t* argv[])
}
else
{
pal::string_t dev_config_file;
auto config_path = get_runtime_config_from_file(args.managed_application, &dev_config_file);
runtime_config_t config(config_path, dev_config_file);
pal::string_t config_file, dev_config_file;
get_runtime_config_paths_from_file(args.managed_application, &config_file, &dev_config_file);
runtime_config_t config(config_file, dev_config_file);
if (!config.is_valid())
{
trace::error(_X("Invalid runtimeconfig.json [%s] [%s]"), config.get_path().c_str(), config.get_dev_path().c_str());

View file

@ -6,20 +6,23 @@
#include "trace.h"
#include "libhost.h"
pal::string_t get_runtime_config_from_file(const pal::string_t& file, pal::string_t* dev_cfg)
void get_runtime_config_paths_from_file(const pal::string_t& file, pal::string_t* cfg, pal::string_t* dev_cfg)
{
auto name = get_filename_without_ext(file);
auto json_name = name + _X(".runtimeconfig.json");
auto dev_json_name = name + _X(".runtimeconfig.dev.json");
auto json_path = get_directory(file);
auto dev_json_path = json_path;
append_path(&json_path, json_name.c_str());
append_path(&dev_json_path, dev_json_name.c_str());
trace::verbose(_X("Runtime config is cfg=%s dev=%s"), json_path.c_str(), dev_json_path.c_str());
dev_cfg->assign(dev_json_path);
return json_path;
cfg -> assign(json_path);
}
host_mode_t detect_operating_mode(const int argc, const pal::char_t* argv[], pal::string_t* p_own_dir)

View file

@ -80,7 +80,7 @@ public:
}
};
pal::string_t get_runtime_config_from_file(const pal::string_t& file, pal::string_t* dev_config_file);
void get_runtime_config_paths_from_file(const pal::string_t& file, pal::string_t* config_file, pal::string_t* dev_config_file);
host_mode_t detect_operating_mode(const int argc, const pal::char_t* argv[], pal::string_t* own_dir = nullptr);
void try_patch_roll_forward_in_dir(const pal::string_t& cur_dir, const fx_ver_t& start_ver, pal::string_t* max_str);