如何在Web应用程序ASPX代码页面之前使用C#7?

(这是我的问题“ 如何使用C#6与网站项目类型? ”的后续行动)

我正在尝试在Visual Studio 2017中使用C#7function。

为此,我在现有的ASP.NET WebForms 4.6.2应用程序中将Microsoft.Net.Compilers NuGet包更新到v2.0.0-rc4 。

它似乎从Visual Studio 2017内部运行良好。

当部署到我的网站时,我看到的只是一个黄色的死亡屏幕:

编译错误,错误代码255。

[详细编译输出]

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.6.1590.0

完整的编译器源太长了,无法在此发布(超过30k字符), 我已将其上传到Pastebin 。

我的问题:

有没有机会在ASP.NET WebForms Web应用程序中使用最新的Roslyn编译器?

更新1:

当然,我已经包含了Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet包和web.config条目, 如此处所述 。

       

我甚至试图将上面XML中的/langversion:6参数改为/langversion:7 ,没有不同的结果。

更新2:

对于在.cshtml Razor文件中使用ASP.NET MVC视图中的C#7function,问题和答案可能类似。

更新3:

我已经挖掘了事件日志,发现了这些(德国系统,对不起):

 Anwendung: csc.exe Frameworkversion: v4.0.30319 Beschreibung: Der Prozess wurde aufgrund einer unbehandelten Ausnahme beendet. Ausnahmeinformationen: System.IO.FileLoadException bei Microsoft.CodeAnalysis.CommandLine.BuildClient.GetCommandLineWindows(System.Collections.Generic.IEnumerable'1) bei Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run(System.Collections.Generic.IEnumerable'1, System.Collections.Generic.IEnumerable'1, Microsoft.CodeAnalysis.CommandLine.RequestLanguage, Microsoft.CodeAnalysis.CommandLine.CompileFunc, Microsoft.CodeAnalysis.IAnalyzerAssemblyLoader) bei Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(System.String[], System.String[]) bei Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(System.String[]) 

和:

 Exception information: Exception type: HttpCompileException Exception message: Eine externe Komponente hat eine Ausnahme ausgelöst. bei System.Web.Compilation.AssemblyBuilder.Compile() bei System.Web.Compilation.BuildProvidersCompiler.PerformBuild() bei System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) bei System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) bei System.Web.Compilation.BuildManager.CompileResourcesDirectory() bei System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() bei System.Web.Compilation.BuildManager.CallAppInitializeMethod() bei System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) 

最后,我解决了它。

在Sysinternals Process Monitor的帮助下,我发现csc.exe尝试加载一个名为“ csc.exe.config ”的文件,该文件不存在。

所以我将“csc.exe.config”文件从我当地网站的“bin \ roslyn”文件夹复制到我的实时网站的“bin \ roslyn”文件夹中。

在那之后,一切都按预期工作。

为了安全起见,我也以同样的方式复制了“csi.exe.config”,虽然看起来这不是必需的,至少在我的测试中。

(配置文件最初不存在的原因是我的发布脚本通常故意忽略配置文件而不覆盖现有配置)。