在 .NET 4.5 Azure 部署中找不到編譯器執行檔 csc.exe
我有一個網站,該網站曾經有效:
- ASP.NET 4
- MVC 3
- 實體框架 4.3
- 以 Azure 網路角色執行(我注意到它是 osFamily=“1”,這很奇怪,因為我預計它是 2 - 但無論如何……)
- Azure SDK 1.7
我已經升級了我的整個程式碼庫,以與大量新玩具保持同步。所以現在是:
- ASP.NET 4.5
- MVC 4(剃刀 2)
- 實體框架 5
- Azure 配置設置為 osFamily=“3”
- Azure SDK 1.8(儲存客戶端庫煞費苦心地升級到 2 而不是 1.7)
當我在登台訪問該站點時,我得到一個黃色的當機螢幕,說Compiler executable file csc.exe can not be found。我的問題是為什麼?
它在本地也可以在發布模式下正常工作。我進行了遠端操作,並且這些實例肯定在執行 Windows Server 2012(因此 .NET 4.5??我發現很難說清楚,因為 .NET 4.5 替換了 .NET 4 文件夾中的 .NET 4 程序集)。
根據響應標頭,它肯定在執行 IIS 8,但有趣的是它聲稱 X-ASPNET-VERSION 是 4.xxxx。這對於 ASP.NET 4 站點是否正常?
更新:
我以 .NET 4 框架為目標並將 osFamily 更改為 2,它現在可以工作了。所以我現在懷疑我有一個使用 .NET 3.5 或 2 的第 3 方程序集(事實上我確信我這樣做了),但是當針對高於導入程序集中引用的框架的 .NET 框架時,肯定會使用更高版本的框架??
osFamily=“3” 僅安裝了 .NET 4 和 4.5,所以我想這是錯誤的原因,但我對目標的看法不正確嗎?我想使用 osFamily=“3” 我可以在這裡做什麼?
堆棧跟踪
[InvalidOperationException: Compiler executable file csc.exe cannot be found.] System.CodeDom.Compiler.RedistVersionInfo.GetCompilerPath(IDictionary`2 provOptions, String compilerExecutable) +8675071 Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames) +739 Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources) +3293761 Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources) +64 HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.Compile(String fileName, String[] sources, IEnumerable`1 assembliesToReference) +1252 HibernatingRhinos.Profiler.Appender.Util.GenerateAssembly.CompileAssembly(IEnumerable`1 sourcesResources, IEnumerable`1 assembliesToReference, String assemblyName) +118 HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.SetupDatabaseDefaultConnectionFactoryIfNeeded() +929 HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.SetupEntityFrameworkIntegration() +80 HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize(EntityFrameworkAppenderConfiguration configuration) +47 HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize() +73 Web4.MvcApplication.Application_Start() +17 [HttpException (0x80004005): Compiler executable file csc.exe cannot be found.] System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864673 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475 [HttpException (0x80004005): Compiler executable file csc.exe cannot be found.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881540 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722601
我有類似的問題。確保您的目標是正確的編譯器。我的目標是 v4.5(但應該有 v4.0,因為現在有 4.5 編譯器)
在 web.config 檢查
<system.web> <compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.0"> </system.web>
是的,如果您有 Server 2012,那麼您肯定執行的是 Fx 4.5 而不是 4.0,因為它是就地升級。
要以粗體字回答您的問題,給定的 ASP.NET 應用程序一次只能使用一個框架。如果您作為 4.5 站點執行,那麼任何 2.0/3.5 程序集都應該在框架 4.5 下執行。
所以我懷疑那些舊的程序集不是你問題的根源。
話雖如此,我無法解釋 csc 問題。包含您收到的確切錯誤消息以及一些堆棧跟踪可能會有所幫助。