我正在尝试运行简单的ASP.NET Web API项目(.NET Framework 4.5.2)。它使用的是存储在.dll文件中的类库。在使用“带有操作的API控制器,使用实体框架”添加控制器时,我收到了此错误:
A type with the name [A].[B] does not exist
in Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
in Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
in Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
in Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
A
是我的CL的主命名空间,而B
是我想要从中创建控制器的类。
这个问题的解决方案是什么?
答案 0 :(得分:0)
也许这不是这个问题的真正答案,但我从包含类库到dll变为包括整个类库项目,现在它可以工作。
答案 1 :(得分:0)
Visual Studio 不喜欢项目引用和引用的项目引用之间的混合/次要版本。
因为 My Domain 和 Data 类位于不同的项目中,需要将这些引用同步到 5.0.2。并从 Web.Api 项目中删除了这些库项目中已经包含的所有引用。
import re, inspect
FUNC_BODY = re.compile('^(?P<tabs>[\t ]+)?def (?P<name>[a-zA-Z0-9_]+)([^\n]+)\n(?P<body>(^([\t ]+)?([^\n]+)\n)+)', re.M)
class Source(object):
@staticmethod
def investigate(focus:object, strfocus:str) -> str:
with open(inspect.getsourcefile(focus), 'r') as f:
for m in FUNC_BODY.finditer(f.read()):
if m.group('name') == strfocus:
tabs = m.group('tabs') if not m.group('tabs') is None else ''
return f"{tabs}'''\n{m.group('body')}{tabs}'''"
def decorator(func):
def inner():
print("I'm decorated")
func()
return inner
@decorator
def test():
a = 5
b = 6
return a+b
print(Source.investigate(test, 'test'))
在我发现我的工作是使用 cli 之前
<块引用>dotnet-aspnet-codegenerator controller -name CustomerController -api -m Customer -dc AccountContextApi -outDir Controllers