Don't roll prefercliruntime tools forward across major versions of .NET Core

This commit is contained in:
Daniel Plaisted 2017-04-24 23:09:45 -07:00
parent ea7d84fbca
commit 8615c30063
2 changed files with 37 additions and 3 deletions

View file

@ -20,11 +20,43 @@ namespace Microsoft.DotNet.Cli.Utils
private static void AddAditionalParameters(string commandPath, IList<string> arguments)
{
if(PrefersCliRuntime(commandPath))
{
var runtimeConfigFile = Path.ChangeExtension(commandPath, FileNameSuffixes.RuntimeConfigJson);
var runtimeConfig = new RuntimeConfig(runtimeConfigFile);
var muxer = new Muxer();
Version currentFrameworkSimpleVersion = GetVersionWithoutPrerelease(muxer.SharedFxVersion);
Version toolFrameworkSimpleVersion = GetVersionWithoutPrerelease(runtimeConfig.Framework.Version);
if (currentFrameworkSimpleVersion.Major != toolFrameworkSimpleVersion.Major)
{
Reporter.Verbose.WriteLine(
string.Format(
LocalizableStrings.IgnoringPreferCLIRuntimeFile,
nameof(PackagedCommandSpecFactory),
runtimeConfig.Framework.Version,
muxer.SharedFxVersion));
}
else
{
arguments.Add("--fx-version");
arguments.Add(new Muxer().SharedFxVersion);
}
}
}
private static Version GetVersionWithoutPrerelease(string version)
{
int dashOrPlusIndex = version.IndexOfAny(new char[] { '-', '+' });
if (dashOrPlusIndex >= 0)
{
version = version.Substring(0, dashOrPlusIndex);
}
return new Version(version);
}
private static bool PrefersCliRuntime(string commandPath)
{
@ -35,7 +67,7 @@ namespace Microsoft.DotNet.Cli.Utils
Reporter.Verbose.WriteLine(
string.Format(
LocalizableStrings.LookingForPreferCliRuntimeFile,
"packagedcommandspecfactory",
nameof(PackagedCommandSpecFactory),
preferCliRuntimePath));
return File.Exists(preferCliRuntimePath);

View file

@ -19,6 +19,8 @@ namespace Microsoft.DotNet.Cli.Utils
public const string LookingForPreferCliRuntimeFile = "{0}: Looking for prefercliruntime file at `{1}`";
public const string IgnoringPreferCLIRuntimeFile = "{0}: Ignoring prefercliruntime file as the tool target framework ({1}) has a different major version than the current CLI runtime ({2})";
public const string AttemptingToResolve = "{0}: attempting to resolve {1}";
public const string DidNotFindAMatchingProject = "{0}: Did not find a matching project {1}.";