公司项目容器化的需要, 小编研究将net framework
项目升级成net standard 2.0
,但是在打包上传nupkg
后,vs 的 nuget 插件不能识别依赖项,显示 Unsupported
。
小编怀疑是公司的 nuge server 版本太低的原因,于是通过 nuget 安装了最新的Nuget.Server
。 项目启动后,抛500错误:
[FileLoadException: 未能加载文件或程序集“NuGet.Server, Version=3.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)]
nuget.server.App_Start.NuGetODataConfig.Start() in C:\Project_Works\github.com\nuget.server\nugetserver\App_Start\NuGetODataConfig.cs:35
[TargetInvocationException: 调用的目标发生了异常。]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +87
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +101
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +73
WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +637
WebActivatorEx.ActivationManager.Run() +101
[InvalidOperationException: 针对类型 WebActivatorEx.ActivationManager 的应用程序预启动初始化方法 Run 引发了异常,显示下列错误消息: 调用的目标发生了异常。。]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures) +615
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +141
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
System.Web.Compilation.BuildManager.ExecutePreAppStart() +157
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +549
[HttpException (0x80004005): 针对类型 WebActivatorEx.ActivationManager 的应用程序预启动初始化方法 Run 引发了异常,显示下列错误消息: 调用的目标发生了异常。。]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10075596
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
因为nuget.server的程序包有问题, 最终小编下载了最新的源代码 Nuget.Server
本地编译运行正常,但是将发布后的web项目部署在服务器上, 项目运行返回500错误。
异常信息:
异常类型: NullReferenceException
异常消息: 未将对象引用设置到对象的实例。
在 NuGet.Server.ServiceResolverExtensions.Resolve[T](IServiceResolver resolver) 位置 C:\Project_Works\github.com\nuget\NuGet.Server\src\NuGet.Server\Core\ServiceResolverExtensions.cs:行号 11
在 ASP.default_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer)
在 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
在 System.Web.UI.Page.Render(HtmlTextWriter writer)
在 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
根据日志判断:项目启动时没有注入相关对象,导致在进行IOC 解析的时候,出现的空指针异常。
最终在 NuGetODataConfig.cs 文件中发现了错误原因。将if 断言删除,重新发布项目,Nuget.Server 运行成功,vs 也能正常识别依赖项
// The consuming project executes this logic with its own copy of this class. This is done with a .pp file that is
// added and transformed upon package install.
#if DEBUG
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(NuGet.Server.App_Start.NuGetODataConfig), "Start")]
#endif