Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Check for min runtime version at application start #2675

Merged
merged 1 commit into from
Sep 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/Microsoft.Dnx.ApplicationHost/DefaultHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace Microsoft.Dnx.ApplicationHost
{
public class DefaultHost
{
private static readonly string RuntimeAbstractionsPackageName =
typeof(IRuntimeEnvironment).GetTypeInfo().Assembly.GetName().Name;

private ApplicationHostContext _applicationHostContext;

private readonly string _projectDirectory;
Expand Down Expand Up @@ -124,6 +127,8 @@ private void Initialize(RuntimeOptions options, IServiceProvider hostServices, I

_project = applicationHostContext.Project;

ValidateMinRuntimeVersion(libraries);

if (options.WatchFiles)
{
fileWatcher.OnChanged += _ =>
Expand All @@ -140,11 +145,11 @@ private void Initialize(RuntimeOptions options, IServiceProvider hostServices, I
var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, options.Configuration, hostEnvironment);

var compilationContext = new CompilationEngineContext(
applicationEnvironment,
_runtimeEnvironment,
loadContextAccessor.Default,
new CompilationCache(),
fileWatcher,
applicationEnvironment,
_runtimeEnvironment,
loadContextAccessor.Default,
new CompilationCache(),
fileWatcher,
new ProjectGraphProvider());

// Compilation services available only for runtime compilation
Expand Down Expand Up @@ -183,6 +188,28 @@ private void Initialize(RuntimeOptions options, IServiceProvider hostServices, I
AddBreadcrumbs(libraries);
}

private void ValidateMinRuntimeVersion(IEnumerable<LibraryDescription> libraries)
{
if (string.Equals(Environment.GetEnvironmentVariable(EnvironmentNames.DnxDisableMinVersionCheck), "1", StringComparison.OrdinalIgnoreCase))
{
// Min version is disabled
return;
}

foreach (var lib in libraries)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid the 2 for loops and do the servicing and this in a single pass but that's not important right now.

{
// We only need to validate if runtime abstractions is precompiled
// because when building from sources the versions are not ordered
// correctly
if (lib.Type == LibraryTypes.Package &&
string.Equals(lib.Identity.Name, RuntimeAbstractionsPackageName, StringComparison.Ordinal) &&
lib.Identity.Version > new SemanticVersion(_runtimeEnvironment.RuntimeVersion))
{
throw new InvalidOperationException($"This application requires DNX version {lib.Identity.Version} or newer to run.");
}
}
}

private void AddBreadcrumbs(IEnumerable<LibraryDescription> libraries)
{
AddRuntimeServiceBreadcrumb();
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Dnx.Runtime.Sources/Impl/EnvironmentNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ internal static class EnvironmentNames
public const string PortablePdb = "DNX_BUILD_PORTABLE_PDB";
public const string DnxIsWindows = "DNX_IS_WINDOWS";
public const string AspNetLoaderPath = "DNX_ASPNET_LOADER_PATH";
public const string DnxDisableMinVersionCheck = "DNX_NO_MIN_VERSION_CHECK";
}
}