I have a C# solution targeting .NET framework 4.8, it builds fine in Visual Studio 2022. However when I try and run a build using a Cake script it falls over on the following line at the .:
applicationName = ConfigurationManager.AppSettings["ApplicationName"]?.Trim();
The Error is below:
ApplicationMetadata.cs(38,91): error CS1525: Invalid expression term '.' [*path*]
ApplicationMetadata.cs(38,92): error CS1003: Syntax error, ':' expected [*path*]
It does build if I remove the '?' from the code. It's an old code base, we're using Cake 0.21.1 and Microsoft.Bcl to add in async functions. Previously the code was targeting .NET Framework 4.6.1.
I can get that Cake script to build if I install Visual Studio Build Tools 2017, however I'm trying to update the code enough to have it work with more up to date tools.
I've also updated all the csproj files in the solution to use tools version 17.0, in case it wasn't building because it was specifically targeting the older build tools version, but it doesn't seem to have made any difference at all, and the error messages are exactly the same as before.
I know it's not a huge amount of information, but I'm hoping someone might have dealt with a similar situation before.
CodePudding user response:
My guess is the problem lies in the old Cake version.
Cake 0.21.1 "knows" VS 2017 as the latest BuildTools. If you don't have those installed, Cake falls back to some other, lower version. (Hence, the build works if you install BuildTools 2017)
I'd suggest switching to a newer version of Cake.