在.NET 4.5 Azure部署中找不到编译器可执行文件csc.exe

时间:2012-11-12 11:58:30

标签: asp.net asp.net-mvc azure .net-4.5 windows-server-2012

我有一个 并且有效的网站:

  • ASP.NET 4
  • MVC 3
  • 实体框架4.3
  • 在Azure网络角色中运行(我注意到它是osFamily =“1”,这很奇怪,因为我预计它会是2 - 但无论如何......)
  • Azure SDK 1.7

我已经升级了我的整个代码库,以便与大量新玩具保持同步。所以现在是:

  • ASP.NET 4.5
  • MVC 4(Razor 2)
  • 实体框架5
  • Azure配置设置为osFamily =“3”
  • Azure SDK 1.8(存储客户端库精心升级到2而不是1.7)

当我在分期中访问该网站时,我得到一个黄色的死亡屏幕,说无法找到编译器可执行文件csc.exe 。我的问题是为什么?

它在本地工作正常,在发布模式下也是如此。我转发了,实例肯定在运行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的第三方程序集(事实上我确定我这样做)但是当针对高于导入程序集中引用的.NET框架的.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

5 个答案:

答案 0 :(得分:3)

我有类似的问题。确保您的目标是正确的编译器。 我的目标是v4.5(但是应该有v4.0,因为现在有4.5个编译器)

在web.config中检查

<system.web>
 <compilation debug="true" defaultLanguage="c#" optimizeCompilations="true" targetFramework="4.0">
</system.web>

答案 1 :(得分:2)

是的,如果你有Server 2012,你肯定在运行Fx 4.5而不是4.0,因为它是一个就地升级。

要以粗体回答您的问题,给定的ASP.NET应用程序一次只能使用一个框架。如果您作为4.5站点运行,那么任何2.0 / 3.5程序集都应该按照框架4.5运行。

所以我怀疑那些较旧的程序集不是问题的根源。

话虽如此,我无法解释csc问题。它可能有助于包含您获得的确切错误消息以及一些堆栈跟踪。

答案 2 :(得分:1)

好的David Ebbo指出我正确的方向,我开始仔细审查Entity Framework Profiler。关于它有一个线程here

它在运行时创建一个程序集的东西,它似乎osfamily =“3”(Server 2012)不允许(它工作在osfamily =“2”(Server 2008 R2))。不再调试了,因为我不想在我的实时环境中使用探查器。删除EF Profiler使其工作。

答案 3 :(得分:0)

我发布这篇文章是为了帮助某人。我们使用框架的版本2动态编译代码,并且在仅.net 4的服务器上我们收到了错误消息。这只是因为我们对框架版本进行了硬编码:

var provider = new CSharpCodeProvider(new Dictionary<String, String> { { "CompilerVersion", "v3.5" } });

所以这只是一个删除它的问题 - 可能是因为它编译了当时正在使用的框架的任何版本。

var provider = new CSharpCodeProvider();

所以错误只是需要编译的代码,但是不存在所需框架版本的编译器。另一种选择只是为了确保安装.net 3.5功能。

答案 4 :(得分:0)

我在AWS Windows Server 2019映像中遇到类似的问题。

出于兼容性原因,CSharpCodeProvider设置为.Net 2.0版:

 new CSharpCodeProvider(new Dictionary<String, String> { { "CompilerVersion", "v2.0" } });

我已经安装了ASP 4.7功能,除此问题外,我的应用程序运行正常。
事实证明,计算机上未安装.Net 2.0。

解决方案-从Windows服务器管理控制台安装.Net 3.5功能。
.Net 3.5随附.Net 2.0