2017-03-09 26 views
4

(这是怎样的一个后续行动,我的问题“How to use C# 6 with Web Site project type?”的)如何在Web应用程序中使用C#7 ASPX代码 - 页面之前?

我试图用C#7特点与Visual Studio 2017年

对于这一点,我已经更新的Microsoft.Net.Compilers NuGet package to v2.0.0-rc4我现有的ASP.NET WebForms 4.6.2应用程序。

这似乎从Visual Studio中很好地工作2017年

当部署到我的网站,我看到的是死亡的黄屏:

编译器错误,错误代码255

[详细编译器输出]

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

完整的编译器源太长,无法在此张贴(超过30k字符),I've uploaded it to Pastebin

我的问题:

是否有任何机会,以使用ASP.NET WebForms的Web应用程序中最新的罗斯林编译器?

更新1:

当然,我已经包括了Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet包和web.config中的条目,as described here

<system.codedom> 
    <compilers> 
    <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /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.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" /> 
    </compilers> 
</system.codedom> 

我甚至试着在上面的XML没有不同的结果改变/langversion:6参数/langversion:7

更新2:

可能的问题和答案将是使用C#7特点从.cshtml剃刀内的文件ASP.NET MVC的观点中的相似。

更新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<System.String>)  
    bei Microsoft.CodeAnalysis.CommandLine.DesktopBuildClient.Run(System.Collections.Generic.IEnumerable'1<System.String>, System.Collections.Generic.IEnumerable'1<System.String>, 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)  
+1

错误代码255是一个流行的错误,[这里](http://stackoverflow.com/questions/33989211/another-strange-asp-net-error-the-compiler-failed-with-error-code- 255)是一对夫妇的建议 – maccettura

+1

@UweKeim啊,这个更新有一点帮助。 –

+1

如果您想使用C#7功能,您可能需要考虑从WebForms移动到MVC 6。 C#7的好处大于尝试使用WebForms工作的维护开销?切换堆栈可能会更好。 –

回答

3

最后,我解决了它。

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

因此,我将我本地网站的“bin \ roslyn”文件夹中的“csc.exe.config”文件复制到我的实时网站的“bin \ roslyn”文件夹中。

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

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

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

相关问题