一、前言
- 本篇文章解决办法适用范围?
- 错误提示为找不到roslyn编译器
(通常项目为VS2107创建会碰到这个问题)
二、问题分析
- 错误信息
System.IO.FileNotFoundException
Could not find file "/mysiteroot/bin\roslyn\csc.exe".
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): mscorlib.
Exception stack trace:
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0019c] in <3753d1715b8842d8bb13a30db0388b60>:0
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <3753d1715b8842d8bb13a30db0388b60>:0
at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
at System.IO.File.OpenRead (System.String path) [0x00000] in <3753d1715b8842d8bb13a30db0388b60>:0
at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.get_CompilerName () [0x00019] in <13231d2f854e4437bf639e10b63dd37e>:0
at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.FromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00168] in <13231d2f854e4437bf639e10b63dd37e>:0
at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.CompileAssemblyFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00048] in <13231d2f854e4437bf639e10b63dd37e>:0
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromFile (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00006] in <1d7393d853954016b607e8e348b00ad1>:0
at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath, System.CodeDom.Compiler.CompilerParameters options) [0x0029f] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.Compilation.AssemblyBuilder.BuildAssembly (System.Web.VirtualPath virtualPath) [0x00008] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.Compilation.BuildManager.GenerateAssembly (System.Web.Compilation.AssemblyBuilder abuilder, System.Web.Compilation.BuildProviderGroup group, System.Web.VirtualPath vp, System.Boolean debug) [0x00202] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, System.Boolean debug) [0x00106] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.Compilation.BuildManager.Build (System.Web.VirtualPath vp) [0x00058] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.Compilation.BuildManager.GetCompiledType (System.Web.VirtualPath virtualPath) [0x00037] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.Compilation.BuildManager.GetCompiledType (System.String virtualPath) [0x00006] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.HttpApplicationFactory.InitType (System.Web.HttpContext context) [0x00219] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.HttpApplicationFactory.GetApplication (System.Web.HttpContext context) [0x00018] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
at System.Web.HttpRuntime.Process (System.Web.HttpWorkerRequest req) [0x00052] in <8fe6d5c66f4c4efb8f2d2af3ae3c8850>:0
实际错误诱因:
Could not find file "/mysiteroot/bin\roslyn\csc.exe".
也就是站点启动时找不到站点根目录bin文件夹中的roslyn编译器
由于Mono不兼容roslyn那我们只能考虑改用msbuild
一个项目的编译信息是由.csproj文件存储的,那具体怎么解决这个问题
就只能从这个文件入手
分析.csproj文件发现跟roslyn相关的配置
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />
也就是说项目中安装了如下两个package:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers
三、解决办法
#通过nuget卸载这两个package即可
uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
uninstall-package Microsoft.Net.Compilers