gpt4 book ai didi

c# - ASP.NET Core 1.0 RC2 中的 "The type or namespace name could not be found"

转载 作者:太空狗 更新时间:2023-10-29 21:04:11 24 4
gpt4 key购买 nike

我目前正在尝试 ASP.NET Core 1.0 RC2。我将其创建为 .NET Framework 项目(而不是 .NET Core 项目),并使用 .NET Framework 4.5 通过项目引用添加了对我们的 Models 库的引用:

"frameworks": {
"net46": {
"dependencies": {
"Project.Core": {
"target": "project"
},
"Project.DataAccess": {
"target": "project"
},
"Project.Encryption": {
"target": "project"
},
"Project.Models": {
"target": "project"
},
"Project.Resources": {
"target": "project"
}
}
}
},

现在向我的 View 添加模型指令时,出现以下错误:

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

它还在智能感知中显示:无法解析标记“Project.Models.User”无法解析符号“model”

我添加了一个项目引用,添加了一个using语句......仍然出现这个错误。这是为什么?

最佳答案

这是 RC2 中的错误 with an open issue . workaround在对我有用的问题讨论中:

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 执行此操作。

不确定是否4.6.1 and Update 2 is needed for both projects ,我只尝试过。

关于c# - ASP.NET Core 1.0 RC2 中的 "The type or namespace name could not be found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37589250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com