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

Commit

Permalink
fix #438 by adding support for dependency targets
Browse files Browse the repository at this point in the history
Targets can be used to restrict a dependency so that it can only be
satisfied by a particular type of library.
  • Loading branch information
analogrelay committed Sep 25, 2015
1 parent 1ce3be1 commit 1299bfe
Show file tree
Hide file tree
Showing 28 changed files with 409 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
TestResults/
.nuget/
_ReSharper.*/
/packages
packages/
artifacts/
TestOutput/
PublishProfiles/
Expand Down
33 changes: 33 additions & 0 deletions misc/DependencyTargets/DependencyTargets.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AC1AC331-AE09-4FDC-8C0C-07BDB3F5FEDE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D86121D1-15A1-4082-9066-F4E5D3803601}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
NuGet.Config = NuGet.Config
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "A", "src\A\A.xproj", "{0FA61EE7-5B67-441A-8097-6F8EDCAB1337}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0FA61EE7-5B67-441A-8097-6F8EDCAB1337}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FA61EE7-5B67-441A-8097-6F8EDCAB1337}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FA61EE7-5B67-441A-8097-6F8EDCAB1337}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FA61EE7-5B67-441A-8097-6F8EDCAB1337}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0FA61EE7-5B67-441A-8097-6F8EDCAB1337} = {AC1AC331-AE09-4FDC-8C0C-07BDB3F5FEDE}
EndGlobalSection
EndGlobal
8 changes: 8 additions & 0 deletions misc/DependencyTargets/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
4 changes: 4 additions & 0 deletions misc/DependencyTargets/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"packages": "packages",
"projects": [ "src", "test" ]
}
20 changes: 20 additions & 0 deletions misc/DependencyTargets/src/A/A.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>0fa61ee7-5b67-441a-8097-6f8edcab1337</ProjectGuid>
<RootNamespace>A</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
14 changes: 14 additions & 0 deletions misc/DependencyTargets/src/A/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace A
{
public static class Helper
{
public static string GetValue()
{
#if PACKAGE
return "This is Package A";
#else
return "This is Project A";
#endif
}
}
}
18 changes: 18 additions & 0 deletions misc/DependencyTargets/src/A/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "1.0.0",

"configurations": {
"package": {
"compilationOptions": { "define": [ "PACKAGE" ] }
}
},

"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Runtime": "4.0.0-beta-*"
}
}
}
}
20 changes: 20 additions & 0 deletions misc/DependencyTargets/src/App/App.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>036baeb2-6d3a-422c-ba4a-0656718927aa</ProjectGuid>
<RootNamespace>App</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
13 changes: 13 additions & 0 deletions misc/DependencyTargets/src/App/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace App
{
public class Program
{
public void Main(string[] args)
{
Console.WriteLine($"A: {A.Helper.GetValue()}");
Console.WriteLine($"B: {B.Helper.GetValue()}");
}
}
}
25 changes: 25 additions & 0 deletions misc/DependencyTargets/src/App/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "1.0.0",

"dependencies": {
"A": { "target": "project" },
"B": {
"version": "1.0.0-*",
"target": "package"
}
},

"commands": {
"App": "App"
},

"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Runtime": "4.0.0-beta-*",
"System.Console": "4.0.0-beta-*"
}
}
}
}
20 changes: 20 additions & 0 deletions misc/DependencyTargets/src/B/B.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>3532117e-5ffc-4d31-9ad6-e953005d3974</ProjectGuid>
<RootNamespace>B</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
14 changes: 14 additions & 0 deletions misc/DependencyTargets/src/B/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace B
{
public static class Helper
{
public static string GetValue()
{
#if PACKAGE
return "This is Package B";
#else
return "This is Project B";
#endif
}
}
}
18 changes: 18 additions & 0 deletions misc/DependencyTargets/src/B/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "1.0.0",

"configurations": {
"package": {
"compilationOptions": { "define": [ "PACKAGE" ] }
}
},

"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Runtime": "4.0.0-beta-*"
}
}
}
}
42 changes: 42 additions & 0 deletions src/Microsoft.Dnx.Runtime.Abstractions/DependencyTargets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace Microsoft.Dnx.Runtime
{
public static class DependencyTargets
{
public static readonly string Project = nameof(Project);
public static readonly string Package = nameof(Package);

private const string NoTargetDisplayName = "Dependency";

public static string GetDisplayForTarget(string target)
{
// Normalize the case of the known targets
if (string.Equals(target, Project, StringComparison.OrdinalIgnoreCase))
{
return Project;
}
else if (string.Equals(target, Package, StringComparison.OrdinalIgnoreCase))
{
return Package;
}
else
{
return NoTargetDisplayName;
}
}

public static bool SupportsPackage(string target)
{
return string.IsNullOrEmpty(target) || string.Equals(target, Package, StringComparison.OrdinalIgnoreCase);
}

public static bool SupportsProject(string target)
{
return string.IsNullOrEmpty(target) || string.Equals(target, Project, StringComparison.OrdinalIgnoreCase);
}
}
}
1 change: 1 addition & 0 deletions src/Microsoft.Dnx.Runtime.Abstractions/LibraryTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public static class LibraryTypes
public static readonly string ReferenceAssembly = "Assembly"; //Can't use 'nameof(ReferenceAssembly)' because of WTE compat for now. Logged with tooling.
public static readonly string GlobalAssemblyCache = nameof(GlobalAssemblyCache);
public static readonly string Unresolved = nameof(Unresolved);
public static readonly string Implicit = nameof(Implicit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class LibraryRange : IEquatable<LibraryRange>

public int Column { get; set; }

public string Target { get; set; }

public LibraryRange(string name, bool frameworkReference)
{
Name = name;
Expand Down
9 changes: 7 additions & 2 deletions src/Microsoft.Dnx.Runtime/ProjectReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ private static void PopulateDependencies(
var dependencyValue = dependencies.Value(dependencyKey);
var dependencyTypeValue = LibraryDependencyType.Default;
JsonString dependencyVersionAsString = null;
string target = null;

if (dependencyValue is JsonObject)
{
// "dependencies" : { "Name" : { "version": "1.0", "type": "build" } }
// "dependencies" : { "Name" : { "version": "1.0", "type": "build", "target": "project" } }
var dependencyValueAsObject = (JsonObject)dependencyValue;
dependencyVersionAsString = dependencyValueAsObject.ValueAsString("version");

Expand All @@ -212,6 +213,9 @@ private static void PopulateDependencies(
{
dependencyTypeValue = LibraryDependencyType.Parse(type.Value);
}

// Read the target if specified
target = dependencyValueAsObject.ValueAsString("target")?.Value;
}
else if (dependencyValue is JsonString)
{
Expand Down Expand Up @@ -249,7 +253,8 @@ private static void PopulateDependencies(
VersionRange = dependencyVersionRange,
FileName = projectPath,
Line = dependencyValue.Line,
Column = dependencyValue.Column
Column = dependencyValue.Column,
Target = target
},
Type = dependencyTypeValue
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public Task<WalkProviderMatch> FindLibrary(LibraryRange libraryRange, FrameworkN
return Task.FromResult(new WalkProviderMatch()
{
Provider = this,
LibraryType = LibraryTypes.Implicit,
Library = new LibraryIdentity(ImplicitRuntimePackageId, ImplicitRuntimePackageVersion, isGacOrFrameworkReference: false)
});
}
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.Dnx.Tooling/Restore/LocalWalkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Task<WalkProviderMatch> FindLibrary(LibraryRange libraryRange, FrameworkN
return Task.FromResult(new WalkProviderMatch
{
Library = description.Identity,
LibraryType = description.Type,
Path = description.Path,
Provider = this,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public IEnumerable<string> GetAttemptedPaths(FrameworkName targetFramework)

public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkName targetFramework)
{
if (libraryRange.IsGacOrFrameworkReference)
if(!DependencyTargets.SupportsPackage(libraryRange.Target))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkNam
return null;
}

if (!DependencyTargets.SupportsProject(libraryRange.Target))
{
return null;
}

string name = libraryRange.Name;

Runtime.Project project;
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.Dnx.Tooling/Restore/RemoteWalkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public RemoteWalkProvider(IPackageFeed source)

public async Task<WalkProviderMatch> FindLibrary(LibraryRange libraryRange, FrameworkName targetFramework, bool includeUnlisted)
{
if(!DependencyTargets.SupportsPackage(libraryRange.Target))
{
return null;
}

var results = await _source.FindPackagesByIdAsync(libraryRange.Name);
PackageInfo bestResult = null;
if(!includeUnlisted)
Expand All @@ -54,6 +59,7 @@ public async Task<WalkProviderMatch> FindLibrary(LibraryRange libraryRange, Fram
return new WalkProviderMatch
{
Library = new LibraryIdentity(bestResult.Id, bestResult.Version, isGacOrFrameworkReference: false),
LibraryType = LibraryTypes.Package,
Path = bestResult.ContentUri,
Provider = this,
};
Expand Down
Loading

0 comments on commit 1299bfe

Please sign in to comment.