Fix boot json on mac/linux (#19332)
This commit is contained in:
parent
461051ec78
commit
bfcf72dfdf
|
|
@ -70,10 +70,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
||||||
{
|
{
|
||||||
foreach (var resource in Resources)
|
foreach (var resource in Resources)
|
||||||
{
|
{
|
||||||
var resourceTypeMetadata = resource.GetMetadata("BootResourceType");
|
var resourceTypeMetadata = resource.GetMetadata("BootManifestResourceType");
|
||||||
if (!Enum.TryParse<ResourceType>(resourceTypeMetadata, out var resourceType))
|
if (!Enum.TryParse<ResourceType>(resourceTypeMetadata, out var resourceType))
|
||||||
{
|
{
|
||||||
throw new NotSupportedException($"Unsupported BootResourceType metadata value: {resourceTypeMetadata}");
|
throw new NotSupportedException($"Unsupported BootManifestResourceType metadata value: {resourceTypeMetadata}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.resources.TryGetValue(resourceType, out var resourceList))
|
if (!result.resources.TryGetValue(resourceType, out var resourceList))
|
||||||
|
|
@ -82,10 +82,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
||||||
result.resources.Add(resourceType, resourceList);
|
result.resources.Add(resourceType, resourceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
var resourceFileRelativePath = GetResourceFileRelativePath(resource);
|
var resourceName = GetResourceName(resource);
|
||||||
if (!resourceList.ContainsKey(resourceFileRelativePath))
|
if (!resourceList.ContainsKey(resourceName))
|
||||||
{
|
{
|
||||||
resourceList.Add(resourceFileRelativePath, $"sha256-{resource.GetMetadata("FileHash")}");
|
resourceList.Add(resourceName, $"sha256-{resource.GetMetadata("FileHash")}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,21 +99,16 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
||||||
serializer.WriteObject(writer, result);
|
serializer.WriteObject(writer, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetResourceFileRelativePath(ITaskItem item)
|
private static string GetResourceName(ITaskItem item)
|
||||||
{
|
{
|
||||||
// The build targets use RelativeOutputPath in the case of satellite assemblies, which
|
var name = item.GetMetadata("BootManifestResourceName");
|
||||||
// will have relative paths like "fr\\SomeAssembly.resources.dll". If RelativeOutputPath
|
|
||||||
// is specified, we want to use all of it.
|
|
||||||
var outputPath = item.GetMetadata("RelativeOutputPath");
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(outputPath))
|
if (string.IsNullOrEmpty(name))
|
||||||
{
|
{
|
||||||
// If RelativeOutputPath was not specified, we assume the item will be placed at the
|
throw new Exception($"No BootManifestResourceName was specified for item '{item.ItemSpec}'");
|
||||||
// root of whatever directory is used for its resource type (e.g., assemblies go in _bin)
|
|
||||||
outputPath = Path.GetFileName(item.GetMetadata("TargetOutputPath"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return outputPath.Replace('\\', '/');
|
return name.Replace('\\', '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable IDE1006 // Naming Styles
|
#pragma warning disable IDE1006 // Naming Styles
|
||||||
|
|
|
||||||
|
|
@ -83,17 +83,18 @@
|
||||||
<_BlazorCopyLocalPaths Remove="@(_BlazorManagedRuntimeAssemby)" />
|
<_BlazorCopyLocalPaths Remove="@(_BlazorManagedRuntimeAssemby)" />
|
||||||
|
|
||||||
<_BlazorOutputWithTargetPath Include="@(_BlazorCopyLocalPaths)">
|
<_BlazorOutputWithTargetPath Include="@(_BlazorCopyLocalPaths)">
|
||||||
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BlazorBootManifestResourceType>
|
<!-- This group is for satellite assemblies. We set the resource name to include a path, e.g. "fr\\SomeAssembly.resources.dll" -->
|
||||||
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BlazorBootManifestResourceType>
|
<BootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BootManifestResourceType>
|
||||||
|
<BootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BootManifestResourceType>
|
||||||
|
<BootManifestResourceName>%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</BootManifestResourceName>
|
||||||
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</TargetOutputPath>
|
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</TargetOutputPath>
|
||||||
<RelativeOutputPath>%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</RelativeOutputPath>
|
|
||||||
</_BlazorOutputWithTargetPath>
|
</_BlazorOutputWithTargetPath>
|
||||||
|
|
||||||
<_BlazorOutputWithTargetPath Include="@(_BlazorResolvedAssembly)">
|
<_BlazorOutputWithTargetPath Include="@(_BlazorResolvedAssembly)">
|
||||||
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BlazorBootManifestResourceType>
|
<BootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BootManifestResourceType>
|
||||||
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BlazorBootManifestResourceType>
|
<BootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BootManifestResourceType>
|
||||||
|
<BootManifestResourceName>%(FileName)%(Extension)</BootManifestResourceName>
|
||||||
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(FileName)%(Extension)</TargetOutputPath>
|
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(FileName)%(Extension)</TargetOutputPath>
|
||||||
<RelativeOutputPath>%(FileName)%(Extension)</RelativeOutputPath>
|
|
||||||
</_BlazorOutputWithTargetPath>
|
</_BlazorOutputWithTargetPath>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
@ -120,10 +121,10 @@
|
||||||
<_BlazorCopyLocalPaths Remove="@(_BlazorManagedRuntimeAssemby)" Condition="'%(Extension)' == '.dll'" />
|
<_BlazorCopyLocalPaths Remove="@(_BlazorManagedRuntimeAssemby)" Condition="'%(Extension)' == '.dll'" />
|
||||||
|
|
||||||
<_BlazorOutputWithTargetPath Include="@(_BlazorCopyLocalPaths)">
|
<_BlazorOutputWithTargetPath Include="@(_BlazorCopyLocalPaths)">
|
||||||
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BlazorBootManifestResourceType>
|
<BootManifestResourceType Condition="'%(Extension)' == '.dll'">assembly</BootManifestResourceType>
|
||||||
<BlazorBootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BlazorBootManifestResourceType>
|
<BootManifestResourceType Condition="'%(Extension)' == '.pdb'">pdb</BootManifestResourceType>
|
||||||
|
<BootManifestResourceName>%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</BootManifestResourceName>
|
||||||
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</TargetOutputPath>
|
<TargetOutputPath>$(_BlazorRuntimeBinOutputPath)%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</TargetOutputPath>
|
||||||
<RelativeOutputPath>%(_BlazorCopyLocalPaths.DestinationSubDirectory)%(FileName)%(Extension)</RelativeOutputPath>
|
|
||||||
</_BlazorOutputWithTargetPath>
|
</_BlazorOutputWithTargetPath>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
@ -144,13 +145,15 @@
|
||||||
<_DotNetWasmRuntimeFile Include="$(ComponentsWebAssemblyRuntimePath)*.wasm" />
|
<_DotNetWasmRuntimeFile Include="$(ComponentsWebAssemblyRuntimePath)*.wasm" />
|
||||||
<_BlazorOutputWithTargetPath Include="@(_DotNetWasmRuntimeFile)">
|
<_BlazorOutputWithTargetPath Include="@(_DotNetWasmRuntimeFile)">
|
||||||
<TargetOutputPath>$(_BlazorRuntimeWasmOutputPath)%(FileName)%(Extension)</TargetOutputPath>
|
<TargetOutputPath>$(_BlazorRuntimeWasmOutputPath)%(FileName)%(Extension)</TargetOutputPath>
|
||||||
<BlazorBootManifestResourceType>runtime</BlazorBootManifestResourceType>
|
<BootManifestResourceType>runtime</BootManifestResourceType>
|
||||||
|
<BootManifestResourceName>%(FileName)%(Extension)</BootManifestResourceName>
|
||||||
</_BlazorOutputWithTargetPath>
|
</_BlazorOutputWithTargetPath>
|
||||||
|
|
||||||
<_DotNetWasmJsFile Include="$(ComponentsWebAssemblyRuntimePath)*.js" />
|
<_DotNetWasmJsFile Include="$(ComponentsWebAssemblyRuntimePath)*.js" />
|
||||||
<_BlazorOutputWithTargetPath Include="@(_DotNetWasmJsFile)">
|
<_BlazorOutputWithTargetPath Include="@(_DotNetWasmJsFile)">
|
||||||
<TargetOutputPath>$(_BlazorRuntimeWasmOutputPath)%(FileName).$(TemporaryDotNetJsFileVersion)%(Extension)</TargetOutputPath>
|
<TargetOutputPath>$(_BlazorRuntimeWasmOutputPath)%(FileName).$(TemporaryDotNetJsFileVersion)%(Extension)</TargetOutputPath>
|
||||||
<BlazorBootManifestResourceType>runtime</BlazorBootManifestResourceType>
|
<BootManifestResourceType>runtime</BootManifestResourceType>
|
||||||
|
<BootManifestResourceName>%(FileName).$(TemporaryDotNetJsFileVersion)%(Extension)</BootManifestResourceName>
|
||||||
</_BlazorOutputWithTargetPath>
|
</_BlazorOutputWithTargetPath>
|
||||||
|
|
||||||
<_BlazorJSFile Include="$(_BlazorJSPath)" />
|
<_BlazorJSFile Include="$(_BlazorJSPath)" />
|
||||||
|
|
@ -329,9 +332,7 @@
|
||||||
Inputs="$(MSBuildAllProjects);@(_BlazorOutputWithTargetPath)"
|
Inputs="$(MSBuildAllProjects);@(_BlazorOutputWithTargetPath)"
|
||||||
Outputs="$(_BlazorBootJsonIntermediateOutputPath)">
|
Outputs="$(_BlazorBootJsonIntermediateOutputPath)">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<_BlazorBootResource Include="@(_BlazorOutputWithTargetPath->HasMetadata('BlazorBootManifestResourceType'))">
|
<_BlazorBootResource Include="@(_BlazorOutputWithTargetPath->HasMetadata('BootManifestResourceType'))" />
|
||||||
<BootResourceType>%(_BlazorOutputWithTargetPath.BlazorBootManifestResourceType)</BootResourceType>
|
|
||||||
</_BlazorBootResource>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<GetFileHash Files="@(_BlazorBootResource)" Algorithm="SHA256" HashEncoding="base64">
|
<GetFileHash Files="@(_BlazorBootResource)" Algorithm="SHA256" HashEncoding="base64">
|
||||||
|
|
|
||||||
|
|
@ -24,26 +24,22 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
||||||
{
|
{
|
||||||
CreateResourceTaskItem(
|
CreateResourceTaskItem(
|
||||||
ResourceType.assembly,
|
ResourceType.assembly,
|
||||||
itemSpec: Path.Combine("dir", "My.Assembly1.ext"), // Can specify item spec
|
name: "My.Assembly1.ext", // Can specify filename with no dir
|
||||||
relativeOutputPath: null,
|
|
||||||
fileHash: "abcdefghikjlmnopqrstuvwxyz"),
|
fileHash: "abcdefghikjlmnopqrstuvwxyz"),
|
||||||
|
|
||||||
CreateResourceTaskItem(
|
CreateResourceTaskItem(
|
||||||
ResourceType.assembly,
|
ResourceType.assembly,
|
||||||
itemSpec: "Ignored",
|
name: "dir\\My.Assembly2.ext2", // Can specify Windows-style path
|
||||||
relativeOutputPath: Path.Combine("dir", "My.Assembly2.ext2"), // Can specify relative path
|
|
||||||
fileHash: "012345678901234567890123456789"),
|
fileHash: "012345678901234567890123456789"),
|
||||||
|
|
||||||
CreateResourceTaskItem(
|
CreateResourceTaskItem(
|
||||||
ResourceType.pdb,
|
ResourceType.pdb,
|
||||||
itemSpec: "SomePdb.pdb",
|
name: "otherdir/SomePdb.pdb", // Can specify Linux-style path
|
||||||
relativeOutputPath: null,
|
|
||||||
fileHash: "pdbhashpdbhashpdbhash"),
|
fileHash: "pdbhashpdbhashpdbhash"),
|
||||||
|
|
||||||
CreateResourceTaskItem(
|
CreateResourceTaskItem(
|
||||||
ResourceType.runtime,
|
ResourceType.runtime,
|
||||||
itemSpec: "some-runtime-file",
|
name: "some-runtime-file", // Can specify path with no extension
|
||||||
relativeOutputPath: null,
|
|
||||||
fileHash: "runtimehashruntimehash")
|
fileHash: "runtimehashruntimehash")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -63,14 +59,14 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
||||||
Assert.Equal(ResourceType.assembly, resourceListKey);
|
Assert.Equal(ResourceType.assembly, resourceListKey);
|
||||||
Assert.Equal(2, resources.Count);
|
Assert.Equal(2, resources.Count);
|
||||||
Assert.Equal("sha256-abcdefghikjlmnopqrstuvwxyz", resources["My.Assembly1.ext"]);
|
Assert.Equal("sha256-abcdefghikjlmnopqrstuvwxyz", resources["My.Assembly1.ext"]);
|
||||||
Assert.Equal("sha256-012345678901234567890123456789", resources["dir/My.Assembly2.ext2"]); // For relative paths, we preserve the whole relative path, but use URL-style separators
|
Assert.Equal("sha256-012345678901234567890123456789", resources["dir/My.Assembly2.ext2"]); // Paths are converted to use URL-style separators
|
||||||
},
|
},
|
||||||
resourceListKey =>
|
resourceListKey =>
|
||||||
{
|
{
|
||||||
var resources = parsedContent.resources[resourceListKey];
|
var resources = parsedContent.resources[resourceListKey];
|
||||||
Assert.Equal(ResourceType.pdb, resourceListKey);
|
Assert.Equal(ResourceType.pdb, resourceListKey);
|
||||||
Assert.Single(resources);
|
Assert.Single(resources);
|
||||||
Assert.Equal("sha256-pdbhashpdbhashpdbhash", resources["SomePdb.pdb"]);
|
Assert.Equal("sha256-pdbhashpdbhashpdbhash", resources["otherdir/SomePdb.pdb"]);
|
||||||
},
|
},
|
||||||
resourceListKey =>
|
resourceListKey =>
|
||||||
{
|
{
|
||||||
|
|
@ -141,13 +137,11 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Build
|
||||||
return (BootJsonData)serializer.ReadObject(stream);
|
return (BootJsonData)serializer.ReadObject(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ITaskItem CreateResourceTaskItem(ResourceType type, string itemSpec, string relativeOutputPath, string fileHash)
|
private static ITaskItem CreateResourceTaskItem(ResourceType type, string name, string fileHash)
|
||||||
{
|
{
|
||||||
var mock = new Mock<ITaskItem>();
|
var mock = new Mock<ITaskItem>();
|
||||||
mock.Setup(m => m.ItemSpec).Returns(itemSpec);
|
mock.Setup(m => m.GetMetadata("BootManifestResourceType")).Returns(type.ToString());
|
||||||
mock.Setup(m => m.GetMetadata("TargetOutputPath")).Returns(itemSpec);
|
mock.Setup(m => m.GetMetadata("BootManifestResourceName")).Returns(name);
|
||||||
mock.Setup(m => m.GetMetadata("BootResourceType")).Returns(type.ToString());
|
|
||||||
mock.Setup(m => m.GetMetadata("RelativeOutputPath")).Returns(relativeOutputPath);
|
|
||||||
mock.Setup(m => m.GetMetadata("FileHash")).Returns(fileHash);
|
mock.Setup(m => m.GetMetadata("FileHash")).Returns(fileHash);
|
||||||
return mock.Object;
|
return mock.Object;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue