AspNetCoreコントローラとビューを、Microsoft.AspNetCore.Mvcパッケージを参照する独立した.net標準2.0プロジェクトに分割しました。コントローラが正常に動作し、ビューcshtmlが見つかります。AspNetCoreランタイムエラー "定義済みのタイプ 'System.String'が定義またはインポートされていません。
しかし、実行時CSHTMLのコンパイル時に、例外が多数のいくつかの基本的なタイプを示す投げたがなど可能System.String、System.Typeを、System.Void、未定義た
エラー
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HL7VCA4VNMOK", Request id "0HL7VCA4VNMOK:00000001": An unhandled exception was thrown by the application.
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException: One or more compilation failures occurred:
bbnqa23f.htw(4,62): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
bbnqa23f.htw(4,81): error CS0518: Predefined type 'System.String' is not defined or imported
bbnqa23f.htw(4,109): error CS0518: Predefined type 'System.Type' is not defined or imported
bbnqa23f.htw(4,11): error CS0518: Predefined type 'System.Void' is not defined or imported
bbnqa23f.htw(8,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
bbnqa23f.htw(9,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
bbnqa23f.htw(10,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
bbnqa23f.htw(11,11): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
この問題の解決方法を知っている人はいますか?
Index.cshtml
@{
ViewData["Title"] = "Home Page";
}
This is view
Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"]</title>
</head>
<body>
@RenderBody()
</body>
</html>
コントローラ
public class HomeController : Controller
{
[HttpGet]
public IActionResult Index()
{
return View();
}
}
Startup.cs
public class Startup : IStartup
{
IConfigurationRoot cfg;
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddEnvironmentVariables();
cfg = builder.Build();
}
public void Configure(IApplicationBuilder app)
{
app
.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = true,
FileProvider = new PhysicalFileProvider(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "static")),
RequestPath = new PathString("/s")
})
.UseSession()
.UseMvc(route =>
{
route.MapRoute(name: "default", template: "{controller}/{action}", defaults: new { controller = "home", action = "index" });
})
.UseSwagger(so =>
{
})
.UseSwaggerUI(suo =>
{
suo.SwaggerEndpoint("/swagger/v1/swagger.json", "Api Document");
});
}
public IServiceProvider ConfigureServices(IServiceCollection services)
{
var rlt = services
.AddLogging(config =>
{
config.AddConsole();
})
.AddSession()
.AddMvc(mo =>
{
mo.SslPort = 443;
})
.AddControllersAsServices()
.Services
.AddSwaggerGen(so =>
{
so.SwaggerDoc("v1", new Info { Title = "API Document", Version = "v1" });
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Biz.xml");
Console.WriteLine(path);
so.IncludeXmlComments(path);
})
.BuildServiceProvider();
;
return rlt;
}
}