Skip to content

Commit

Permalink
Support for ContentFiles in generated props.
Browse files Browse the repository at this point in the history
Added support for writing out contentFiles to the generated props file.
Renamed buildCrossTargeting to buildMultiTargeting
Combined RestoreResult and MSBuildRestoreResult
MSBuild targets/props are now full members of nuget restore.

Fixes NuGet/Home#4098
Fixes NuGet/Home#3928
Fixes NuGet/Home#3683
Fixes NuGet/Home#3399
Fixes NuGet/Home#4116
  • Loading branch information
emgarten committed Dec 17, 2016
1 parent 36293a3 commit efae789
Show file tree
Hide file tree
Showing 30 changed files with 2,168 additions and 1,516 deletions.
27 changes: 22 additions & 5 deletions src/NuGet.Core/NuGet.Client/ManagedCodeConventions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@ public class ManagedCodeConventions
PropertyNames.AnyValue,
parser: (o, t) => o); // Identity parser, all strings are valid for any
private static readonly ContentPropertyDefinition AssemblyProperty = new ContentPropertyDefinition(PropertyNames.ManagedAssembly,
parser: (o, t) => o.Equals(PackagingCoreConstants.EmptyFolder, StringComparison.Ordinal) ? o : null, // Accept "_._" as a pseudo-assembly
parser: AllowEmptyFolderParser,
fileExtensions: new[] { ".dll", ".winmd", ".exe" });
private static readonly ContentPropertyDefinition MSBuildProperty = new ContentPropertyDefinition(PropertyNames.MSBuild, fileExtensions: new[] { ".targets", ".props" });
private static readonly ContentPropertyDefinition SatelliteAssemblyProperty = new ContentPropertyDefinition(PropertyNames.SatelliteAssembly, fileExtensions: new[] { ".resources.dll" });
private static readonly ContentPropertyDefinition MSBuildProperty = new ContentPropertyDefinition(PropertyNames.MSBuild,
parser: AllowEmptyFolderParser,
fileExtensions: new[] { ".targets", ".props" });
private static readonly ContentPropertyDefinition SatelliteAssemblyProperty = new ContentPropertyDefinition(PropertyNames.SatelliteAssembly,
parser: AllowEmptyFolderParser,
fileExtensions: new[] { ".resources.dll" });

private static readonly ContentPropertyDefinition CodeLanguageProperty = new ContentPropertyDefinition(
PropertyNames.CodeLanguage,
parser: CodeLanguage_Parser);


private static readonly Dictionary<string, object> DefaultTfmAny = new Dictionary<string, object>
{
{ PropertyNames.TargetFrameworkMoniker, AnyFramework.Instance }
Expand Down Expand Up @@ -197,6 +202,12 @@ private static NuGetFramework TargetFrameworkName_ParserCore(string name)
return new NuGetFramework(name, FrameworkConstants.EmptyVersion);
}

private static object AllowEmptyFolderParser(string s, PatternTable table)
{
// Accept "_._" as a pseudo-assembly
return PackagingCoreConstants.EmptyFolder.Equals(s, StringComparison.Ordinal) ? s : null;
}

private static bool TargetFrameworkName_CompatibilityTest(object criteria, object available)
{
var criteriaFrameworkName = criteria as NuGetFramework;
Expand Down Expand Up @@ -355,7 +366,7 @@ public class ManagedCodePatterns
/// <summary>
/// Pattern used to identify MSBuild global targets and props files
/// </summary>
public PatternSet MSBuildCrossTargetingFiles { get; }
public PatternSet MSBuildMultiTargetingFiles { get; }

/// <summary>
/// Pattern used to identify content files
Expand Down Expand Up @@ -449,14 +460,20 @@ internal ManagedCodePatterns(ManagedCodeConventions conventions)
new PatternDefinition("build/{msbuild}", table: null, defaults: DefaultTfmAny)
});

MSBuildCrossTargetingFiles = new PatternSet(
MSBuildMultiTargetingFiles = new PatternSet(
conventions.Properties,
groupPatterns: new PatternDefinition[]
{
new PatternDefinition("buildMultiTargeting/{msbuild?}", table: null, defaults: DefaultTfmAny),

// deprecated
new PatternDefinition("buildCrossTargeting/{msbuild?}", table: null, defaults: DefaultTfmAny)
},
pathPatterns: new PatternDefinition[]
{
new PatternDefinition("buildMultiTargeting/{msbuild}", table: null, defaults: DefaultTfmAny),

// deprecated
new PatternDefinition("buildCrossTargeting/{msbuild}", table: null, defaults: DefaultTfmAny)
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ private bool IsCompatible(CompatibilityData compatibilityData)
compatibilityData.TargetLibrary.FrameworkAssemblies.Count > 0 || // Framework Assemblies, or
compatibilityData.TargetLibrary.ContentFiles.Count > 0 || // Shared content
compatibilityData.TargetLibrary.ResourceAssemblies.Count > 0 || // Resources (satellite package)
compatibilityData.TargetLibrary.Build.Count > 0 || // Build
compatibilityData.TargetLibrary.BuildMultiTargeting.Count > 0 || // Cross targeting build
!compatibilityData.Files.Any(p =>
p.StartsWith("ref/", StringComparison.OrdinalIgnoreCase)
|| p.StartsWith("lib/", StringComparison.OrdinalIgnoreCase)); // No assemblies at all (for any TxM)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Collections.Generic;
using NuGet.ProjectModel;

namespace NuGet.Commands
Expand All @@ -24,5 +25,10 @@ public interface IRestoreResult
/// The existing lock file. This is null if no lock file was provided on the <see cref="RestoreRequest"/>.
/// </summary>
LockFile PreviousLockFile { get; }

/// <summary>
/// Props and targets files to be written to disk.
/// </summary>
IEnumerable<MSBuildOutputFile> MSBuildOutputFiles { get; }
}
}
33 changes: 33 additions & 0 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand/MSBuildOutputFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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;
using System.Xml.Linq;

namespace NuGet.Commands
{
public class MSBuildOutputFile
{
/// <summary>
/// Output path on disk.
/// </summary>
public string Path { get; }

/// <summary>
/// MSBuild file content. This will be null for files
/// that should be removed.
/// </summary>
public XDocument Content { get; }

public MSBuildOutputFile (string path, XDocument content)
{
if (path == null)
{
throw new ArgumentNullException(nameof(path));
}

Path = path;
Content = content;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// 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;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

namespace NuGet.Commands
{
public class MSBuildRestoreImportGroup
public class MSBuildRestoreItemGroup
{
public static readonly string ItemGroup = nameof(ItemGroup);
public static readonly string ImportGroup = nameof(ImportGroup);

/// <summary>
/// Optional position arguement used when ordering groups in the output file.
/// </summary>
Expand All @@ -20,9 +23,14 @@ public class MSBuildRestoreImportGroup
public List<string> Conditions { get; set; } = new List<string>();

/// <summary>
/// Project paths to import.
/// Items or imports.
/// </summary>
public List<string> Imports { get; set; } = new List<string>();
public List<XElement> Items { get; set; } = new List<XElement>();

/// <summary>
/// Root element name.
/// </summary>
public string RootName { get; set; } = ImportGroup;

/// <summary>
/// Combined conditions
Expand All @@ -41,5 +49,21 @@ public string Condition
}
}
}

public static MSBuildRestoreItemGroup Create(
string rootName,
IEnumerable<XElement> items,
int position,
IEnumerable<string> conditions)
{
var group = new MSBuildRestoreItemGroup();

group.RootName = rootName;
group.Items.AddRange(items);
group.Position = position;
group.Conditions.AddRange(conditions);

return group;
}
}
}
Loading

0 comments on commit efae789

Please sign in to comment.