Skip to content

Commit

Permalink
If user specifies a CLI version in the global.json, honor it - error …
Browse files Browse the repository at this point in the history
…out if not found.

And search the multilevel sdk lookup to find that specified version.

Addresses: https://github.com/dotnet/core-setup/issues/2334
https://github.com/dotnet/core-setup/issues/2336
  • Loading branch information
John Beisner committed May 19, 2017
1 parent c8456dc commit 2d00df8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if not defined VisualStudioVersion (
goto :Run
)
echo Error: Visual Studio 2015 required.
echo Please see https://github.com/dotnet/corefx/blob/master/Documentation/building/windows-instructions.md for build instructions.
echo Please see https://github.com/dotnet/core-setup/blob/master/Documentation/building/windows-instructions.md for build instructions.
exit /b 1
)

Expand Down
14 changes: 12 additions & 2 deletions src/corehost/cli/fxr/fx_muxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,20 +660,26 @@ bool fx_muxer_t::resolve_sdk_dotnet_path(const pal::string_t& own_dir, const pal
}

pal::string_t retval;
bool cli_version_specified = false;
bool cli_version_found = false;
pal::string_t cli_version;

for (pal::string_t dir : hive_dir)
{
trace::verbose(_X("Searching SDK directory in [%s]"), dir.c_str());
if (!global.empty())
{
pal::string_t cli_version = resolve_cli_version(global);
cli_version = resolve_cli_version(global);
if (!cli_version.empty())
{
cli_version_specified = true;
pal::string_t sdk_path = dir;
append_path(&sdk_path, _X("sdk"));
append_path(&sdk_path, cli_version.c_str());

if (pal::directory_exists(sdk_path))
{
cli_version_found = true;
trace::verbose(_X("CLI directory [%s] from global.json exists"), sdk_path.c_str());
retval = sdk_path;
}
Expand All @@ -683,7 +689,7 @@ bool fx_muxer_t::resolve_sdk_dotnet_path(const pal::string_t& own_dir, const pal
}
}
}
if (retval.empty())
if (retval.empty() && !cli_version_specified)
{
pal::string_t sdk_path = dir;
append_path(&sdk_path, _X("sdk"));
Expand All @@ -698,6 +704,10 @@ bool fx_muxer_t::resolve_sdk_dotnet_path(const pal::string_t& own_dir, const pal
}

trace::verbose(_X("It was not possible to find any SDK version"));
if (cli_version_specified && !cli_version_found)
{
trace::error(_X("The specified SDK version [%s] from global.json [%s] doesn't exist; install specified SDK version [%s]"), cli_version.c_str(), global.c_str(), cli_version.c_str());
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void SdkLookup_Must_Verify_Folders_in_the_Correct_Order()
}

[Fact]
public void SdkLookup_Must_Look_For_Available_Versions_Before_Looking_Into_Another_Folder()
public void SdkLookup_Global_Json_Versioned_Behaviors()
{
var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture
.Copy();
Expand All @@ -187,7 +187,7 @@ public void SdkLookup_Must_Look_For_Available_Versions_Before_Looking_Into_Anoth
// CWD: empty
// User: 9999.0.0, 9999.0.0-dummy
// Exe: 9999.0.0-dummy
// Expected: 9999.0.0 from user dir
// Expected: no compatible version and specific error message
dotnet.Exec("help")
.WorkingDirectory(_currentWorkingDir)
.WithUserProfile(_userDir)
Expand All @@ -196,19 +196,39 @@ public void SdkLookup_Must_Look_For_Available_Versions_Before_Looking_Into_Anoth
.CaptureStdErr()
.Execute()
.Should()
.Pass()
.Fail()
.And
.HaveStdErrContaining(Path.Combine(_userSelectedMessage, "9999.0.0", _dotnetSdkDllMessageTerminator));
.HaveStdErrContaining("global.json] doesn't exist; install specified SDK version [9999.0.0-global-dummy]");

// Add some dummy versions
AddAvailableSdkVersions(_cwdSdkBaseDir, "9999.0.0");
// Add specified CLI version
AddAvailableSdkVersions(_exeSdkBaseDir, "9999.0.0-global-dummy");

// Specified CLI version: 9999.0.0-global-dummy
// CWD: 9999.0.0 --> should not be picked
// CWD: empty
// User: 9999.0.0, 9999.0.0-dummy
// Exe: 9999.0.0-dummy, 9999.0.0-global-dummy
// Expected: 9999.0.0 from user dir
// Expected: 9999.0.0-global-dummy from exe dir
dotnet.Exec("help")
.WorkingDirectory(_currentWorkingDir)
.WithUserProfile(_userDir)
.Environment(s_DefaultEnvironment)
.CaptureStdOut()
.CaptureStdErr()
.Execute()
.Should()
.Pass()
.And
.HaveStdErrContaining(Path.Combine(_exeSelectedMessage, "9999.0.0-global-dummy", _dotnetSdkDllMessageTerminator));

// Add more specified CLI versions
AddAvailableSdkVersions(_cwdSdkBaseDir, "9999.0.0-global-dummy");
AddAvailableSdkVersions(_userSdkBaseDir, "9999.0.0-global-dummy");

// Specified CLI version: 9999.0.0-global-dummy
// CWD: 9999.0.0-global-dummy --> should not be picked
// User: 9999.0.0, 9999.0.0-dummy; 9999.0.0-global-dummy
// Exe: 9999.0.0-dummy, 9999.0.0-global-dummy
// Expected: 9999.0.0-global-dummy from user dir
dotnet.Exec("help")
.WorkingDirectory(_currentWorkingDir)
.WithUserProfile(_userDir)
Expand All @@ -219,10 +239,10 @@ public void SdkLookup_Must_Look_For_Available_Versions_Before_Looking_Into_Anoth
.Should()
.Pass()
.And
.HaveStdErrContaining(Path.Combine(_userSelectedMessage, "9999.0.0", _dotnetSdkDllMessageTerminator));
.HaveStdErrContaining(Path.Combine(_userSelectedMessage, "9999.0.0-global-dummy", _dotnetSdkDllMessageTerminator));

// Remove dummy folders from user dir
DeleteAvailableSdkVersions(_userSdkBaseDir, "9999.0.0", "9999.0.0-dummy");
DeleteAvailableSdkVersions(_userSdkBaseDir, "9999.0.0", "9999.0.0-dummy", "9999.0.0-global-dummy");
}

[Fact]
Expand Down

0 comments on commit 2d00df8

Please sign in to comment.