在网上下载了个AdminLTE 模板的VS插件,安装插件后,使用VS2019创建了一个测试项目。直接调试运行出现了错误:未能找到路径“E:\AdminLTETest\bin\roslyn\csc.exe”的一部分
“/”应用程序中的服务器错误。
未能找到路径“E:\AdminLTETest\bin\roslyn\csc.exe”的一部分。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.IO.DirectoryNotFoundException: 未能找到路径“E:\AdminLTETest\bin\roslyn\csc.exe”的一部分。
源错误:
执行当前 Web 请求期间生成了未经处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 |
堆栈跟踪:
[DirectoryNotFoundException: 未能找到路径“E:\AdminLTETest\bin\roslyn\csc.exe”的一部分。] System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +373 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +738 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +68 Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.get_CompilerName() +91 Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.FromFileBatch(CompilerParameters options, String[] fileNames) +658 Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames) +186 System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile(CompilerParameters options, String[] fileNames) +25 System.Web.Compilation.AssemblyBuilder.Compile() +985 System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +10223794 System.Web.Compilation.ApplicationBuildProvider.GetGlobalAsaxBuildResult(Boolean isPrecompiledApp) +10113866 System.Web.Compilation.BuildManager.CompileGlobalAsax() +47 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +274 [HttpException (0x80004005): 未能找到路径“E:\AdminLTETest\bin\roslyn\csc.exe”的一部分。] System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +65 System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +458 System.Web.Compilation.BuildManager.CallAppInitializeMethod() +35 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +605 [HttpException (0x80004005): 未能找到路径“E:\AdminLTETest\bin\roslyn\csc.exe”的一部分。] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10080656 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +99 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +263 |
问题出现的原因是因为您的项目中已经添加了以下软件包,所以您在生成项目的时候会尝试查找\ bin \ roslyn \ csc.exe。只需查看您项目中的packages.config文件,您就可以在其中找到它们:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0
Microsoft.Net.Compilers
解决方法:
1.先将多余的依赖库删掉,一般是
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0
Microsoft.Net.Compilers
在程序包管理器控制台中删除命令
-
PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
-
PM> Uninstall-package Microsoft.Net.Compilers
之后,您的web.config文件应自动更新。 如果没有,请在web.config文件中查找以下代码,如果找到,则删除这段代码。
1
2
3
4
5
6
|
<system.codedom> <compilers> <compiler language= "c#;cs;csharp" extension= ".cs" type= "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel= "4" compilerOptions= "/langversion:default /nowarn:1659;1699;1701" /> <compiler language= "vb;vbs;visualbasic;vbscript" extension= ".vb" type= "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel= "4" compilerOptions= "/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> </compilers> </system.codedom> |
为什么要删除Roslyn
If your project has Roslyn references and you are interested to deploy it no server, you will get unwanted errors on the website as many hosting providers still have not upgraded their servers and hence do not support Roslyn.To resolve this issue, you will need to remove the Roslyn compiler from the project template.