0

I am working on an old project in VS2017. My changes work fine in the development environment. But when I try to build to a server I get this error;

 Models\HoldingCompany.cs (21): Unexpected character '$'

The line affected is;

public override string ToString()
{
    return $"{this.Name} - {this.VatRegistrationNumber}";
}

Now it is true that the project was not originally written in C# 6. So what do I need to do to fix this? I have install the .Net framework 4.6 on the server I am deploying to. I have googled around trying to find what else I need to do but I have not come up with anything. I am using the original XAML Build definitions. This is my log file: https://1drv.ms/t/s!ArKf9AZKW_zWgQVzxitLQzMWjfSh

arame3333
  • 9,887
  • 26
  • 122
  • 205
  • 1
    And? What is that line? Why do you assume there is any problem with Visual Studio? You mention a build server. What does the *build server* use? I suspect it isn't using Visual Studio. Is it using the correct msbuild tools and compiler? Are you using an interpolated string perhaps? If the build tools on the server are old, or the language version is *not* at least 6, you'd get such an error – Panagiotis Kanavos Jun 01 '17 at 11:55
  • Updated the question. It is a new C#6 feature. The code was not originally C#6 so what do I need to do to fix this? It compiles and runs OK in development. – arame3333 Jun 01 '17 at 12:15
  • Install updated tools on the build server. And/or fix the settings to point to a newer SDK folder. You haven't explained which build server you use or how you build your project, so it's impossible to give more specific help – Panagiotis Kanavos Jun 01 '17 at 12:16
  • I am building from Team Explorer with TFS. The build server OS is windows server 2008 R2. – arame3333 Jun 01 '17 at 12:19
  • I have put in a link to my log file in the question. – arame3333 Jun 01 '17 at 12:29
  • Have a squiz at https://stackoverflow.com/a/32008030/34092 – mjwills Jun 01 '17 at 13:15

1 Answers1

0

You need the build server to use the correct build tools. in your case, you need C# 6 compiler to kick in, so I recommend doing the following steps: 1. Install VS2015 build tools (or above) 2. open your build definition (xaml template) and modify the ToolPath property to point at the correct folder in your server machine:

"C:\Program Files (x86)\MSBuild\14.0\Bin" (if VS2015) "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin" (if VS2017)

MOses
  • 71
  • 9