Project builds fine with Visual Studio but fails from the command line

前端 未结 3 1990
独厮守ぢ
独厮守ぢ 2020-12-12 05:05

I have a solution which builds fine when running through Visual Studio 2015 but when I run from the command line I run into the error

error CS1056: Unexpected charac

相关标签:
3条回答
  • 2020-12-12 05:50

    That feature is a syntactic sugar is for C#6, try to install the latest version of the framework 4.6.2 https://www.microsoft.com/en-us/download/details.aspx?id=53345

    Then go to your Project properties and change on the Application option on Target framework to point to the latest. You don't need to change your code to replace the string interpolation with string.Format method to fix it.

    If you are still getting this error, is because, the compiler that is running your build is not the latest version of C#, try to add the Microsoft.Net.Compilers, from Nuget and compile again, that should resolve the issue. If you want to avoid to install this package, try to open your .csproj and take a look on the ToolsVersion that should be pointing to the version 12, then change it to 14, but make sure you have installed the latest version of the MSBuild from https://www.microsoft.com/en-us/download/details.aspx?id=48159 or go to C:\Program Files (x86)\MSBuild\14.0\Bin, there you should have this folder with the csc.exe compiler. If even then that doesn't resolve the issue, then try to follow this steps https://msdn.microsoft.com/en-us/library/bb383985.aspx. In my experience, just getting the package from Nuget solved the problem. Hope this helps

    0 讨论(0)
  • 2020-12-12 06:03

    $ can be converted to string.format.

    var CutOffTextFragment = deadLineTime.Deadline.Minute == 0 
                             ? 
                             string.Format("{0:htt}",deadLineTime.Deadline) 
                             : 
                             string.Format("{0:h:mmtt}", deadLineTime.Deadline);
    
    0 讨论(0)
  • 2020-12-12 06:09
    $"{deadLineTime.Deadline:htt}"
    

    is a syntax sugar for

    string.Format("{0:htt}", deadline.Deadline);
    

    same it goes for

    $"{deadLineTime.Deadline:h:mmtt}"
    

    as

    string.Format("{0:h:mmtt}", deadline.Deadline);
    

    try to replace them

    0 讨论(0)
提交回复
热议问题