Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ public Library(string type, string name, string version, string? hash, System.Co
public partial class ResourceAssembly
{
public ResourceAssembly(string path, string locale) { }
public ResourceAssembly(string path, string locale, string? localPath) { }
public string Locale { get { throw null; } set { } }
public string Path { get { throw null; } set { } }
public string? LocalPath { get { throw null; } }
}
public partial class RuntimeAssembly
{
Expand Down Expand Up @@ -156,9 +158,11 @@ public RuntimeFallbacks(string runtime, params string?[] fallbacks) { }
public partial class RuntimeFile
{
public RuntimeFile(string path, string? assemblyVersion, string? fileVersion) { }
public RuntimeFile(string path, string? assemblyVersion, string? fileVersion, string? localPath) { }
public string? AssemblyVersion { get { throw null; } }
public string? FileVersion { get { throw null; } }
public string Path { get { throw null; } }
public string? LocalPath { get { throw null; } }
}
public partial class RuntimeLibrary : Microsoft.Extensions.DependencyModel.Library
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ private static List<RuntimeFile> ReadRuntimeFiles(ref Utf8JsonReader reader)
{
string? assemblyVersion = null;
string? fileVersion = null;
string? localPath = null;

string? path = reader.GetString();

Expand All @@ -527,12 +528,15 @@ private static List<RuntimeFile> ReadRuntimeFiles(ref Utf8JsonReader reader)
case DependencyContextStrings.FileVersionPropertyName:
fileVersion = propertyValue;
break;
case DependencyContextStrings.LocalPathPropertyName:
localPath = propertyValue;
break;
}
}

reader.CheckEndObject();

runtimeFiles.Add(new RuntimeFile(path, assemblyVersion, fileVersion));
runtimeFiles.Add(new RuntimeFile(path, assemblyVersion, fileVersion, localPath));
}

reader.CheckEndObject();
Expand Down Expand Up @@ -578,6 +582,9 @@ private List<RuntimeTargetEntryStub> ReadTargetLibraryRuntimeTargets(ref Utf8Jso
case DependencyContextStrings.FileVersionPropertyName:
runtimeTarget.FileVersion = propertyValue;
break;
case DependencyContextStrings.LocalPathPropertyName:
runtimeTarget.LocalPath = propertyValue;
break;
}
}

Expand Down Expand Up @@ -607,6 +614,7 @@ private List<ResourceAssembly> ReadTargetLibraryResources(ref Utf8JsonReader rea
}

string? locale = null;
string? localPath = null;

reader.ReadStartObject();

Expand All @@ -616,13 +624,17 @@ private List<ResourceAssembly> ReadTargetLibraryResources(ref Utf8JsonReader rea
{
locale = propertyValue;
}
else if (propertyName == DependencyContextStrings.LocalPathPropertyName)
{
localPath = propertyValue;
}
}

reader.CheckEndObject();

if (locale != null)
{
resources.Add(new ResourceAssembly(path, Pool(locale)));
resources.Add(new ResourceAssembly(path, Pool(locale), localPath));
}
}

Expand Down Expand Up @@ -786,7 +798,7 @@ IEnumerable<Library> CreateLibrariesNotNull(IEnumerable<TargetLibrary> libraries
{
RuntimeFile[] groupRuntimeAssemblies = ridGroup
.Where(e => e.Type == DependencyContextStrings.RuntimeAssetType)
.Select(e => new RuntimeFile(e.Path, e.AssemblyVersion, e.FileVersion))
.Select(e => new RuntimeFile(e.Path, e.AssemblyVersion, e.FileVersion, e.LocalPath))
.ToArray();

if (groupRuntimeAssemblies.Length != 0)
Expand All @@ -798,7 +810,7 @@ IEnumerable<Library> CreateLibrariesNotNull(IEnumerable<TargetLibrary> libraries

RuntimeFile[] groupNativeLibraries = ridGroup
.Where(e => e.Type == DependencyContextStrings.NativeAssetType)
.Select(e => new RuntimeFile(e.Path, e.AssemblyVersion, e.FileVersion))
.Select(e => new RuntimeFile(e.Path, e.AssemblyVersion, e.FileVersion, e.LocalPath))
.ToArray();

if (groupNativeLibraries.Length != 0)
Expand Down Expand Up @@ -909,6 +921,8 @@ private struct RuntimeTargetEntryStub
public string? AssemblyVersion;

public string? FileVersion;

public string? LocalPath;
}

private struct LibraryStub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,7 @@ internal static class DependencyContextStrings
internal const string AssemblyVersionPropertyName = "assemblyVersion";

internal const string FileVersionPropertyName = "fileVersion";

internal const string LocalPathPropertyName = "localPath";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ private static void AddResourceAssemblies(IReadOnlyList<ResourceAssembly> resour
ResourceAssembly resourceAssembly = resourceAssemblies[i];
jsonWriter.WriteStartObject(NormalizePath(resourceAssembly.Path));
jsonWriter.WriteString(DependencyContextStrings.LocalePropertyName, resourceAssembly.Locale);
if (resourceAssembly.LocalPath != null)
{
jsonWriter.WriteString(DependencyContextStrings.LocalPathPropertyName, NormalizePath(resourceAssembly.LocalPath));
}

jsonWriter.WriteEndObject();
}
jsonWriter.WriteEndObject();
Expand Down Expand Up @@ -363,6 +368,11 @@ private static void AddRuntimeSpecificAssets(IEnumerable<RuntimeFile> assets, st
jsonWriter.WriteString(DependencyContextStrings.FileVersionPropertyName, asset.FileVersion);
}

if (asset.LocalPath != null)
{
jsonWriter.WriteString(DependencyContextStrings.LocalPathPropertyName, NormalizePath(asset.LocalPath));
}

jsonWriter.WriteEndObject();
}
}
Expand Down Expand Up @@ -396,6 +406,11 @@ private static void WriteAssetList(string key, IEnumerable<RuntimeFile> runtimeF
jsonWriter.WriteString(DependencyContextStrings.FileVersionPropertyName, runtimeFile.FileVersion);
}

if (runtimeFile.LocalPath != null)
{
jsonWriter.WriteString(DependencyContextStrings.LocalPathPropertyName, NormalizePath(runtimeFile.LocalPath));
}

jsonWriter.WriteEndObject();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace Microsoft.Extensions.DependencyModel
public class ResourceAssembly
{
public ResourceAssembly(string path, string locale)
: this(path, locale, null)
{ }

public ResourceAssembly(string path, string locale, string? localPath)
{
if (string.IsNullOrEmpty(path))
{
Expand All @@ -19,11 +23,16 @@ public ResourceAssembly(string path, string locale)
}
Locale = locale;
Path = path;
LocalPath = localPath;
}

public string Locale { get; set; }

// Depending on the source of the resource assembly, this path may be relative to the
// a referenced NuGet package's root or to the app/component root.
public string Path { get; set; }

// Path relative to the app/component represented by the dependency context
public string? LocalPath { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace Microsoft.Extensions.DependencyModel
public class RuntimeFile
{
public RuntimeFile(string path, string? assemblyVersion, string? fileVersion)
: this(path, assemblyVersion, fileVersion, null)
{ }

public RuntimeFile(string path, string? assemblyVersion, string? fileVersion, string? localPath)
{
if (string.IsNullOrEmpty(path))
{
Expand All @@ -17,12 +21,18 @@ public RuntimeFile(string path, string? assemblyVersion, string? fileVersion)
Path = path;
AssemblyVersion = assemblyVersion;
FileVersion = fileVersion;
LocalPath = localPath;
}

// Depending on the source of the runtime file, this path may be relative to the
// a referenced NuGet package's root or to the app/component root.
public string Path { get; }

public string? AssemblyVersion { get; }

public string? FileVersion { get; }

// Path relative to the app/component represented by the dependency context
public string? LocalPath { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -835,5 +835,123 @@ public void FailsToReadEmptyLibraryType()
}
"));
}

[Fact]
public void ReadsRuntimeFilesWithLocalPath()
{
var context = Read(
@"{
""targets"": {
"".NETCoreApp,Version=v5.0"": {
""System.Banana/1.0.0"": {
""runtime"": {
""lib/System.Banana.dll"": {
""assemblyVersion"": ""1.2.3"",
""fileVersion"": ""4.5.6"",
""localPath"": ""local/path/System.Banana.dll""
}
}
}
}
},
""libraries"": {
""System.Banana/1.0.0"": {
""type"": ""package"",
""serviceable"": false,
""sha512"": ""HASH-System.Banana""
}
}
}");

var runtimeLibrary = context.RuntimeLibraries.Should().ContainSingle().Subject;
var runtimeFile = runtimeLibrary.RuntimeAssemblyGroups.GetDefaultRuntimeFileAssets().Single();

Assert.Equal("lib/System.Banana.dll", runtimeFile.Path);
Assert.Equal("1.2.3", runtimeFile.AssemblyVersion);
Assert.Equal("4.5.6", runtimeFile.FileVersion);
Assert.Equal("local/path/System.Banana.dll", runtimeFile.LocalPath);
}

[Fact]
public void ReadsRuntimeTargetsWithLocalPath()
{
var context = Read(
@"{
""targets"": {
"".NETCoreApp,Version=v5.0/unix"": {
""System.Banana/1.0.0"": {
""runtimeTargets"": {
""runtimes/unix/lib/System.Banana.dll"": {
""rid"": ""unix"",
""assetType"": ""runtime"",
""assemblyVersion"": ""1.2.3"",
""fileVersion"": ""4.5.6"",
""localPath"": ""unix/custom/System.Banana.dll""
},
""runtimes/linux-x64/native/native.so"": {
""rid"": ""linux-x64"",
""assetType"": ""native"",
""assemblyVersion"": ""1.2.3"",
""fileVersion"": ""4.5.6"",
""localPath"": ""local/path/linux-x64/native.so""
}
}
}
}
},
""libraries"": {
""System.Banana/1.0.0"": {
""type"": ""package"",
""serviceable"": false,
""sha512"": ""HASH-System.Banana""
}
}
}");

var runtimeLibrary = context.RuntimeLibraries.Should().ContainSingle().Subject;
var runtimeFile = runtimeLibrary.RuntimeAssemblyGroups.GetRuntimeFileAssets("unix").Single();
Assert.Equal("runtimes/unix/lib/System.Banana.dll", runtimeFile.Path);
Assert.Equal("1.2.3", runtimeFile.AssemblyVersion);
Assert.Equal("4.5.6", runtimeFile.FileVersion);
Assert.Equal("unix/custom/System.Banana.dll", runtimeFile.LocalPath);

runtimeFile = runtimeLibrary.NativeLibraryGroups.GetRuntimeFileAssets("linux-x64").Single();
Assert.Equal("runtimes/linux-x64/native/native.so", runtimeFile.Path);
Assert.Equal("local/path/linux-x64/native.so", runtimeFile.LocalPath);
}

[Fact]
public void ReadsResourceAssembliesWithLocalPath()
{
var context = Read(
@"{
""targets"": {
"".NETCoreApp,Version=v5.0"": {
""System.Banana/1.0.0"": {
""resources"": {
""fr/System.Banana.resources.dll"": {
""locale"": ""fr"",
""localPath"": ""local/path/fr/System.Banana.resources.dll""
}
}
}
}
},
""libraries"": {
""System.Banana/1.0.0"": {
""type"": ""package"",
""serviceable"": false,
""sha512"": ""HASH-System.Banana""
}
}
}");

var runtimeLibrary = context.RuntimeLibraries.Should().ContainSingle().Subject;
var resourceAssembly = runtimeLibrary.ResourceAssemblies.Single();

Assert.Equal("fr/System.Banana.resources.dll", resourceAssembly.Path);
Assert.Equal("fr", resourceAssembly.Locale);
Assert.Equal("local/path/fr/System.Banana.resources.dll", resourceAssembly.LocalPath);
}
}
}
Loading
Loading