Azure站点:编译器错误消息:CS1056:意外字符"$" [英] Azure site : Compiler Error Message: CS1056: Unexpected character '$'

查看:140
本文介绍了Azure站点:编译器错误消息:CS1056:意外字符"$"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将应用程序托管在Azure中,但出现以下错误:

I am trying to host my application in Azure but getting below error:

编译器错误消息:CS1056:意外字符"$"版本信息:Microsoft .NET Framework 版本:4.0.30319 ;ASP.NET 版本:4.7.2623.0

Compiler Error Message: CS1056: Unexpected character '$' Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2623.0

我使用了使用'$'符号的字符串连接.在我的本地计算机上这可以正常工作,但是会引发编译错误.

I have used string concatenation using '$' sign. This works fine in my local machine, but throws the compilation error.

如何在Azure中设置正确的框架版本并避免上述异常.

How to set the right framework version in Azure and avoid the above exception.

谢谢,Sharath

Thanks, Sharath

推荐答案

Lex应该以正确的方向发送此消息,这一点值得赞扬.我想确认这是正确的路径,并解决了该问题并提供了更多详细信息.尝试将ASP.NET应用程序部署到Microsoft Azure App Service时遇到相同的问题和错误消息编译器错误消息:CS1056:意外字符'$'",实际上解决方案是将Roslyn编译器添加到项目中.默认情况下,Microsoft Azure App Service上使用的内置编译器似乎仅支持最多C#5语言功能,并且需要Roslyn来编译和使用C#6功能.请注意,我正在为我的项目部署CS文件,而不是已编译的DLL文件.

Lex should get credit for sending this in the correct direction. I want to confirm that this is the correct path and fixes the issue and give a little more detail. I was having the same issue and error message "Compiler Error Message: CS1056: Unexpected character '$'" when trying to deploy a ASP.NET app to Microsoft Azure App Service and indeed the solution was to add the Roslyn compiler to the project. It appears by default the built in compiler used on Microsoft Azure App Service only supports up to C# 5 language features and Roslyn is needed to compile and use the C# 6 features. Note I am deploying CS files for my project and not compiled DLL files.

在项目中安装Roslyn

  1. 在Visual Studio 2017中,选择工具"->"NuGet程序包管理器"->管理解决方案的NuGet程序包..."
  2. 从选项卡中选择浏览",然后搜索"Microsoft.CodeDom.Providers.DotNetCompilerPlatform"
  3. 从搜索结果中选择"Microsoft.CodeDom.Providers.DotNetCompilerPlatform",然后在右侧上方检查要添加到的项目名称,然后单击安装"按钮.
  4. 重建您的解决方案,并确保它仍在构建.

与Roslyn一起部署

  1. 您会注意到安装DotNetCompilerPlatform软件包后,会在Web.config文件中添加一个类似于以下内容的部分,请确保将该部分添加到已部署的Web.config中:

  1. You will notice installing the DotNetCompilerPlatform package added a section to your Web.config file that looks something like this, make sure this section gets added to your deployed Web.config:

  <system.codedom>
<compilers>
  <compiler language="c#;cs;csharp" extension=".cs"
    type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
    type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
</compilers></system.codedom>

  • 您还将注意到安装DotNetCompilerPlatform软件包并在构建解决方案时向Bin文件夹中添加了一些文件,请确保将这些文件(包括整个"roslyn"文件夹及其中的所有文件)放入您的Bin文件夹中部署:要部署的Bin文件夹文件
  • 这就是使用C#6语言功能恢复并运行我的网站所需要的一切,希望对您有所帮助.

    That was all it took to get my website back up and running with C# 6 language features, hope it helps.

    这篇关于Azure站点:编译器错误消息:CS1056:意外字符"$"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆