2017-09-19 32 views
1

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; 
    } 
} 

答えて

0

私はちょうどnetcoreapp2.0にnetcoreapp1.1から私の解決策プロジェクトを更新した後、同様の問題がありました。私はVisual Studio 2017を使用しています。私は更新を行う必要がありました。

コントロールパネル - >プログラムと機能 - > Microsoft Visual Studio 2017 右クリックし、「変更」を選択します。許可し、更新するよう促されました。

その後、すべてが機能し始めました。これはWeb APIプロジェクトのみに適用され、cshtmlに適用されるかどうかは不明です。

関連する問題