c#error CS1056:Jenkins或MSbuild的意外字符'$'

Siv*_*ddy 0 .net c# asp.net jenkins

我需要使用Jenkins进行Continues集成,在我的代码中我编写了类似的代码

throw new ArgumentNullException($"The {nameof(Id)} cannot be null");
Run Code Online (Sandbox Code Playgroud)

如果我构建应用程序它正在构建成功,但如果我使用MsBuild(或)Jenkins构建相同的应用程序,

我得到的错误就像

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.
Run Code Online (Sandbox Code Playgroud)

我正在使用v4.0.30319 FrameWork for MSBuild.

小智 9

我通过使用C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe而不是C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe在jenkins上修复了问题.


Geo*_*son 6

$字符串插值符号只在C#提供6+.确保使用C#6进行编译.MSBuild 14.0+支持C#6.