ASP.NET Core 2.1 提供来自另一个项目的静态文件
ASP.NET Core 2.1 Serve static files from another project
我正在尝试使用 ASP.NET Core 2.1 后端服务 API 和 Angular 前端。 Startup.cs
在项目 MyApp.Api
中。我希望从另一个项目 MyApp.FrontEnd
.
的 wwwroot 中提取我的静态文件
我看过里面描述了下面的方法
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new EmbeddedFileProvider(
assembly: Assembly.Load(new AssemblyName("OpenIddict.Assets")),
baseNamespace: "OpenIddict.Assets")
});
但是,当我尝试用我的项目名称替换 "OpenIddicts.Assets" 时,出现以下错误:
FTL Application startup exception
System.IO.FileNotFoundException: Could not load file or assembly
'MyApp.FrontEnd, Culture=neutral, PublicKeyToken=null'.
The system cannot find the file specified.
File name: 'MyApp.FrontEnd, Culture=neutral, PublicKeyToken=null'
上面链接的 post 中引用的 GitHub 存储库似乎不再存在。我想我错过了一个相当明显的地方。任何帮助将不胜感激。
MyApp.FrontEnd.dll
必须存在于输出文件夹中。如果您发布主项目(参考 MyApp.FrontEnd
),那么一切都应该有效。
如果您可以从程序集中访问某些类型,那么您可以尝试 Assembly.GetAssembly(type)
而不是 Assembly.Load(...)
,即
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new EmbeddedFileProvider(
assembly: Assembly.GetAssembly(typeof(SomeClassFromAssembly)),
baseNamespace: "OpenIddict.Assets")
});
我正在尝试使用 ASP.NET Core 2.1 后端服务 API 和 Angular 前端。 Startup.cs
在项目 MyApp.Api
中。我希望从另一个项目 MyApp.FrontEnd
.
我看过
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new EmbeddedFileProvider(
assembly: Assembly.Load(new AssemblyName("OpenIddict.Assets")),
baseNamespace: "OpenIddict.Assets")
});
但是,当我尝试用我的项目名称替换 "OpenIddicts.Assets" 时,出现以下错误:
FTL Application startup exception System.IO.FileNotFoundException: Could not load file or assembly 'MyApp.FrontEnd, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. File name: 'MyApp.FrontEnd, Culture=neutral, PublicKeyToken=null'
上面链接的 post 中引用的 GitHub 存储库似乎不再存在。我想我错过了一个相当明显的地方。任何帮助将不胜感激。
MyApp.FrontEnd.dll
必须存在于输出文件夹中。如果您发布主项目(参考 MyApp.FrontEnd
),那么一切都应该有效。
如果您可以从程序集中访问某些类型,那么您可以尝试 Assembly.GetAssembly(type)
而不是 Assembly.Load(...)
,即
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new EmbeddedFileProvider(
assembly: Assembly.GetAssembly(typeof(SomeClassFromAssembly)),
baseNamespace: "OpenIddict.Assets")
});