"类型或命名空间名称找不到"在ASP.NET 1.0的核心RC2 [英] "The type or namespace name could not be found" in ASP.NET Core 1.0 RC2
问题描述
我目前正在试用ASP.NET Core 1.0 RC2。我创建了它作为一个.NET框架项目(而不是一个.NET核心项目),并添加引用到我们的模型
库,使用.NET Framework 4.5,通过项目引用:
I'm currently trying ASP.NET Core 1.0 RC2. I've created it as a .NET Framework project (as opposed to a .NET Core project) and added references to our Models
library, using .NET Framework 4.5, via a project reference:
"frameworks": {
"net46": {
"dependencies": {
"Project.Core": {
"target": "project"
},
"Project.DataAccess": {
"target": "project"
},
"Project.Encryption": {
"target": "project"
},
"Project.Models": {
"target": "project"
},
"Project.Resources": {
"target": "project"
}
}
}
},
现在在我的视图中添加模型指令时,会发生以下错误: / p>
Now when adding a model directive to my view, the following error occurs:
@model System.Collections.Generic.List<Project.Models.User>
The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)
public class _Views_Home_Index_cshtml : Microsoft.AspNetCore.Mvc.Razor.RazorPage<System.Collections.Generic.List<Project.Models.User>>
The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)
public Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<System.Collections.Generic.List<Project.Models.User>> Html { get; private set; }
它也显示在intellisense中:无法解析标签'Project.Models.User' / em>无法解析符号模型
It also displays in intellisense: Cannot resolve tag 'Project.Models.User' and Cannot resolve symbol 'model'
我已添加项目引用,添加了using语句...仍然出现此错误中。为什么呢?
I have added a project reference, added a using statement... Still this error occurs. Why is that?
推荐答案
这是RC2中的一个错误有一个开放问题。问题讨论中对我有效的解决方法是:
This is a bug in RC2 with an open issue. A workaround in the issue discussion that works for me is:
services.AddMvc()
.AddRazorOptions(options =>
{
var previous = options.CompilationCallback;
options.CompilationCallback = context =>
{
previous?.Invoke(context);
context.Compilation = context.Compilation.AddReferences(MetadataReference.CreateFromFile(typeof(MyClass).Assembly.Location));
};
});
在您的示例中,您需要为 Project.Models .User
。
In your example, you'd need to do this for Project.Models.User
.
不确定 4.6。 1和更新2需要两个项目,我只尝试了。
这篇关于"类型或命名空间名称找不到"在ASP.NET 1.0的核心RC2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!