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

Conversation

victorhurdugaci
Copy link
Contributor

Fixes: #2197

  • The error shows up only on run
  • The error doesn't show up on build so you can build with an older runtime
  • No tests because this is super hard to test
  • Most of the change is passing IRuntimeEnvironment up the stack

please review @davidfowl @anurse

@@ -30,18 +30,20 @@ public class ApplicationHostContext

public bool SkipLockfileValidation { get; set; }

public bool SkipRuntimeMinVersionCheck { get; set; }

public FrameworkReferenceResolver FrameworkResolver { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Add the RuntimeVersion to the ApplicationHostContext, so we don't have to flow this thing everywhere.

@moozzyk
Copy link
Contributor

moozzyk commented Sep 11, 2015

Is it possible to add tests?

@victorhurdugaci victorhurdugaci force-pushed the victorhu/min-version branch 3 times, most recently from eb4c9e0 to 5f4829d Compare September 11, 2015 19:26
@victorhurdugaci
Copy link
Contributor Author

Updated with tests

// Ignore projects references because in that case we are compiling from sources
// and versions don't match
if (lib.Type == LibraryTypes.Package &&
lib.Identity.Name.Equals("Microsoft.Dnx.Runtime.Abstractions", StringComparison.Ordinal))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we extract the string Microsoft.Dnx.Runtime.Abstractions in way rather than hard code the string. For example reflecting a type name?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd avoid reflection since this is in the critical runtime path. But putting it in a constant is a good idea :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm with @anurse on this one

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, though if we make other name changes we'll have to catch this case as well.

@analogrelay
Copy link
Contributor

Looking good. A few comments inline.


if (abstractions != null)
{
minRequiredRuntime = abstractions.Identity.Version.ToString();
Copy link
Member

Choose a reason for hiding this comment

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

Why are you turning this into a string and then back into a version?

@davidfowl
Copy link
Member

After giving this some thought, I think this change should be here:

https://github.com/aspnet/dnx/blob/dev/src/Microsoft.Dnx.ApplicationHost/DefaultHost.cs#L172

It's only relevant at runtime, we're trying to protect people from themselves and since we only throw at runtime, why put it in ApplicationHostContext.

@@ -13,5 +13,8 @@
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops, forgot these. Will revert

@victorhurdugaci victorhurdugaci force-pushed the victorhu/min-version branch 2 times, most recently from d1cf461 to daf9993 Compare September 14, 2015 17:30
@victorhurdugaci
Copy link
Contributor Author

updated

// because when building from sources the versions are not ordered
// correctly
if (lib.Type == LibraryTypes.Package &&
string.Equals(lib.Identity.Name, "Microsoft.Dnx.Runtime.Abstractions", StringComparison.Ordinal) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Constantify, as discussed earlier ;)

Copy link
Member

Choose a reason for hiding this comment

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

maybe typeof(SomethingInThatAssembly).GetTypeInfo().Assembly.GetName().Name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will change now

@analogrelay
Copy link
Contributor

LGTM

@@ -183,6 +185,22 @@ private void Initialize(RuntimeOptions options, IServiceProvider hostServices, I
AddBreadcrumbs(libraries);
}

private void ValidateMinRuntimeVersion(IEnumerable<LibraryDescription> libraries)
{
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.

@davidfowl
Copy link
Member

:shipit:

@victorhurdugaci victorhurdugaci force-pushed the victorhu/min-version branch 2 times, most recently from b44bef2 to d7299b9 Compare September 15, 2015 17:51
@victorhurdugaci victorhurdugaci merged commit 82b1501 into dev Sep 15, 2015
@victorhurdugaci victorhurdugaci deleted the victorhu/min-version branch September 15, 2015 22:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants