Skip to content

Commit

Permalink
Add package id and version to Reference and ReferenceCopyLocalPaths I…
Browse files Browse the repository at this point in the history
…tems (#603)

* Add package id and version to Reference and ReferenceCopyLocalPaths items #567

* Clean up statements in response to PR feedback; use transform to pull in metadata for compile files and framework assemblies

* Use transform for copy local items also
  • Loading branch information
natidea authored Mar 1, 2017
1 parent 350b396 commit b76e22d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,16 @@ public void ItOutputsCopyLocalItems()
var item = copyLocalItems.Where(t => t.ItemSpec.EndsWith(assetWritePath)).First();
item.GetMetadata("TargetPath").Should().Be("samplepp.output.txt");
item.GetMetadata(MetadataKeys.ParentPackage).Should().Be(package);
item.GetMetadata(MetadataKeys.PackageName).Should().Be("LibA");
item.GetMetadata(MetadataKeys.PackageVersion).Should().Be("1.2.3");

for (int i = 1; i < 3; i++)
{
item = copyLocalItems.Where(t => t.ItemSpec.EndsWith(contentFiles[i])).First();
item.GetMetadata("TargetPath").Should().Be(Path.Combine("output", contentFiles[i]));
item.GetMetadata(MetadataKeys.ParentPackage).Should().Be(package);
item.GetMetadata(MetadataKeys.PackageName).Should().Be("LibA");
item.GetMetadata(MetadataKeys.PackageVersion).Should().Be("1.2.3");
}

// not added to copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ public void ItAssignsFileDefinitionMetadata()
fileDefns.Count().Should().Be(1);
fileDefns.First().GetMetadata(MetadataKeys.Type).Should().Be(pair.Value);
fileDefns.First().GetMetadata(MetadataKeys.Path).Should().Be(pair.Key);
fileDefns.First().GetMetadata(MetadataKeys.PackageName).Should().Be("LibB");
fileDefns.First().GetMetadata(MetadataKeys.PackageVersion).Should().Be("1.2.3");
fileDefns.First().GetMetadata(MetadataKeys.ResolvedPath)
.Should().Be(Path.Combine(_packageRoot, "LibB", "1.2.3", "path",
pair.Key.Replace('/', Path.DirectorySeparatorChar)));
Expand Down
2 changes: 2 additions & 0 deletions src/Tasks/Microsoft.NET.Build.Tasks/MetadataKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public static class MetadataKeys
public const string FileGroup = "FileGroup";
public const string Path = "Path";
public const string ResolvedPath = "ResolvedPath";
public const string PackageName = "PackageName";
public const string PackageVersion = "PackageVersion";
public const string IsImplicitlyDefined = "IsImplicitlyDefined";
public const string IsTopLevelDependency = "IsTopLevelDependency";

Expand Down
18 changes: 12 additions & 6 deletions src/Tasks/Microsoft.NET.Build.Tasks/ProduceContentAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,23 @@ private void ProduceContentAsset(ITaskItem contentFile)
string pathToFinalAsset = resolvedPath;
string ppOutputPath = contentFile.GetMetadata(PPOutputPathKey);
string parentPackage = contentFile.GetMetadata(MetadataKeys.ParentPackage);
string[] parts = parentPackage?.Split('/');
if (parts == null || parts.Length != 2)
{
throw new BuildErrorException(Strings.ContentFileDoesNotContainExpectedParentPackageInformation, contentFile.ItemSpec);
}
string packageName = parts[0];
string packageVersion = parts[1];

if (!string.IsNullOrEmpty(ppOutputPath))
{
if (string.IsNullOrEmpty(ContentPreprocessorOutputDirectory))
{
throw new BuildErrorException(Strings.ContentPreproccessorParameterRequired, nameof(ProduceContentAssets), nameof(ContentPreprocessorOutputDirectory));
}
string [] parts = parentPackage?.Split('/');
if (parts == null)
{
throw new BuildErrorException(Strings.ContentFileDoesNotContainExpectedParentPackageInformation, contentFile.ItemSpec);
}

// We need the preprocessed output, so let's run the preprocessor here
string relativeOutputPath = Path.Combine(parts[0], parts[1], ppOutputPath);
string relativeOutputPath = Path.Combine(packageName, packageVersion, ppOutputPath);
if (AssetPreprocessor.Process(resolvedPath, relativeOutputPath, out pathToFinalAsset))
{
_fileWrites.Add(new TaskItem(pathToFinalAsset));
Expand All @@ -259,6 +261,8 @@ private void ProduceContentAsset(ITaskItem contentFile)
var item = new TaskItem(pathToFinalAsset);
item.SetMetadata("TargetPath", outputPath);
item.SetMetadata(MetadataKeys.ParentPackage, parentPackage);
item.SetMetadata(MetadataKeys.PackageName, packageName);
item.SetMetadata(MetadataKeys.PackageVersion, packageVersion);

_copyLocalItems.Add(item);
}
Expand All @@ -274,6 +278,8 @@ private void ProduceContentAsset(ITaskItem contentFile)
{
var item = new TaskItem(pathToFinalAsset);
item.SetMetadata(MetadataKeys.ParentPackage, parentPackage);
item.SetMetadata(MetadataKeys.PackageName, packageName);
item.SetMetadata(MetadataKeys.PackageVersion, packageVersion);

// We'll put additional metadata on the item so we can convert it back to the real item group in our targets
item.SetMetadata("ProcessedItemType", buildAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@ private void GetPackageAndFileDefinitions()
TaskItem item;
foreach (var package in LockFile.Libraries)
{
string packageId = $"{package.Name}/{package.Version.ToNormalizedString()}";
var packageName = package.Name;
var packageVersion = package.Version.ToNormalizedString();
string packageId = $"{packageName}/{packageVersion}";
item = new TaskItem(packageId);
item.SetMetadata(MetadataKeys.Name, package.Name);
item.SetMetadata(MetadataKeys.Name, packageName);
item.SetMetadata(MetadataKeys.Type, package.Type);
item.SetMetadata(MetadataKeys.Version, package.Version.ToNormalizedString());
item.SetMetadata(MetadataKeys.Version, packageVersion);

item.SetMetadata(MetadataKeys.Path, package.Path ?? string.Empty);

Expand All @@ -207,6 +209,8 @@ private void GetPackageAndFileDefinitions()
var fileKey = $"{packageId}/{file}";
var fileItem = new TaskItem(fileKey);
fileItem.SetMetadata(MetadataKeys.Path, file);
fileItem.SetMetadata(MetadataKeys.PackageName, packageName);
fileItem.SetMetadata(MetadataKeys.PackageVersion, packageVersion);

string resolvedPath = ResolveFilePath(file, resolvedPackagePath);
fileItem.SetMetadata(MetadataKeys.ResolvedPath, resolvedPath ?? string.Empty);
Expand Down Expand Up @@ -388,6 +392,8 @@ private void GetFileDependencies(LockFileTargetLibrary package, string targetNam
{
// NOTE: the path provided for framework assemblies is the name of the framework reference
item.SetMetadata("FrameworkAssembly", filePath);
item.SetMetadata(MetadataKeys.PackageName, package.Name);
item.SetMetadata(MetadataKeys.PackageVersion, package.Version.ToNormalizedString());
}

foreach (var property in properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<__CompileFileDefinitions Include="@(FileDefinitions)" Exclude="@(_CompileFileItems)" />
<_CompileFileDefinitions Include="@(FileDefinitions)" Exclude="@(__CompileFileDefinitions)" />

<ResolvedCompileFileDefinitions Include="%(_CompileFileDefinitions.ResolvedPath)">
<ResolvedCompileFileDefinitions Include="@(_CompileFileDefinitions->'%(ResolvedPath)')">
<Private>false</Private>
<NuGetIsFrameworkReference>false</NuGetIsFrameworkReference>
<NuGetSourceType>Package</NuGetSourceType>
<NuGetPackageId>%(PackageName)</NuGetPackageId>
<NuGetPackageVersion>%(PackageVersion)</NuGetPackageVersion>
</ResolvedCompileFileDefinitions>

</ItemGroup>
Expand All @@ -347,10 +349,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<ItemGroup>
<_FrameworkAssemblies Include="@(_TFMOnlyFileDependencies->WithMetadataValue('FileGroup', 'FrameworkAssembly'))" />

<ResolvedFrameworkAssemblies Include="%(_FrameworkAssemblies.FrameworkAssembly)">
<ResolvedFrameworkAssemblies Include="@(_FrameworkAssemblies->'%(FrameworkAssembly)')">
<Private>false</Private>
<NuGetIsFrameworkReference>true</NuGetIsFrameworkReference>
<NuGetSourceType>Package</NuGetSourceType>
<NuGetPackageId>%(PackageName)</NuGetPackageId>
<NuGetPackageVersion>%(PackageVersion)</NuGetPackageVersion>
</ResolvedFrameworkAssemblies>

</ItemGroup>
Expand Down Expand Up @@ -462,10 +466,22 @@ Copyright (c) .NET Foundation. All rights reserved.
<ResourceCopyLocalItems Include="%(_ResourceCopyLocalItems.ResolvedPath)" />

<!-- ALL -->
<AllCopyLocalItems Include="@(NativeCopyLocalItems);@(RuntimeCopyLocalItems);@(ResourceCopyLocalItems);@(_ContentCopyLocalItems)">
<_AllCopyLocalItems Include="@(_NativeCopyLocalItems);@(_RuntimeCopyLocalItems);@(_ResourceCopyLocalItems)" />

<AllCopyLocalItems Include="@(_AllCopyLocalItems->'%(ResolvedPath)')">
<Private>false</Private>
<NuGetIsFrameworkReference>false</NuGetIsFrameworkReference>
<NuGetSourceType>Package</NuGetSourceType>
<NuGetPackageId>%(PackageName)</NuGetPackageId>
<NuGetPackageVersion>%(PackageVersion)</NuGetPackageVersion>
</AllCopyLocalItems>

<AllCopyLocalItems Include="@(_ContentCopyLocalItems)">
<Private>false</Private>
<NuGetIsFrameworkReference>false</NuGetIsFrameworkReference>
<NuGetSourceType>Package</NuGetSourceType>
<NuGetPackageId>%(PackageName)</NuGetPackageId>
<NuGetPackageVersion>%(PackageVersion)</NuGetPackageVersion>
</AllCopyLocalItems>

</ItemGroup>
Expand Down

0 comments on commit b76e22d

Please sign in to comment.