在 Controller 中找不到来自 NuGet 包引用的命名空间
Namespace from NuGet package reference canot be found in Controller
我正在尝试在 ASP.Net 5 Beta 3 中使用 Aftership SDK,但即使我已将其添加为依赖项,我仍然会收到以下错误:
Microsoft.Framework.Runtime.Roslyn.RoslynCompilationException:
~/myproject/Controllers/PackagesController.cs(5,7):
error CS0246: The type or namespace name 'Aftership' could not be
found (are you missing a using directive or an assembly reference?)
所有相关的 SO 问题都说要从 packages.json
文件中删除 CoreCLR 框架引用,但我已经这样做了:
{
"webroot": "wwwroot",
"exclude": "wwwroot/**/*.*",
"dependencies": {
"Microsoft.AspNet.Server.IIS":"1.0.0-beta3",
"Microsoft.AspNet.Mvc": "6.0.0-beta3",
"Microsoft.AspNet.Hosting": "1.0.0-beta3",
"Microsoft.AspNet.Security.Cookies": "1.0.0-beta3",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta3",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta3",
"Kestrel": "1.0.0-beta3",
"Aftership": "4.0.8"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
},
"frameworks": {
"aspnet50": { }
}
}
我的控制器代码是标准的:
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc;
using Mirror.Models;
using Aftership;
using System.Linq;
namespace Mirror.Controllers
{
public class PackagesController : Controller
{
public IActionResult Index()
{
return View(GetPackages());
}
private List<Package> GetPackages()
{
var packages = new List<Package>();
var conn = new ConnectionAPI("...");
...
}
}
}
在 运行 kpm restore
之后,我可以在我的包目录下找到该库:~/.k/packages/Aftership/4.0.8/lib/net40/Aftership-API.exe
问题可能是由于 Aftership 库提供了一个 exe 而不是适当命名的 Aftership.dll
?我尝试重命名文件,但没有成功...
最后我自己将它编译成一个 DLL(这意味着我也可以针对 .Net 4.5)并为它构建一个私有的 NuGet 包。感谢开源软件!
感谢@Elion 确认 DLL 是唯一受支持的参考。
我正在尝试在 ASP.Net 5 Beta 3 中使用 Aftership SDK,但即使我已将其添加为依赖项,我仍然会收到以下错误:
Microsoft.Framework.Runtime.Roslyn.RoslynCompilationException:
~/myproject/Controllers/PackagesController.cs(5,7):
error CS0246: The type or namespace name 'Aftership' could not be
found (are you missing a using directive or an assembly reference?)
所有相关的 SO 问题都说要从 packages.json
文件中删除 CoreCLR 框架引用,但我已经这样做了:
{
"webroot": "wwwroot",
"exclude": "wwwroot/**/*.*",
"dependencies": {
"Microsoft.AspNet.Server.IIS":"1.0.0-beta3",
"Microsoft.AspNet.Mvc": "6.0.0-beta3",
"Microsoft.AspNet.Hosting": "1.0.0-beta3",
"Microsoft.AspNet.Security.Cookies": "1.0.0-beta3",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta3",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta3",
"Kestrel": "1.0.0-beta3",
"Aftership": "4.0.8"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
},
"frameworks": {
"aspnet50": { }
}
}
我的控制器代码是标准的:
using System;
using System.Collections.Generic;
using Microsoft.AspNet.Mvc;
using Mirror.Models;
using Aftership;
using System.Linq;
namespace Mirror.Controllers
{
public class PackagesController : Controller
{
public IActionResult Index()
{
return View(GetPackages());
}
private List<Package> GetPackages()
{
var packages = new List<Package>();
var conn = new ConnectionAPI("...");
...
}
}
}
在 运行 kpm restore
之后,我可以在我的包目录下找到该库:~/.k/packages/Aftership/4.0.8/lib/net40/Aftership-API.exe
问题可能是由于 Aftership 库提供了一个 exe 而不是适当命名的 Aftership.dll
?我尝试重命名文件,但没有成功...
最后我自己将它编译成一个 DLL(这意味着我也可以针对 .Net 4.5)并为它构建一个私有的 NuGet 包。感谢开源软件!
感谢@Elion 确认 DLL 是唯一受支持的参考。