Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.
Closed
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
2 changes: 1 addition & 1 deletion src/Microsoft.Dnx.Runtime/ApplicationHostContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private static Result InitializeCore(ApplicationHostContext context)

var path = Path.GetFullPath(Path.Combine(context.ProjectDirectory, projectLibrary.Path));

var projectDescription = projectResolver.GetDescription(context.TargetFramework, path, library);
var projectDescription = projectResolver.GetDescription(path, library);

libraries.Add(projectDescription);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Dnx.Runtime
{
public class ProjectDependencyProvider
{
public ProjectDescription GetDescription(FrameworkName targetFramework, string path, LockFileTargetLibrary targetLibrary)
public ProjectDescription GetDescription(string path, LockFileTargetLibrary targetLibrary)
{
Project project;

Expand All @@ -22,7 +22,7 @@ public ProjectDescription GetDescription(FrameworkName targetFramework, string p
return null;
}

return GetDescription(targetFramework, project);
return GetDescription(targetLibrary.TargetFramework, project);
}

public ProjectDescription GetDescription(FrameworkName targetFramework, Project project)
Expand All @@ -31,7 +31,7 @@ public ProjectDescription GetDescription(FrameworkName targetFramework, Project
var targetFrameworkInfo = project.GetTargetFramework(targetFramework);
var targetFrameworkDependencies = new List<LibraryDependency>(targetFrameworkInfo.Dependencies);

if (VersionUtility.IsDesktop(targetFramework))
if (targetFramework != null && VersionUtility.IsDesktop(targetFramework))
{
targetFrameworkDependencies.Add(new LibraryDependency
{
Expand Down Expand Up @@ -71,8 +71,7 @@ public ProjectDescription GetDescription(FrameworkName targetFramework, Project

// Mark the library as unresolved if there were specified frameworks
// and none of them resolved
bool unresolved = targetFrameworkInfo.FrameworkName == null &&
project.GetTargetFrameworks().Any();
bool unresolved = targetFrameworkInfo.FrameworkName == null;

return new ProjectDescription(
new LibraryRange(project.Name, frameworkReference: false),
Expand Down
11 changes: 2 additions & 9 deletions src/Microsoft.Dnx.Runtime/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,12 @@ public ICompilerOptions GetCompilerOptions(FrameworkName targetFramework,

public TargetFrameworkInformation GetTargetFramework(FrameworkName targetFramework)
{
TargetFrameworkInformation targetFrameworkInfo;
if (_targetFrameworks.TryGetValue(targetFramework, out targetFrameworkInfo))
TargetFrameworkInformation targetFrameworkInfo = null;
if (targetFramework != null && _targetFrameworks.TryGetValue(targetFramework, out targetFrameworkInfo))
{
return targetFrameworkInfo;
}

IEnumerable<TargetFrameworkInformation> compatibleConfigurations;
if (VersionUtility.GetNearest(targetFramework, GetTargetFrameworks(), out compatibleConfigurations) &&
compatibleConfigurations.Any())
{
targetFrameworkInfo = compatibleConfigurations.FirstOrDefault();
}

return targetFrameworkInfo ?? _defaultTargetFrameworkConfiguration;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't need the targetFrameworkInfo ?? part

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not?

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind

}

Expand Down
27 changes: 27 additions & 0 deletions src/Microsoft.Dnx.Tooling/ProjectExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

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

copyright

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we have a script for this?

Copy link
Member

Choose a reason for hiding this comment

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

Not that I know of

using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using Microsoft.Dnx.Runtime;
using NuGet;

namespace Microsoft.Dnx.Tooling
{
public static class ProjectExtensions
{
public static TargetFrameworkInformation GetCompatibleTargetFramework(this Runtime.Project project, FrameworkName targetFramework)
{
IEnumerable<TargetFrameworkInformation> targets;
if (VersionUtility.GetNearest(targetFramework, project.GetTargetFrameworks(), out targets) &&
targets.Any())
{
return targets.FirstOrDefault();
}

return new TargetFrameworkInformation
{
Dependencies = new List<LibraryDependency>()
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkNam
}

// This never returns null
var targetFrameworkInfo = project.GetTargetFramework(targetFramework);
var targetFrameworkInfo = project.GetCompatibleTargetFramework(targetFramework);

var dependencies = project.Dependencies.Concat(targetFrameworkInfo.Dependencies).ToList();

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Dnx.Tooling/Utils/LockFileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static LockFileProjectLibrary CreateLockFileProjectLibrary(Runtime.Projec
public static LockFileTargetLibrary CreateLockFileTargetLibrary(Runtime.Project projectDependency,
RestoreContext context)
{
var targetFrameworkInfo = projectDependency.GetTargetFramework(context.FrameworkName);
var targetFrameworkInfo = projectDependency.GetCompatibleTargetFramework(context.FrameworkName);

var lockFileLib = new LockFileTargetLibrary
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ public void AppHostShowsErrorWhenGivenSubcommandWasNotFoundInProjectJson(string

using (var projectPath = TestUtils.CreateTempDir())
{
DirTree.CreateFromJson(projectStructure).WriteTo(projectPath);
DirTree.CreateFromJson(projectStructure)
.WithFileContents("project.json", @"
{
""frameworks"": {
""dnx451"": { },
""dnxcore50"": { }
}
}").WriteTo(projectPath);

string stdOut, stdErr;
var exitCode = TestUtils.ExecBootstrapper(
Expand Down
4 changes: 4 additions & 0 deletions test/Microsoft.Dnx.Tooling.FunctionalTests/DnuPackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ public void DnuPack_DoesNotExecutePostBuildScriptWhenBuildFails(string flavor, s
{
var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
var projectJson = @"{
""frameworks"": {
""dnx451"": { },
""dnxcore50"": { }
},
""scripts"": {
""postbuild"": ""echo POST_BUILD_SCRIPT_OUTPUT"",
""postpack"": ""echo POST_PACK_SCRIPT_OUTPUT""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ private void CreateNewPackage(string name, string version)
var outputDir = dir.CreateSubdirectory("output");
var projectJson = Path.Combine(projectDir.FullName, "project.json");

File.WriteAllText(projectJson, "{\"version\": \"" + version + "\"}");
File.WriteAllText(projectJson, $@"{{
""version"": ""{version}"",
""frameworks"": {{
""dnx451"": {{ }}
}}
}}");
DnuTestUtils.ExecDnu(runtimeHomePath, "restore", projectJson);
DnuTestUtils.ExecDnu(runtimeHomePath, "pack", projectJson + " --out " + outputDir.FullName, environment: null, workingDir: null);

Expand Down