2016-05-30 51 views
2

我有一個新的ASP.NET核心RC2內置如下:存儲在.NET框架的DLL庫參考從ASP.NET的核心觀點一NET461 DLL模型類型

  • 型號461
  • 網絡是MVC核心1.0完整的框架 - 不是基於核心框架

時參考的DLL庫的型號和運行項目,我得到了以下錯誤:

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately. Generated Code The type or namespace name 'Data' does not exist in the namespace 'ADMA.EWRS' (are you missing an assembly reference?) 23. public class _Views_Murad_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage> The type or namespace name 'Data' does not exist in the namespace 'ADMA.EWRS' (are you missing an assembly reference?) 39. public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper> Html { get; private set; } An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately. Generated Code The type or namespace name 'Data' does not exist in the namespace 'ADMA.EWRS' (are you missing an assembly reference?) 23. public class _Views_Murad_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage> The type or namespace name 'Data' does not exist in the namespace 'ADMA.EWRS' (are you missing an assembly reference?) 39. public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper> Html { get; private set; }

配置Project.json如下:

{ 
    "dependencies": { 
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final", 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final", 
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final", 
    "Microsoft.AspNetCore.Razor.Tools": { 
     "version": "1.0.0-preview1-final", 
     "type": "build" 
    }, 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final", 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final", 
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final", 
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final", 
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final", 
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final", 
    "Microsoft.AspNetCore.Authorization": "1.0.0-rc2-final", 
    "Microsoft.AspNetCore.Authentication": "1.0.0-rc2-final", 
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final", 
    "Microsoft.AspNetCore.Session": "1.0.0-rc2-final", 
    "ADMA.EWRS.Web.Security": "1.0.0-*" 
    }, 

    "tools": { 
    "Microsoft.AspNetCore.Razor.Tools": { 
     "version": "1.0.0-preview1-final", 
     "imports": "portable-net45+win8+dnxcore50" 
    }, 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": { 
     "version": "1.0.0-preview1-final", 
     "imports": "portable-net45+win8+dnxcore50" 
    } 
    }, 

    "frameworks": { 
    "net461": { 
     "dependencies": { 
     "ADMA.EWRS.BizDomain": { 
      "target": "project" 
     }, 
     "ADMA.EWRS.Data.Models": { 
      "target": "project" 
     } 
     } 
    } 
    }, 


    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "Views", 
     "appsettings.json", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ], 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 
} 

Solution Explorer

X Project

+0

您的xproj文件是否有用於ADMA.EWRS.Data.Models項目的ProjectReference條目? – KTCO

+0

是的,請檢查附加圖像2 –

+0

我的意思是,如果您在記事本中打開ADMA.EWRS.Web.Core.xproj,您是否看到ADMA.EWRS.Data.Models項目的ProjectReference條目?如果缺失,那可能是問題所在。 – KTCO

回答

1

添加刀片選項,如下面的代碼後問題:

services.AddMvc().// Murad Add this for RC2, remove it if release 1.0 after June 
       AddRazorOptions(options => 
      { 
       var previous = options.CompilationCallback; 
       options.CompilationCallback = context => 
       { 
        previous?.Invoke(context); 
        context.Compilation = context.Compilation.AddReferences(Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(typeof(ADMA.EWRS.Data.Models.Murad).Assembly.Location)); 
       }; 
      }); 

      //var myAssemblies = AppDomain.CurrentDomain.GetAssemblies().Select(x => Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(x.Location)).ToList(); 
      //services.Configure((Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions options) => 
      //{ 
      // var previous = options.CompilationCallback; 
      // options.CompilationCallback = (context) => 
      // { 
      //  previous?.Invoke(context); 

      //  context.Compilation = context.Compilation.AddReferences(myAssemblies); 
      // }; 
      //}); 

檢查

https://github.com/aspnet/Mvc/issues/4686