Browse Source

嵌入静态资源

master
大石头 2 years ago
parent
commit
f04ebc42d4
  1. 2
      GitCandy.Web/GitCandy.Web.csproj
  2. 18
      GitCandy.Web/Program.cs
  3. 2
      GitCandy.Web/Properties/PublishProfiles/FolderProfile.pubxml

2
GitCandy.Web/GitCandy.Web.csproj

@ -21,7 +21,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="LibGit2Sharp" Version="0.27.2" />
<PackageReference Include="NewLife.Core" Version="10.6.2023.1001" />
<PackageReference Include="NewLife.Cube.Core" Version="5.6.2023.1008" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.1001" />

18
GitCandy.Web/Program.cs

@ -1,10 +1,14 @@
using GitCandy.Git.Cache;
using System.Reflection;
using GitCandy.Git.Cache;
using GitCandy.Web.Base;
using GitCandy.Web.Services;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.FileProviders;
using NewLife;
using NewLife.Caching;
using NewLife.Cube;
using NewLife.Cube.Extensions;
using NewLife.Log;
using XCode;
@ -78,6 +82,18 @@ else
app.UseResponseCompression();
app.UseStaticFiles();
// 独立静态文件设置,魔方自己的静态资源内嵌在程序集里面
var env = app.Environment;
var options = new StaticFileOptions();
{
var embeddedProvider = new CubeEmbeddedFileProvider(Assembly.GetExecutingAssembly(), "GitCandy.Web.wwwroot");
if (!env.WebRootPath.IsNullOrEmpty() && Directory.Exists(env.WebRootPath))
options.FileProvider = new CompositeFileProvider(new PhysicalFileProvider(env.WebRootPath), embeddedProvider);
else
options.FileProvider = embeddedProvider;
}
app.UseStaticFiles(options);
// 使用魔方
app.UseCube(app.Environment);

2
GitCandy.Web/Properties/PublishProfiles/FolderProfile.pubxml

@ -14,7 +14,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>d1e514b2-2a79-4101-bb0d-ff2139ffd1ec</ProjectGuid>
<SelfContained>false</SelfContained>

Loading…
Cancel
Save