[Static Web Assets] Various fixes (#10937)
* [Static Web Assets] Various fixes * Remove support for the embedded manifest. * Move static web assets directly into hosting
This commit is contained in:
parent
9336a6acd6
commit
7e162096a9
|
|
@ -3,10 +3,6 @@
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore
|
namespace Microsoft.AspNetCore
|
||||||
{
|
{
|
||||||
public static partial class StaticWebAssetsWebHostBuilderExtensions
|
|
||||||
{
|
|
||||||
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseStaticWebAssets(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { throw null; }
|
|
||||||
}
|
|
||||||
public static partial class WebHost
|
public static partial class WebHost
|
||||||
{
|
{
|
||||||
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder CreateDefaultBuilder() { throw null; }
|
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder CreateDefaultBuilder() { throw null; }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
// 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.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.HostFiltering;
|
using Microsoft.AspNetCore.HostFiltering;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Hosting.StaticWebAssets;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||||
|
|
@ -7,7 +7,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Microsoft.AspNetCore" />
|
<Reference Include="Microsoft.AspNetCore" />
|
||||||
<Reference Include="Microsoft.AspNetCore.TestHost" />
|
<Reference Include="Microsoft.AspNetCore.TestHost" />
|
||||||
<EmbeddedResource Include="Microsoft.AspNetCore.TestHost.StaticWebAssets.xml" LogicalName="Microsoft.AspNetCore.StaticWebAssets.xml" />
|
|
||||||
<Content Include="Microsoft.AspNetCore.TestHost.StaticWebAssets.xml" CopyToOutputDirectory="Always" />
|
<Content Include="Microsoft.AspNetCore.TestHost.StaticWebAssets.xml" CopyToOutputDirectory="Always" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
<Reference Include="Microsoft.Extensions.Configuration" />
|
<Reference Include="Microsoft.Extensions.Configuration" />
|
||||||
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
||||||
<Reference Include="Microsoft.Extensions.FileProviders.Physical" />
|
<Reference Include="Microsoft.Extensions.FileProviders.Physical" />
|
||||||
|
<Reference Include="Microsoft.Extensions.FileProviders.Composite" />
|
||||||
<Reference Include="Microsoft.Extensions.Hosting.Abstractions" />
|
<Reference Include="Microsoft.Extensions.Hosting.Abstractions" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging" />
|
<Reference Include="Microsoft.Extensions.Logging" />
|
||||||
<Reference Include="Microsoft.Extensions.Options" />
|
<Reference Include="Microsoft.Extensions.Options" />
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// 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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore
|
||||||
|
{
|
||||||
|
public static partial class StaticWebAssetsWebHostBuilderExtensions
|
||||||
|
{
|
||||||
|
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseStaticWebAssets(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) { throw null; }
|
||||||
|
}
|
||||||
|
}
|
||||||
namespace Microsoft.AspNetCore.Hosting
|
namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
public partial class DelegateStartup : Microsoft.AspNetCore.Hosting.StartupBase<Microsoft.Extensions.DependencyInjection.IServiceCollection>
|
public partial class DelegateStartup : Microsoft.AspNetCore.Hosting.StartupBase<Microsoft.Extensions.DependencyInjection.IServiceCollection>
|
||||||
|
|
@ -208,6 +215,14 @@ namespace Microsoft.AspNetCore.Hosting.Server.Features
|
||||||
public bool PreferHostingUrls { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
public bool PreferHostingUrls { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
||||||
|
{
|
||||||
|
public partial class StaticWebAssetsLoader
|
||||||
|
{
|
||||||
|
public StaticWebAssetsLoader() { }
|
||||||
|
public static void UseStaticWebAssets(Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
namespace Microsoft.Extensions.Hosting
|
namespace Microsoft.Extensions.Hosting
|
||||||
{
|
{
|
||||||
public static partial class GenericHostWebHostBuilderExtensions
|
public static partial class GenericHostWebHostBuilderExtensions
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<Reference Include="Microsoft.Extensions.Configuration" />
|
<Reference Include="Microsoft.Extensions.Configuration" />
|
||||||
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
||||||
<Reference Include="Microsoft.Extensions.FileProviders.Physical" />
|
<Reference Include="Microsoft.Extensions.FileProviders.Physical" />
|
||||||
|
<Reference Include="Microsoft.Extensions.FileProviders.Composite" />
|
||||||
<Reference Include="Microsoft.Extensions.Hosting.Abstractions" />
|
<Reference Include="Microsoft.Extensions.Hosting.Abstractions" />
|
||||||
<Reference Include="Microsoft.Extensions.Logging" />
|
<Reference Include="Microsoft.Extensions.Logging" />
|
||||||
<Reference Include="Microsoft.Extensions.Options" />
|
<Reference Include="Microsoft.Extensions.Options" />
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore
|
namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
||||||
{
|
{
|
||||||
// A file provider used for serving static web assets from referenced projects and packages during development.
|
// A file provider used for serving static web assets from referenced projects and packages during development.
|
||||||
// The file provider maps folders from referenced projects and packages and prepends a prefix to their relative
|
// The file provider maps folders from referenced projects and packages and prepends a prefix to their relative
|
||||||
|
|
@ -9,13 +9,20 @@ using System.Reflection;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore
|
namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
||||||
{
|
{
|
||||||
internal class StaticWebAssetsLoader
|
/// <summary>
|
||||||
|
/// Loader for static web assets
|
||||||
|
/// </summary>
|
||||||
|
public class StaticWebAssetsLoader
|
||||||
{
|
{
|
||||||
internal const string StaticWebAssetsManifestName = "Microsoft.AspNetCore.StaticWebAssets.xml";
|
internal const string StaticWebAssetsManifestName = "Microsoft.AspNetCore.StaticWebAssets.xml";
|
||||||
|
|
||||||
internal static void UseStaticWebAssets(IWebHostEnvironment environment)
|
/// <summary>
|
||||||
|
/// Configure the <see cref="IWebHostEnvironment"/> to use static web assets.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="environment"></param>
|
||||||
|
public static void UseStaticWebAssets(IWebHostEnvironment environment)
|
||||||
{
|
{
|
||||||
using (var manifest = ResolveManifest(environment))
|
using (var manifest = ResolveManifest(environment))
|
||||||
{
|
{
|
||||||
|
|
@ -49,24 +56,10 @@ namespace Microsoft.AspNetCore
|
||||||
|
|
||||||
internal static Stream ResolveManifest(IWebHostEnvironment environment)
|
internal static Stream ResolveManifest(IWebHostEnvironment environment)
|
||||||
{
|
{
|
||||||
// We plan to remove the embedded file resolution code path in
|
|
||||||
// a future preview.
|
|
||||||
Assembly assembly = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
assembly = Assembly.Load(environment.ApplicationName);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
if (assembly != null && assembly.GetManifestResourceNames().Any(a => a == StaticWebAssetsManifestName))
|
var assembly = Assembly.Load(environment.ApplicationName);
|
||||||
{
|
|
||||||
return assembly.GetManifestResourceStream(StaticWebAssetsManifestName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Fallback to physical file as we plan to use a file on disk instead of the embedded resource.
|
|
||||||
var filePath = Path.Combine(Path.GetDirectoryName(GetAssemblyLocation(assembly)), $"{environment.ApplicationName}.StaticWebAssets.xml");
|
var filePath = Path.Combine(Path.GetDirectoryName(GetAssemblyLocation(assembly)), $"{environment.ApplicationName}.StaticWebAssets.xml");
|
||||||
if (File.Exists(filePath))
|
if (File.Exists(filePath))
|
||||||
{
|
{
|
||||||
|
|
@ -80,6 +73,10 @@ namespace Microsoft.AspNetCore
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string GetAssemblyLocation(Assembly assembly)
|
internal static string GetAssemblyLocation(Assembly assembly)
|
||||||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore
|
namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
||||||
{
|
{
|
||||||
internal static class StaticWebAssetsReader
|
internal static class StaticWebAssetsReader
|
||||||
{
|
{
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Hosting.StaticWebAssets;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore
|
namespace Microsoft.AspNetCore
|
||||||
{
|
{
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
<StaticWebAssets Version="1.0">
|
||||||
|
<ContentRoot Path="/Path" BasePath="/BasePath" />
|
||||||
|
</StaticWebAssets>
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="$(SharedSourceRoot)test\SkipOnHelixAttribute.cs" />
|
<Compile Include="$(SharedSourceRoot)test\SkipOnHelixAttribute.cs" />
|
||||||
<Content Include="testroot\**\*" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
|
<Content Include="testroot\**\*" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="PreserveNewest" />
|
||||||
|
<Content Include="Microsoft.AspNetCore.Hosting.StaticWebAssets.xml" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Tests
|
namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
||||||
{
|
{
|
||||||
public class StaticWebAssetsFileProviderTests
|
public class StaticWebAssetsFileProviderTests
|
||||||
{
|
{
|
||||||
|
|
@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Tests
|
||||||
Path.GetDirectoryName(new Uri(typeof(StaticWebAssetsFileProviderTests).Assembly.CodeBase).LocalPath));
|
Path.GetDirectoryName(new Uri(typeof(StaticWebAssetsFileProviderTests).Assembly.CodeBase).LocalPath));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var file = provider.GetFileInfo("/_CONTENT/Microsoft.AspNetCore.TestHost.StaticWebAssets.xml");
|
var file = provider.GetFileInfo("/_CONTENT/Microsoft.AspNetCore.Hosting.StaticWebAssets.xml");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedResult, file.Exists);
|
Assert.Equal(expectedResult, file.Exists);
|
||||||
|
|
@ -9,7 +9,7 @@ using Microsoft.AspNetCore.Hosting.Internal;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Tests
|
namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
||||||
{
|
{
|
||||||
public class StaticWebAssetsLoaderTests
|
public class StaticWebAssetsLoaderTests
|
||||||
{
|
{
|
||||||
|
|
@ -58,27 +58,6 @@ namespace Microsoft.AspNetCore.Tests
|
||||||
Assert.Equal(originalRoot, environment.WebRootFileProvider);
|
Assert.Equal(originalRoot, environment.WebRootFileProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ResolveManifest_FindsEmbeddedManifestProvider()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var expectedManifest = @"<StaticWebAssets Version=""1.0"">
|
|
||||||
<ContentRoot Path=""/Path"" BasePath=""/BasePath"" />
|
|
||||||
</StaticWebAssets>
|
|
||||||
";
|
|
||||||
var originalRoot = new NullFileProvider();
|
|
||||||
var environment = new HostingEnvironment()
|
|
||||||
{
|
|
||||||
ApplicationName = typeof(StaticWebAssetsReaderTests).Assembly.GetName().Name
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var manifest = StaticWebAssetsLoader.ResolveManifest(environment);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.Equal(expectedManifest, new StreamReader(manifest).ReadToEnd());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ResolveManifest_ManifestFromFile()
|
public void ResolveManifest_ManifestFromFile()
|
||||||
{
|
{
|
||||||
|
|
@ -90,7 +69,7 @@ namespace Microsoft.AspNetCore.Tests
|
||||||
|
|
||||||
var environment = new HostingEnvironment()
|
var environment = new HostingEnvironment()
|
||||||
{
|
{
|
||||||
ApplicationName = "Microsoft.AspNetCore.TestHost"
|
ApplicationName = "Microsoft.AspNetCore.Hosting"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -8,7 +8,7 @@ using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Tests
|
namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
||||||
{
|
{
|
||||||
public class StaticWebAssetsReaderTests
|
public class StaticWebAssetsReaderTests
|
||||||
{
|
{
|
||||||
Loading…
Reference in New Issue