0

I have a requirement to work with Jenkins for Continues integration, in my code I have written code like

throw new ArgumentNullException($"The {nameof(Id)} cannot be null");

If I build the application it is building successfully but if I build this same application using MsBuild(or) Jenkins,

I am getting error like

Web\WebSharedHelper.cs "C:\WINDOWS\TEMP\.NETFramework,Version=v4.5.2.AssemblyAttributes.cs"
Security\ApiUserToken.cs(46,32): error CS1056: Unexpected character '$' [C:\Program Files (x86)\Jenkins\workspace\OssiaCICD\common\trunk\Cota.Common.Core\Cota.Common.Core.csproj]
Security\ApiUserToken.cs(58,32): error CS1056: Unexpected character '$' [C:\Program Files (x86)\Jenkins\workspace\OssiaCICD\common\trunk\Cota.Common.Core\Cota.Common.Core.csproj]
Security\ApiUserToken.cs(62,26): error CS1056: Unexpected character '$' [C:\Program Files (x86)\Jenkins\workspace\OssiaCICD\common\trunk\Cota.Common.Core\Cota.Common.Core.csproj]
Done Building Project "C:\Program Files (x86)\Jenkins\workspace\OssiaCICD\common\trunk\Cota.Common.Core\Cota.Common.Core.csproj" (default targets) -- FAILED.

I am using v4.0.30319 FrameWork for MSBuild.

Sivamohan Reddy
  • 436
  • 1
  • 8
  • 26
  • If you build it, it's successfully, but if you build it, you get an error? Could you please specify the difference between those two builds? I guess the compiler used for the second build does not know C#6 (string interpolation)? – René Vogt Mar 28 '17 at 09:10
  • Take in account that in order to use String interpolation you must work on C#6 and forth – apomene Mar 28 '17 at 09:11
  • 1
    Possible duplicate of [Error CS1056: Unexpected character '$' running the msbuild on a tfs continuous integration process](http://stackoverflow.com/questions/42932577/error-cs1056-unexpected-character-running-the-msbuild-on-a-tfs-continuous-i) – Dierig Patrick Mar 28 '17 at 09:11
  • I am building from visual studio it builds successfully. but if I build from command prompt using MSBuild I am getting error. I know the problem with version only but why and How to resolve that issue. – Sivamohan Reddy Mar 28 '17 at 09:14
  • I have gone through this link, but it is totally different question hence I request to keep this question as it is. – Sivamohan Reddy Mar 28 '17 at 09:29

6 Answers6

10

I fixed the problem by using C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe instead of C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe on jenkins.

serkanh
  • 191
  • 1
  • 3
  • Using MSBuild.exe from Visual Studio build tools as @serkanh mentioned was the fix for me, except I'm using version 15.0 (VS2017). It also corrected warnings relating to the ReportViewer control and version numbers. (The build was done through Jenkins.) – Andy S. Mar 22 '19 at 18:44
7

The $ string interpolation symbol is only available in C# 6+. Make sure that you are compiling with C#6. C#6 is supported in MSBuild 14.0+.

George Richardson
  • 1,228
  • 12
  • 19
0

If your Visual Studio version is older than 2015 then by default the IDE does not provide C#6 which you need to compile it.

Use Visual Studio 2015 or newer. It should resolve problem.

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Artsiom Che
  • 122
  • 8
  • Thank you for your Quick reply but I am not getting any error using visual studio problem with msbuild only – Sivamohan Reddy Mar 28 '17 at 09:18
  • So probably the msbuild version is too old: [See this post](http://stackoverflow.com/questions/28921701/does-c-sharp-6-0-work-for-net-4-0#answer-28921749) – Rik Mar 28 '17 at 09:24
0

This problem can be resolved in a couple of ways. Please check my answer here for the first option:

1st https://stackoverflow.com/a/42931980/819153

2nd option - Try to install the visual studio on the tfs where you run the continuous integration, that will save you a lot of headaches

Zinov
  • 3,817
  • 5
  • 36
  • 70
0

As suggested by a gentleman here, I used C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe instead of C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe over the build agent. And it helped me.

I have MSBuild Version 14.0.25420.1 in the build agent.

Pavan Nayakanti
  • 301
  • 3
  • 3
0

In my case, worked below..

Removed langversion nodes and added netstandard reference to csproj for msbuild to work with Jenkins or msbuild command.

commented below lines in .csproj file.

<!--    <LangVersion>8.0</LangVersion>-->

And added <Reference Include="netstandard" /> for more-info

Aditya Y
  • 651
  • 6
  • 12